Parameterization (Using Data Tables)

Feature: Application Login for different users

parameterization.feature

Feature: Application Login for different users


#using Outline

@DifferentUserslogin

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 |



#Using Tables

@Multipledatafields

Scenario: User login with multiple data fields

Given user is on AxisBank Landing Page

When user logs in with following details

| username | admin |

| password | 1234 |

| role | superuser |

Then Axishomepage is display with all Cards details



  • Tag (@Multipledatafields): This tag indicates that this scenario focuses on logging in with multiple details.
  • Scenario: A standard scenario (not an outline) that describes logging into the Axis Bank application with specific details.
  • Given: The user is on the Axis Bank landing page.
  • When: The user logs in using a table of multiple fields (username, password, and role).
  • Then: The expected result is that the homepage appears with displayed card details.

parameterizationSteps.java


package stepDefinitions;


import java.util.Map;


import io.cucumber.java.en.Given;

import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;


public class parameterizationSteps {


//Outline

@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");

}


//Using Tables

@Given("user is on AxisBank Landing Page")

public void userison_Axisbankinglandingpage() {

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

}


@When("user logs in with following details")

public void user_logs_in_with_details(io.cucumber.datatable.DataTable dataTable) {

Map<String, String> data = dataTable.asMap();

System.out.println("Username: " + data.get("username"));

System.out.println("Password: " + data.get("password"));

System.out.println("Role: " + data.get("role"));

}


@Then("Axishomepage is display with all Cards details")

public void Homepage_Cards_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",tags="@Multipledatafields", monochrome=true)

public class parameterizationTestNGRunner extends AbstractTestNGCucumberTests{


}




Output:


User landed on netbanking page

Username: admin

Password: 1234

Role: superuser

all cards are displayed


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

Default suite

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

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



Notes:

  • DataTable: In Cucumber, a DataTable is a structured way to represent data in a tabular format. It allows you to pass multiple sets of data to your step definitions, making your tests more dynamic and flexible.

  • Map: A Map is a collection of key-value pairs. In Java, it is an interface that allows you to store data in a way that each key is unique and maps to a specific value.

  • asMap() Method: This method is part of the DataTable class in Cucumber. It converts the DataTable into a Map, where the first row of the DataTable serves as the keys and the subsequent rows provide the corresponding values.