Test Script Page
Last updated
Last updated
API test scripts page are designed for both creating new API scripts and modifying existing ones.
The API test scripts page can be accessed through the navigation path Automation > API Testing > API Test Script.
The test script page contains the following sections:
Basic Details
URL Details
API Scripts
a. Predependent API scripts b. Request Header c. Request Body
Save Request Parameter
Assertion
Basic details have for sections which is used for creating and updating test script
Component : Provide the new test script component name.
Test ID : Provide the new test script id.
Test Name: Provide the new test script name.
Http Method - Provide new script http method type
Please note :
The 'Component' and 'testID' fields are for the ComboBox. To create a new test component, you need to type the name of the new component. For an existing component, select the appropriate one from the ComboBox. This process is essential for ensuring similarity
To modify any API test scripts, select the component and existing ID. All values will be prepopulated.
After selecting the HTTP method type, the request body template will automatically change. For example, when we choose the POST method, the request body will be displayed as follows:
For creating any API scripts, we require a URL that includes the base URL along with the relative URL (path or query parameters). In the URL details section for new API scripts, we provide the URL based on the URL key name for test scripts.
URL details contain the following information.
The "Environment" section is a listbox sourced from the configuration page.
The base URL is associated with the component key on the configuration page. All component keys will be displayed in the URL details section on the test script page.
This section is used to provide path parameters or query parameters for new test scripts.
For writing a new test script, certain API scripts require credentials in the form of a username and password for authorization. If a test script demands such required credentials, we can select the authorization key from the URL details section. Please note that the Authorization key is sourced from the configuration page.
The API URL is the base URL that is auto-populated based on the component section. This value is not saved; it is used for debugging purposes so that users can view, in the debug section, the URLs that are being called.
The "Testing Type" field is exclusively for debugging purposes and offers two values: "Integration Testing" and "Unit Testing." If you select "Unit Testing" during script debugging, your dependent test scripts won't communicate with the actual server; instead, they will utilize mock data. On the other hand, if the testing type is set to "Integration Testing," dependent test scripts will interact with the server, operating on real data
For writing the API test script, the core components include the request header, request body, and any dependent scripts if required. In this section, details can be added for new API scripts, and existing API script details can be modified.
A test script can depend on multiple existing test scripts. When it is dependent, it means that new test scripts consume the response of the dependent test script. In this section, we can add all dependent test scripts along with their sequence.
You can override the request parameter of a dependent test script. The request body, request header, and relative URL can be overridden by passing the values in the "Set Request Parameter" section.
REST responses can be in the form of JSON objects and arrays. QAautoMATER provides rules for extracting details from the response. For example, if we want to retrieve information from the response body, we need to use the prefix "ResponseBody." Similarly, to obtain a value from the response header, we need to use the prefix "ResponseHeader.
For a example , if we are geeting Response body
for a getting type value from the Response we have to write ResponseBody[type]
Here we are svaing value in variable type and now this variable can be used anywhere in test script with sign {{Type}}
Suppose we are getting response in json Array for a example
Assume we want to retrive title for second index , in that case we have to write ResponseBody[1][title]
After saving the response in variable myTitle it can be used anywhere in test script with sign {{myTitle}}
Please Note : you can save requestbody, reuestheader as well from this section
The Request Header section is used for providing key-value pairs of request headers for new test scripts. By default, all headers defined in the configuration page will be displayed.
In the Request Header, suppose we need to pass a response from another API script. We can use it as follows: for example, to pass the value of myTitle
in the header, set the key as myTitle
The Request Body section is used for providing the request body in an API test script. By default, it is displayed as {1: "Placeholder for request body"}.
In place of the "Placeholder for request body," we need to put the payload for new API scripts according to the script. For example, we may put {"type":"ABC","email":"testabc@test.com"}
We can call dependent API script variables directly using the variable key with {{variableName}}
When providing random data, we can do so by clicking "Select Dynamic Data."
In the case of data iteration, suppose you want to run the same test script with multiple data sets. Then, add a new key with the name "2" and put your data, and so on. This means that whatever data sets are available in the request body, the test script will be executed for each one.
The "Save Request Parameter" feature is used for storing request parameters (Request Header and Request Body) to capture random and dynamic values into variables. For example, if we want to create a new user based on an email, where a random email is provided in the request body, and the scenario involves verifying the email in the response body. To handle this, we can save the request parameter in a variable and then use it in assertions.
The Assertion section is used for adding assertions in a test script. Assertions can be placed on Response Code, Response Body, and Response Header.
In the Expression section, we need to write which key we want to verify.
The Function is a listbox that indicates the type of assertion to be applied.
In the Expected section, we need to provide the expected value.