Header exists
This is a pre-built action available under @Assertion element type. This Action checks whether a specific header name is available in the API response. The output variable stores the validation result as True or False.
Syntax
Input Value: <HeaderKey1>,<HeaderKey2(Optional)>,....,<HeaderKeyn(Optional)>
<HeaderKey1>,<HeaderKey2(Optional)>,....,<HeaderKeyn(Optional)>
Enter the exact name of the response header that you want to check.
Note: You can also provide multiple response headers by separating with comma (,).
Output Value: <Keyword Status(optional)>
<Keyword Status> (Optional)
The action status variable stores the result of the check as True or False.
Example: Checking Whether a Header Exists
In this example, we explain how to verify that the Content-Type header is present in the API response.
Action: Header exists
Input Value: Content-Type
The input value Content-Type specifies the name of the response header to check.
API Response Headers:
Content-Type: application/json Content-Length: 245 Cache-Control: no-cache StatusCode: 200
Output Value: {Status}
The output variable {Status} stores the result with the following possible values:
True: The specified header is available in the API response.
False: The specified header is not present in the API response.
Logical Explanation: The Header exists action takes the header name Content-Type from the Input Value column and checks whether the header is present in the API response. The action does not check the header value. Since the Content-Type header is available, the {Status} variable stores True.

Example 2: Checking Multiple Headers
In this example, we explain how to verify that multiple response headers are present in the API response.
Action: Header exists
Input Value: Content-Type,Authorization,Cache-Control
The input values Content-Type, Authorization, and Cache-Control specify the names of the response headers to check. Each header name is separated by a comma.
API Response Headers
Content-Type: application/json Authorization: Bearer token123 Cache-Control: no-cache StatusCode: 200
Output Value: {Status}
The output variable {Status} stores the result with the following possible values:
True: All the specified headers are present in the API response.
False: One or more of the specified headers are not present in the API response.
Logical Explanation: The Header exists action takes the multiple header names Content-Type, Authorization, and Cache-Control from the Input Value column and checks whether each header is present in the API response. The action does not check the values of the headers. Since all the specified headers are available in the API response, the {Status} variable stores True.

Last updated