Automate REST API Calls

abstract As part of a test flow, we may need to call some webservice via REST APIs. The REST API Call Step in Flowcharts allows calling and verifying REST API calls.

REST Request

  1. Click on the node where you need to add REST API call on the flowchart and select Automate.
  2. Automate dialog opens up with the selected node.
  3. Click on the icon near to Add Step and from the drop-down select REST API Call
  4. It opens a REST API dialog with the options to call GET, POST, PUT, DELETE, PATCH
  5. Choose relevant call, ex. GET and complete the fields like URL, Headers, etc
  6. Click Get Response to get the response of API
  7. It will automatically navigate to the Response tab and show the response of the API.
  8. Click on the TREE under Body tab.
  9. Click on the checkboxes for the values that need to be asserted or stored.
  10. Click on the Update to save the assertion.
  11. Click on Store to store the value of the response in some variable.
  12. info Select multiple checkboxes and use the Assert and Store buttons to assert or store the values in one shot.
  13. Assertions can be seen on Assertions tab
  14. Variables can be seen on Variables tab
  15. Click on Update button to add the API Call in the Keyword.
  16. Similarly, use Post or any other method.

Import from Postman

Import from HAR

REST Response

REST Response section displays following information:
  1. Response Status: Displays the response code returned by the server.
  2. Response Header: Displays the response headers returned by the server.
  3. Response Body: Response Body has 3 tabs:
    • Raw: Displays the response body as it is returned.
    • HTML: Displays the parsed HTML if content-type returned from server is HTML.
    • TREE: Displays the response body in tree structure if content type returned from server is JSON or XML.

Assertions

Assertions can be added through following methods:
  1. On the Response tab, click on the Assert button next to the response values for assertion.
    • The Assert button will be visible only on hovering on any value.
  2. The Add Assertion dialog opens up. Select the relevant assertion type and click on Update
  3. Multiple assertions can be set simultaneously using the checkboxes to select and then click on Assert button at the bottom.
  4. The added assertions can be seen on the Assertions tab.
  5. Assertions can also be added from the Assertions tab by clicking on the New Assertion button at the bottom.
  6. An assertion can be edited by clicking on the Edit icon next to it.

Variables

The values can be stored in variables through following methods:
  1. On the Response tab, click on the Store button next to the response values to store the value on the variable.
    • The Store button will be visible only on hovering on any value.
  2. The Store Value dialog opens up. Type the variable name preceding with a $ symbol and click on Update.
  3. Multiple response values can be stored simultaneously using the checkboxes to select and then click on Store button at the bottom.
    • When multiple variables are created together, the variable names will be taken automatically.
  4. The added variables can be seen on the Variables tab.
  5. Variables can also be created from the Variables tab by clicking on the New Variable button at the bottom.
  6. A variable can be edited by clicking on the Edit icon next to it.

Authorization

Basic Auth

Enter the username and password after selecting Basic Auth from dropdown.

OAuth 1.0:

Choose OAuth 1.0 from the Authorization dropdown.

Uploading a file using REST API Call

 

Input

Description

Example

File name

Absolute file path to the file that should be provided.

http://sahitest.com/demo/php/fileUpload.php

File upload URL

The URL where you want to upload the file. This URL is usually the action URL which is present in the form response values or URL that is passed as an argument for an XML Http Request

OS

OS Dependent path example

Windows

C:\Users\user\Desktop\upload.txt

macOS

/Users/user/Desktop/upload.txt

Linux

/home/user/Desktop/upload.txt

Content Type

Content type of the POST data that is being sent. The content type for the file upload is multipart/form-data and is being used by all the browsers. There are special cases where you can specify your own content type

Content-Type: multipart/form-data; boundary=--boundary123456abcd

Boundary

A random string with 2 hyphens at the beginning

--boundary123456abcd

 

Steps:

  1. Open REST API Call dialog by clicking on the Add Step drop down menu.
  2. Select the POST from HTTP Method combo box.
  3. Specify the file upload URL in the URL field.
  4. Specify the Content-Type header in the HTTP Headers field.
  5. Select the Parameterized radio button for Body field and specify the file path or any other body parameters if required.
  6. Click on the Get Response button.
  7. You will get the following result after the file upload, the response may differ depending on the web application