I am doing a simple rest api test in Cucumber Java. The answer is in Json format.
The gherkin function file I am writing looks like this:
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 several requests for testing with various parameters, such as “employees”, “departments”, etc., it is natural to write “Script Script” to complete 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 simply:
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
by copying and pasting.
But there are problems with this approach:
- There are special characters in the Json line to escape if they are surrounded by "
- The script script table looks very dirty
? else, ?
? , .
,