Creating API tests

You can create API tests and run them on your local machine using the desktop app.

To begin creating your first API test, open the desktop app, click on the New test button in the left sidebar, and select to create an API test.

Choosing from the available test types in mabl.Choosing from the available test types in mabl.

Choosing from the available test types in mabl.

Fill out the test creation form and click on Create test. You will be presented with the mabl API test editor that lets you:

  • Create API steps (requests), including support for variables for chaining requests and doing data-driven testing.
  • Send API requests and see the response data.
  • Easily make assertions and create variables based on the response without writing code.
  • Use JavaScript to add custom pre-request and test logic, including support Postman functions and library thanks to the mabl integration with Postman.
  • Manage variables in the left side panel as well.
  • Drag & drop steps to re-arrange them.
  • Run the entire test locally using the "Run test" button.
Creating an API test in mablCreating an API test in mabl

Creating an API test in mabl

You can now create your first API test steps by clicking the plus sign button in the left panel. If you already have an existing Postman Collection that you would like to import in mabl, just click on the button to import and refer to the Postman integration documentation to learn more.

Creating API test steps

The simplest API step you can create is to make a GET request to a given endpoint URL such as https://reqres.in/api/users or https://postman-echo.com/get. To make this request, give the step a name, specify GET as the HTTP method type, enter the desired URL and click the Send button.

Creating a simple API test step.Creating a simple API test step.

Creating a simple API test step.

🚧

Test size limits

Please note that API tests cannot exceed 1MB in size. We recommend using caution with large JavaScript pre-request scripts.

To make more complex API requests you can configure the following options for the request:

  • HTTP Method - GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
  • Authentication - Basic auth, bearer token, or API key that will be added either as headers or query parameters to the HTTP request depending. If you need support for additional authentication types, please let us know via our feedback portal.
  • Query parameters - key value pairs that will be appended to the API URL.
  • Headers - key value pairs to be send as headers for the HTTP request.
  • Body - any data that you would like to pass along the HTTP request in a supported format like raw text/JSON/XML/HTML, formdata, x-www-form-urlencoded, and GraphQL.
  • Pre-request script - provide JavaScript code that will run before the HTTP request is made, including support for JavaScript functions and libraries available in Postman.
  • Tests - make assertions and create variables based on the response data, including option to write JavaScript code to handle complex scenarios. Learn more in the response validation guide.
  • Settings - key value pair settings that will be applied to the HTTP request.

To learn about creating assertions and variables based on the API response, please review the response validation guide.

🚧

API tests limitations compared to browser tests in mabl

At present, API tests in mabl do not support the following capabilities that are available for browser tests:

  • Reusable flows and JavaScript snippets
  • Browser tests use mabl string templates like {{alnum:11}} or {{fake.name.firstName}} while API tests currently do not support those mabl string templates but support Postman dynamic variables such as {{$randomAlphaNumeric}} due to the mabl integration with Postman..

Also note that network traffic from API tests originate from a random IP address assigned by our cloud provider at the time of execution. They do not adhere to the IP address ranges displayed under the Networking tab in the Settings section.

Running tests

You can use the mabl desktop app to run the API test from your local machine while you are editing the test.

You can also run API tests from the mabl cloud. To trigger an ad-hoc cloud run, go to the test details page and use the Run test button. When you trigger an ad-hoc test run you will see a link to see the test results.

If you want an API test to run on schedule or on deployment, simply add it to a mabl plan. You can include both browser and API tests in the same plan as well as share variables between tests in the plan.

📘

Max runtime duration

An API test can run up to a maximum of 9 minutes. If you have a case where you need an API test to run longer than that, please contact our support team via in-app chat or [email protected] to discuss your options.

Updating tests

To update an API test, go the test details page and click the Edit steps button. You will then be able to make changes to existing API test steps, add new ones, or even replace the steps by importing a Postman Collection.

Editing an API test with the mabl desktop app.Editing an API test with the mabl desktop app.

Editing an API test with the mabl desktop app.

There is revision history, so you can always revert back to a previous version of a test from the Change history tab on test details page.


Did this page help you?