How to use something like doc string in a script scheme in Gherkin?

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, ?

? , .

,

+4
2

1

escape- backslash (\)

: \"employees\" "employees"

2

, , . indent, .

java file, scenario outline examples.

+1

, , .

, - , json. - :

Scenario: Query by category
  Given there is a category
  When I query the service by the category
  Then I should receive a json representation of the category

, json- . , (, ). :

  • json
  • json
  • , .

, , .

+1

Source: https://habr.com/ru/post/1621038/


All Articles