0

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)
RaMb3asT
  • 17
  • 1
  • 2
  • 8
  • Change the step def pattern to - "The response fields should be {details}". Register the 'details' parametertype with logic to return the List of strings. – Grasshopper Apr 09 '19 at 17:08

1 Answers1

0

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);
}
Matthewek
  • 1,519
  • 2
  • 22
  • 42
  • Changed above solution by @Matthewek as following and it worked. Thanks List data = dataTable.asList(String.class); String modificationDate = data.get(0) – Waqas Raza Apr 10 '19 at 07:59