I am doing a simple rest api test in Cucumber Java. The response is in Json format.
The gherkin feature file i write looks like:
Scenario:
Given I query service by "employees"
When I make the rest call
Then response should contain:
"""
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
"""
Now since there are multiple query to test with different parameters like "employees", "departments".. etc, it's natural to write Scenario Outline to perform the task:
Scenario Outline:
Given I query service by "<category>"
When I make the rest call
Then response should contain "<json_string_for_that_category>"
Examples:
| category | json_string_for_that_category |
| employee | "json_string_expected_for_employee" |
| department | "json_string_expected_for_department"|
where json_string_expected_for_employee is just:
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
by copy and paste.
But there are problems with this approach:
- There are special characters in Json string need to escape if just surrounded by " "
- The Scenario Outline table looks very messy
What is a good approach to do this? Can a string variable be defined else where in feature file to store long strings, and this variable name placed in the table?
Or any solutions? This must be a common scenario for people to compare non-trivial data output in Cucumber.
Thanks,