In the mabl Trainer, you can use API steps to validate that the UI is aligned with the backend or to use a value from the API response as a variable in a subsequent step.
This article explains how to create API steps in browser and mobile tests, including how to…
Creating an API step
To create an API step in the mabl Trainer, take the following steps:
- Click on the plus sign to add a new step.
- Select the API request step.
- In the API Step Editor, configure your request.
- Click Send.
- Add assertions to ensure the response matches the expected result.
- If you want to use data from the response in subsequent test steps, create a variable.
- Click Save to add the API step to your test.
The API Step Editor
Referencing variables
To reference existing variables in the API request or assertion, use mabl variable syntax: {{@variableName}}
.
Asserting on an API step
When you send a request in the API Step Editor, mabl adds a default assertion on the response status. To update or add different assertions on the response, take the following steps:
- Click on the Assertions tab.
- Create an assertion on the response status, headers, or body. For assertions on JSON response bodies, use JSON path syntax.
- To preview the assertion, click on the arrow to show transfer value.
Previewing assertions in the API Step Editor
By default, assertions are marked "Fail immediately", which means that if the assertion fails, the test stops running and is marked "failed". If you want the test to continue running even if the assertion fails, update the behavior on failure in the Advanced tab of the API Step Editor:
- "Fail at end of test" - if the assertion fails, the test continues running and is marked "failed" at the end.
- "Continue on failure & mark warning" - if the assertion fails, the step still passes and is marked with a warning.
Creating variables from an API step
To create a variable from the response, take the following steps in the API Step Editor:
- Click on the Variables tab.
- Create a variable using the response status, headers or body. To create a variable from a value in a JSON response body, use JSON path syntax.
- Give the variable a name.
After saving the API step, you can use the new variable just like any other variable in the mabl Trainer.
Creating a variable from an API response
Setting cookies from the API response header
In browser tests, if the API response includes the Set-Cookie header, you can configure the API step to set the cookie in the browser under test in the Advanced section:
Setting cookies in the response header