Skip to content
Advertisement

How to run a Cucumber Step multiple times with different data?

I am trying to automate one scenario using Cucumber.

Step Then Create item actually takes values from first row only.

What I want to do is execute step Then Create item 2 times, before moving to step Then assigns to CRSA.

But my code is taking values from first row only (0P00A). How to take values from both rows?

Background: Application login
    Given User launch the application on browser
    When User logs in to application
   

     Scenario: Test
            Then Create item
              | Item ID    | Attribute Code | New Value | Old Value |
              | 0P00A      | SR             |  XYZ21    | ABC21     |
              | 0P00B      | CA             |  XYZ22    | ABC22     |
     Then assigns to CRSA




  @Then("Create item")
    public void createItem(DataTable dataTable) {
        
        List<Map<String, String>> inputData = dataTable.asMaps();
        
        }

Advertisement

Answer

You can use foreach like below:

List<Map<String, String>> inputData = dataTable.asMaps(); 
   
  for (Map<String, String> columns : inputData ) {

         columns.get("Item ID");
         columns.get("Attribute Code");

}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement