Creating API Tests
Step-by-step guide to creating API test cases in ContextQA — configuring requests, using variables, capturing responses, chaining calls, and importing from Swagger.
Who is this for? Developers and SDETs who want to create REST API test cases in ContextQA — including importing tests directly from a Swagger or OpenAPI specification.
This page walks through creating an API test case from scratch, wiring up variables, and generating tests from a Swagger specification.
Creating an API test case
Click the plus (+) icon in the blue bar on the left side of the ContextQA dashboard.
Select Start recording from the options.
Enter a name for your workspace (for example,
API testing) and click Create.In the step editor, type
restand select Rest API method from the list.Click the three dots icon to open the API testing panel.
The panel exposes the following fields:
HTTP method
Select GET, POST, PUT, PATCH, or DELETE
URL
The full endpoint URL
Headers
Key-value pairs; supports variable interpolation
Body
JSON or other payload for POST/PUT/PATCH requests
Store response
Name of the variable that will hold the response
Validation
Assertions to run against the response
Paste your target API endpoint into the URL field.
Under Store response, enter a variable name such as
result. The full response object — status code, headers, and body — is stored under this name.In the Validation section, configure at least a status code assertion. Choose status as the data type, set the comparator to equal, and enter
200as the expected value.Click Get or Send to test the request interactively and preview the response before saving.
Click Create, then Create again to save the test step.
Click Run to execute. Open the execution screen to confirm the test passed.
Using variables in API requests
Variables prevent you from hard-coding sensitive values such as tokens, base URLs, or environment-specific hostnames directly into test steps.
Defining a variable
Open your API test case.
Click the variables option in the test editor.
Enter a key (for example,
token) and paste the value. Click Create to save it.
Referencing a variable
Use ${variable_name} syntax anywhere in the request configuration:
Authorization header:
Bearer ${token}URL:
${BASE_URL}/api/v1/usersBody field:
"api_key": "${API_KEY}"
Variable values are resolved at execution time. To rotate a token, update the variable value once — no test steps need to change.
Variable scopes
Local variables are defined at the test-case level and are available only within that test case.
Global variables are available across all test cases in a project.
Runtime variables are captured from API responses using the Store response field and are available to subsequent steps within the same execution.
Sending the request and capturing the response
When you click Send in the API panel, ContextQA executes the request immediately and displays the response body, status code, and headers in the panel. Use this preview to:
Confirm the JSON structure before writing JSON path assertions
Copy the exact JSON path to a field (for example,
result.body.email) for use in payload validationVerify that authentication headers are being resolved correctly from variables
After saving the step and running the test case, full response details are accessible in Run History under the Response Body tab.
Chaining API calls
When one API step's response must feed into a later step, store the response in a named variable and reference its fields using dot notation.
Example: A POST /auth call stores its response as result. The access token returned in the body is then available as result.body.access_token. In the next API step, set the Authorization header to Bearer ${result.body.access_token}.
For a detailed walkthrough including hybrid API + UI chaining, see API Chaining.
Generating tests from a Swagger or OpenAPI specification
ContextQA can import a Swagger or OpenAPI file and produce a test case for each endpoint-and-status-code combination defined in the spec.
Click the plus (+) icon on the ContextQA dashboard.
Select Import File.
Choose Import Requirement, then select API.
Upload your
.jsonor.yamlSwagger / OpenAPI file.Review the imported endpoints and response codes in the preview panel.
Navigate to Imported Files and refresh the view to see the generated test cases.
Each generated test case reflects a documented endpoint and expected status code — for example, separate cases for 200, 400, 401, and 500 responses on the same endpoint. You can then edit individual steps to add authentication headers, payloads, and more specific assertions.
This is also available through the generate_tests_from_swagger MCP tool, which accepts the same Swagger/OpenAPI content and produces the equivalent test cases programmatically.
Generate API tests from your Swagger spec in minutes. Book a Demo → — See ContextQA generate and execute REST API tests for your backend.
Last updated
Was this helpful?