Assertions
To make sure that you API is working correctly, you probably want to add some assertions to your workflows โ and Capter makes that super easy!
You write the assertions in plain English, and Capter parses them in to actual assertions.
#
Asserting on a responseYou add assertion at the end of each step:
In the above example we assert that the status equals 200 and that the body we get back is an array.
#
What you can assert onThere are four things you can assert on:
status
- the HTTP status you get backbody
- the response bodyheaders
- the response headersduration
- how long it took to get a response back
!!
operator#
Testing the opposite using the You can invert a test by adding an extra !
at the start of the assertion string:
The above test will fail if the status equals 500. This is equal to the .not
extension you see in many other test frameworks.
#
Composing an assertionSometimes you want to assert that a response matches something in a previous response, for example:
- Create a product
- Assert that we get a product with an
id
back
- Assert that we get a product with an
- Use the
id
from the create response to fetch the product- Assert that the
id
of that user matches theid
in the create step
- Assert that the
In a Capter workflow, that would look something like this:
As you can see on the highlighted line above, we can use values from the previous step in our assertions!
#
Available assertionsHave a look at the workflow reference page.