Parameterization (Using Scenario Outline)

Parameterization in Cucumber Framework allows you to run the same test scenario with different sets of data, making your test scripts more reusable and efficient.

This is particularly useful in scenarios where multiple user types need to be validated, such as debit and credit card users logging into a net banking application.

Why Use Parameterization?

  • Reusability – Avoids duplication of scenarios.
  • Maintainability – Easy to update values in one place.
  • Data Coverage – Allows testing same flow with multiple inputs.
  • Better readability – Keeps feature files clean and readable.

Keyword --->> 
Scenario Outline: A Cucumber feature that allows the definition of a scenario template, which can be executed multiple times with different sets of data.

1. Using Scenario Outline with Examples

User ( Debit card users, credit cards users ) --- >> All kinds of users should be login and able to see the Homepage and Cards details

parameterization.feature

Feature: Application Login for different users


Scenario Outline: user login into the netbanking page

Given user is landing in netbanking login page

When user is login with "<Username>" and password "<Password>" combination

Then homepage is showing

And cards are displayed in homepage


Examples:

| Username | Password |

| debituser | hello123 |

| credituser | 123credit |



parameterizationSteps.java


package stepDefinitions;


import io.cucumber.java.en.Given;

import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;


public class parameterizationSteps {

@Given("user is landing in netbanking login page")

public void userison_netbankinglandingpage() {

System.out.println("User landed on netbanking page");

}


@When("user is login with {string} and password {string} combination")

public void user_is_login_with_and_password_combination(String string1, String string2) {

System.out.println("user login with username " +string1 + " and password is " +string2);

}


@Then("homepage is showing")

public void homepage_is_displayed() {

System.out.println("Home page is showing to the users");

}


@Then("cards are displayed in homepage")

public void cards_are_displayed() {

System.out.println("all cards are displayed");

}

}



parameterizationTestNGRunner.java


package cucumberOptions;


import io.cucumber.testng.AbstractTestNGCucumberTests;

import io.cucumber.testng.CucumberOptions;


@CucumberOptions(features = "src/test/java/features", glue="stepDefinitions", monochrome=true)

public class parameterizationTestNGRunner extends AbstractTestNGCucumberTests{


}



Output:


User landed on netbanking page admin and password in 1234 Home page is displayed Cards are displayed User landed on netbanking page user and password in 0953 Home page is displayed Cards are displayed User landed on netbanking page user login with username debituser and password is hello123 Home page is showing to the users all cards are displayed User landed on netbanking page user login with username credituser and password is 123credit Home page is showing to the users all cards are displayed


===============================================

Default suite

Total tests run: 4, Passes: 4, Failures: 0, Skips: 0

===============================================


NOTE: In above output

We didn't mentioned particular StepDefiniation file details in feature & testNGRunner file .

so when you run the parameterizationTestNGRunner.java

it will execute all the StepDefiniation files

we mentioned only two users details in parameterization.feature file

but we got Total tests run: 4, Passes: 4,