Reputation: 69
In one of our tests, a JSON payload for a POST operation must be externalized for two reasons:
Below is an example of the sample test that will provide some more context:
@post-operation
Scenario: Verify that POST /<some url> is successful
Given I have a valid access token from Ping
** import JSON payload from external file, store it in context and use it here or in Gherkin definition that implements below step **
When I POST to /<some url>
And response code should be 200
And ** some more actions **
Would appreciate your responses. Thank you.
Upvotes: 0
Views: 1188
Reputation: 4099
Give the payload a name and then get the payload in your step definition or better yet a helper method called by your step definition.
Rewrite you scenario so instead of it talking about how you are doing something it talks about WHAT you are doing and WHY its important. The scenario should not even mention things like POST, url, response code instead it should be talking about what you are achieving by doing this interaction.
If you really don't want to take this approach then use a unit testing tool instead, its much more appropriate for doing the sort of thing your scenario is doing, and you won't have the same problems getting external things because you are always in code.
Upvotes: 2