Skip to content

API tests

The API Runner is where you create and run API tests. You can start in a few clicks, then add parameters, authentication, assertions and variables as you need them.

  1. Choose a method type.
  2. Paste the API URL.
  3. Select Send to send the request, or Add API Test to save it.

The API Runner with a method and URL

To try it, send a GET request to a practice API that CloudQA hosts: https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos. See practice APIs.

Most APIs need more than a URL. Open the Parameters tab and select Add Parameter to add values. You can also add headers and a JSON body.

The Parameters tab

  1. Open the Authorization tab.
  2. Choose BasicAuth. The default is Noauth.
  3. Enter the username and password.

The Authorization tab

Each response shows the status code, body, headers and the time the request took.

A response with status, body, headers and timing

Use the Assertions tab to verify the response. You can add several.

  1. Choose the response type.
  2. Choose the condition.
  3. Enter the value to check.

Adding an assertion An assertion in the list

Use the Variables tab to save a value from a response and reuse it.

  1. Select Add Variable.
  2. Give it a name your team will understand.
  3. Enter the JsonPath of the value in the response body.
  4. In another request, use the value as __name of the variable__.

Adding a variable from a response

  1. On the API Runner page, select View Saved Tests.
  2. Select one or more tests and run them.

By default the list shows the status of each test’s last run, and results show the execution history.

The list of saved API tests

You can also run a saved API test as a step inside a browser test. Add an Import API Test step in Edit steps.

Group saved API tests into a suite and schedule it for frequent, automated API testing. To add and schedule API tests, see Test suites and Run a test suite.

An API suite

When many API tests run in several environments, such as staging and production, editing URLs and assertions in every test is slow. Define the values once as application variables and use them in your tests.

  1. Define variables in Settings, on the Variables tab.
  2. Enter the variable name in place of the API URL or an assertion value, wrapped in double underscores: __variablename__.

Defining a baseurl variable Using the baseurl variable in a request

Example requests that use a baseurl variable:

  • GET __baseurl__/users/2
  • PUT __baseurl__/api/users/2 (with a JSON body)
  • POST __baseurl__/api/register (with a JSON body)

Pass several sets of parameter values in a single run with a CSV file. The API runs once for each data row.

  1. Open API Tests.

  2. When you start a run, select a CSV data file.

    Selecting a CSV file for an API run

  3. Format the file with parameter names in the header row, followed by rows of data.

    A CSV file of API parameter values

  4. Upload the file and run.

View results on the API results page.

Random variables generate new data on every run, so you don’t type values by hand.

  1. Open API Tests and edit or create a test.
  2. In the JSON Body section, insert the variable in the required format.
  3. Save the test. The data is generated during execution.

Available random variables, each wrapped in double underscores:

Variable Generates
__FirstName__ A random first name
__LastName__ A random last name
__Email__ A random email address
__Word__ A random word

CloudQA hosts a sample to-do API you can use to practice.

Method URL
POST https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos
GET https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos
GET https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos/{id}
PUT https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos/{id}
DELETE https://um5fdww2pj.execute-api.us-east-1.amazonaws.com/dev/todos/{id}