API steps

Sending API requests in browser tests

The mabl Trainer has the ability to send API requests and interact with the responses via API steps. You can use these steps to expand your test coverage beneath the UI without directly interacting with it.

📘

Note

This feature is part of the mabl API testing capabilities and available to customers on all Enterprise plans, as well as trial users.

To inquire about purchasing API testing, please request a quote.

This guide outlines the basics of creating API steps in browser tests.

The API Step Editor

To create an API request in a browser test, open a new or existing test in the mabl Trainer or quick-edit mode and take the following steps:

  1. Click on the plus icon to add a new step.
  2. Select the API request step.
  3. Configure your API request in the API Step Editor.
1984

Selecting a request method in the API Step Editor

Request method

Clicking on the request method dropdown allows you to select the specific API request method you want to perform against the specified URL.

URL field

Enter the API endpoint in the URL field. Currently, API steps support APIs exposed over HTTP or HTTPS.

The URL field also supports variables using mabl variable syntax: {{@variableName}}. For example, if you stored the base API URL as an environment variable, you could reference it in the URL field: {{@API_URL}}.

Send button

Clicking this button sends the request to the endpoint specified in the URL field.

Modifying the request

Optional modifications to an API request include header, authorization, and body. You can use variables in the request using the same {{@variableName}} syntax.

Header

Enter request headers as key-value pairs.

Authorization

API steps in browser tests support basic and bearer auth.

Body

Enter the request body.

930

Using variables in a request body

Sending the request

After selecting the proper request method, populating the URL field, and filling out any other optional information, click the Send button to send the request.

1986

Receiving a response in the API Step Editor

The response appears as a JSON object containing the status, headers, and, if applicable, the response body.

  • headers: An array of HTTP response headers, each containing a name and value field
  • status: The HTTP response status
  • body: JSON response bodies appear in JSON object format. Other formats for response bodies appear as strings.

Using the result

You can extract data from the response to make assertions and create variables. Assertions and variables can use the following values from a response:

  • Status: HTTP response status
  • Headers: An array of HTTP response headers. Entering the name or key of a specific header extracts its corresponding value.
  • Body (text): Extracts the entire response body as a string.
  • Body (json): Parses the body as JSON so that you can extract a specific value from the body with JSON path.

Assertions

API steps must pass all assertions. You can use mabl variable syntax to reference existing variables in API step assertions.

1984

Using a variable in an API step assertion

Variables

In the variables tab, you can create test-generated variables from the response and use them later in your tests.

1982

Creating a variable from the response of an API step

Use cases for creating variables from API responses include:

  • Saving the entire response as a variable and using this variable later on in a JavaScript step
  • Saving a specific value from the response body and using it in a subsequent step. For example, if the response contained an email address, you could extract the email address, assign it to the variable email_address, and insert that variable into an input field in a form later in the test.

Advanced

The advanced tab includes one option:

  • Set response cookies in the browser: When this option is enabled, mabl sets cookies specified by the Set-Cookie response header in the browser under test.
1018

Option to set response cookies in browser

Saving an API step

Click Save to add the API step to your test.

How do API steps impact the API testing allotment?

Any request that runs as part of an API test or API step in the cloud counts towards the monthly allocated API requests for your workspace.

For example, if you run a browser test with five API steps in the cloud and then an API test with 20 API steps in the cloud, the total number of requests sent is 25. You can review more details on API testing usage in the Usage page (Settings > Usage).

Local runs of both API and browser tests, including steps run in the mabl Trainer and API Test Editor, do not impact your allotment in any way.