3. Comparing Responses
We’ve seen how to use a variable to store a token and test an authenticated endpoint. Now let’s look at another common use case - comparing responses from different versions of the same API.
Comparing responses
Jikken has a built-in compare keyword to easily compare the responses of different APIs.
Here, we put the URL for the endpoint that we want to compare with the request
.
By default, the HTTP status and body of the responses will be compared.
In this case, we have also specified a response.status
of 200.
When using compare
, both responses will be validated against this condition.
The test will only pass if the responses match each other, and they both match the specified status.
Ignoring fields
Let’s say in the newer version of the test status API (v2), we added a new response field that wasn’t present in v1. Naturally, this would cause the body comparison to fail.
To exclude “user.lastActivity” from the comparison, we specify that we want to ignore
this field.
Any ignored fields will be pruned from the JSON responses before the comparison occurs.
Next, we’ll see how to combine all of these concepts into a single multi-stage test.