API testing means that there's an easy way to send HTTP requests within your tests.
This makes it easier to extract values returned from an API call and use them in UI related steps, and validate that the value in the backend correlates to the frontend.
As always, we differentiate between actions and validations:

  • API actions - Should be used when in need to get data and use it for calculation, or to save it for later use in the test. 
  • API validations - Should be used to validate data returned from an API call. Usually validating data on the backend.

API Action

How to add

  1. Hover over the arrow menu where you want to add your API call.
  2. Click ‘+’ ⇒ ‘Actions’ ⇒ ‘Add API action’.

   3.  Fill the following data:

  • Method: Get /Post/ Put/ Patch/ Delete/ Copy/ Head/ Options 
  • URL: Needless to explain :)
  • Header: Fill the keys and values that need to be sent to your API. The 'Raw' switch will allow you to enter the values in their raw format e.g. when copies from the browser's devtools network panel.
  • Body: Select the data structure you want to send, and fill in the text box. Use the "Text" option for entering free text, e.g. sending a key and a value.
  • Send via web page (aka "send cookies"): Uncheck only if you want to send the API call outside the browser context so that browser-restrictions do not apply to it. For example, if your API doesn't support CORS.
    Keep this option checked if you need the API to also send browser information such as cookies (they are sent automatically).

Run additional code

Used to run code after the API call. You can run any JavaScript code, and use the data returned from the API call.

  • Status code
  • Response Body
  • Response Headers

If the "Response Body" content type is XML/JSON the parameter type will be an Object otherwise the parameter type is String.

As any JS step, you can export the returned value from the API to be use in the following steps.

Click here to run a demo test of this example. 


Note
: If you're running via a webpage, and the page has not finished loading, this step can fail. If the previous step requires loading, add a wait for before the API step to verify that the page has finished loading.

API Validation

Use an API validation step to validate the returned value or to validate them against elements in the UI.

As in every custom (JS) validation, it is necessary to return a boolean (truthy/falsy in JS) values in the additional code section.
Read more about validations here

How to add API steps

  1. Hover over the arrow menu where you want to add your API call.
  2. Click ‘+’ ⇒ ‘Validations’ ⇒ ‘Validate API’.
  3. Fill the data as described in API action. 
  4. Fill the additional code section so it returns True/False value.

Parameters

You can use parameters in the API step as you would in any other custom (JS) step. Either in-param, as dependency injection, or out-param via the exports/exportsGlobal.
Read more about parameters options here

Using parameters in the sent HTTP request

Parameters can also be used in the header, body, and URL.
Since those sections are cumbersome to write in JS, we made it easy for you. In these sections you will need to add double curly brackets around the parameters.

For example:

Note: You can use triple brackets if you do not want the parameters to be decoded. e.g {{{param}}}

Using parameters in the HTTP response

Parameters added in the property panel will automatically be added to the function's signature. Plus you can also access any other variables in the test's scope.

Click here to run a demo test of this example. 


Result Run

After running the step, you'll see the response returned from the API call on the "Response" tab, and sometime more info, such as response status code, call duration, and the size of the binary files.

Reusing API steps

API steps are reusable components similar to groups and custom actions.
Click here to read more about reusing steps.

Did this answer your question?