Matching status codes and responses
In the last output, we saw that we get a status code of 200
(also known as OK). This means the request was successful. Let’s add a step to verify this.
Matching the status code and type
If you want to match a simple status code, this is done via the status
keyword like this:
Scenario: Checking user specific posts Given url 'https://jsonplaceholder.typicode.com/posts' When method get Then status 200
We use the Then
keyword here to indicate that this is an assertion. At this point, we can run the test (which should pass).
Status codes
For a complete list of HTTP status codes, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status.
It is a good idea to deliberately make it fail once to verify that this test would not give us a false positive result in an error case.
Making the test fail
Let’s change the status code to the...