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 response#
You 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 on#
There 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
Testing the opposite using the !! operator#
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 assertion#
Sometimes 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
idback
- Assert that we get a product with an
- Use the
idfrom the create response to fetch the product- Assert that the
idof that user matches theidin 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 assertions#
Have a look at the workflow reference page.