0

I have below steps in my feature file for a scenario.

Given my_first_step

And my_second_step
  | Themes          | one | three |

  | Service Windows | two | four  |

And my_third_step

  | Create Apps |

  | Config      |

we can get parameters of 'my_third_step' as below in the java code as a list

public void my_third_step(List listOfItems) {}

but how can get parameters in 'my_second_step' ? I need to get a rows as array of elements in the java code. How can I do that ?

2 Answers 2

1

You have to pass a list of objects, your object will look like

public class MyObject {
    private Integer themes;
    private Integer service;

    public Integer getThemes() {
       return this.themes;
    }

    public void setThemes(Integer themes) {
       this.themes = themes;
    }

    public Integer getService() {
       return this.service;
    }

    public void setService(Integer service) {
       this.service = service;
    }
}

Then you can pass a List<MyObject> to the method.

public void my_second_step(List<MyObject>) {
...
}

In the feature file change the definition as follows:

And my_second_step
  | Themes          | Service |
  | one             | two     |
  | three           | four    |

I hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Found a solution from this approach. I am going to use list of lists. Thanks
0

Using Header we can implement Data Table in much clean & precise way and considering Data Table looks like below one -

And my_second_step
    | Heading_1        | Heading_2 | Heading_3 | 
    |  Themes          |    one    | three     |
    |  Service Windows |    two    | four      |

public void my_second_step(DataTable table) throws Throwable {

List<Map<String, String>> list = table.asMaps(String.class,String.class); 

System.out.println(list.get(0).get("Heading_1") + " : " + list.get(1).get("Heading_1"));
System.out.println(list.get(0).get("Heading_2") + " : " + list.get(1).get("Heading_2"));
System.out.println(list.get(0).get("Heading_3") + " : " + list.get(1).get("Heading_3"));

}

4 Comments

Thanks a lot for the answer 'TheSociety'. I used the DataTables as you mentioned. but that giving me below error.
cucumber.runtime.CucumberException: Could not convert arguments for step [the group {string} has the following permissions] defined at 'com.symbox.stepdefs.iam.iamManagePermissionGroupPageStepDef.theGroupHasTheFollowingPermissions(String,DataTable) in file:/D:/SDBPTestAutomation/SDBP-Automation/sdbp-automated-tests/automation-framework/target/test-classes/'. It appears you did not register a data table type. The details are in the stacktrace below.
Caused by: io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to cucumber.api.DataTable. Please register a DataTableType with a TableTransformer, TableEntryTransformer or TableRowTransformer for cucumber.api.DataTable.
Ohh finally found a way to do it . I am going to use List<List<String>>. That seems like working. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.