In your Test Cases, If some of the Test Data is fetched dynamically from an API Endpoint, we might need to save the Test Data temporarily and use it in subsequent Test Steps. Therefore, Testsigma allows you to fetch data or perform actions via REST API calls along with normal Test Steps in all the Application Types in addition to REST Services so as to provide maximum flexibility and control in your tests.
Let us see how we can save information that is needed in later steps to Run-time Test Data from a REST Response.
For this example, let us consider the Response for a simple GET request to https://app.testsigma.com. It returns the following Header response:
Server : Apache/2.4.6 (CentOS) X-Content-Type-Options : nosniff Connection : keep-alive Pragma : no-cache Date : Thu, 09 Aug 2018 06:42:19 GMT X-Frame-Options : DENY Cache-Control : no-cache, no-store, max-age=0, must-revalidate Set-Cookie : JSESSIONID=D428960F53C951DFDE07F9C39322CF80; Path=/; HttpOnly Expires : 0 Content-Length : 6014 X-XSS-Protection : 1; mode=block Content-Language : en-US Content-Type : text/html;charset=ISO-8859-1
Info: The Response Body contains the HTML content for the login page but that's not relevant for us now. Let us concentrate on the Header Response we have received.
Steps for storing Run-time Test Data from Response
Below given is a sample REST Step:
Please check the below article for more details on creating a REST Step - How to add Test Steps for Web Service/API Testing?
After creating your normal REST API Call till Expected Status Code, please check the second half of the REST Step Creation Wizard.
1. Check the boxes corresponding to whichever Response Content we need to save Test Data from. Check both Store Header Content from Response and Store Body Content from Response check boxes if you want to save values from both Response Header and Response Body. In the above image, we have checked only the Store Header Content from Response.
2. Enter a name for the Run-time parameter which is to be created in the key field. A run-time parameter with the specified name will be created. In the above image, we have create a Run-time parameter named 'server_name'.
3. Enter the JSON Path expression which evaluates to the Response Entity that we need to store in the run-time parameter created from Step 2. If the Response contains a flat key-value pair instead of a JSON Object, you can simply use the key name here.
Please check this article to know more about JSON Path and its usage - Comparison Modes in Web Services Testing
Let us assume we need to use the property named Server from the Header Response of the above API Call in an upcoming Test Step as Test Data. We can do that by saving the value in a Run-time variable using Store Header Content from Response option in RESTful API Steps as shown below:
In a normal REST API Step, we need to do the following to store the value of a key into a Runtime variable:
1. Check the checkbox Store Header Content from Response since we are going to save Test Data only from Response Header in our case.
2. Enter the name servername for the run-time variable we are about to create.
3. Since in our case, our Response Header contains a flat key-value pair, we are simply using the name of the key i.e Server whose value is the server name we need to store ($.Server would also work).
Once the Test is run, the Response given on the top of the page will be received and Testsigma will evaluate the expression given in value field to get the JSON Object/Element name whose value is to be stored. Once the JSON Object/Element name is evaluated, it will store the value of the JSON Object/Element inside the newly created run-time parameter with name servername.
That's all we need to do for storing run-time parameters from REST API Test Steps.
For using previously store Run-time Test Data in REST API Test Steps, please check this article - Using Run-time Test Data in REST API Test Steps in Testsigma