javacucumberrest-assuredfeature-file

How to have List of Strings in step definition function instead of number of parameters from gherkin feature file


I have a Scenario in the feature file, whose Then steps list the number of fields from JSON which should be confirmed that they are present in Response body. Step in the Scenario of feature file is: Then The response fields should be modificationDate, startDate, endDate, id

translated into this following step method

@Then("The response fields should be {string}, {string}, {string}, {string}")
public void the_response_fields_should_be(String strModification, 
String strStartdate, String strEndDate, String strId)

Instead of having multiple parameters, how can I have a List of Strings like:

public void the_response_fields_should_be(List <String> parameter)

Solution

  • Use DataTable

    Gherkin:

    Then The response fields should be 
       | modificationDate | startDate | endDate | id |
    

    Step definition:

    @And("^Then The response fields should be$")
    public void thenTheResponseFieldsShouldBe(DataTable table)
    {
        List<List<String>> data = table.asLists(String.class);
        String modificationDate = data.get(0).get(0);
        String startDate = data.get(0).get(1);
        String endDate = data.get(0).get(2);
        String id = data.get(0).get(3);
    }