Add expectations and extract values
Decide when a step passes and carry a value from one step into the next.
In short
Each step of a suite is judged by its request's checks until you give it expectations of its own. An extract rule reads a value from one step's answer into a variable that later steps use.
Before you start
- Who: Edit on the project. Run reads and runs only.
- Plan: every plan.
- First: open the suite and run it once so there are answers to read from.
Steps
- Open the suite and the step.
- Choose an expectation (see the table). Choose "Same as the request's checks" to follow the request again.
- Add any further checks; they are listed under "Also checks".
- Press "Extract a value" and set the rule: a JSON path such as $.data.id against the body, or a header name.
- Use it in later steps as {{variable}} in the URL, headers, parameters or body.
Result: the step passes or fails by its own expectation, and later steps get the value.
Good to know
- A step's own checks replace the request's; they are not added to them.
- Checks the simple choice cannot show, such as a JSON field, a header or a response time, are listed under "Also checks".
- Beside a response, "Save to a suite" adds the checks it suggests to a step, without duplicating one that is there.
- Step variables are values you set before a step runs. Mark one secret and it is hidden in results and exports.
If something goes wrong
- A later step sends {{variable}} as text: the extract rule found nothing. Check its path against the earlier step's answer.
- A step passes although the body is wrong: its expectation only looks at the status. Add a check under "Also checks".
Related
- /help/api-testing/test-suites
- /help/api-testing/request-editor-and-checks