Variables in API Testing
Variables in Robonito allow you to capture dynamic values from an API response and reuse them across subsequent API requests or UI test steps. Using variables eliminates fragile hardcoding and enables dynamic, data-driven test automation.
Why Use Variables in API Testing?
Modern web APIs rely heavily on dynamic identifiers and session state:
- Authentication Tokens: Extracting Bearer JWTs or OAuth tokens from login endpoints to authenticate downstream calls.
- Auto-Generated IDs: Capturing generated database IDs (e.g.,
userId,orderId,invoiceNumber) from creation endpoints. - Workflow State: Carrying status tokens or correlation IDs across microservice boundaries.
- Environment Portability: Decoupling tests from hardcoded hostnames so they run seamlessly across local, staging, and production environments.
Variable Types & Scopes
Robonito supports three levels of variables in API testing:
| Variable Type | Scope | How It Is Defined | Example Use |
|---|---|---|---|
| Step-Extracted Variables | Current test case and downstream steps. | Extracted from an API response body or header via the Variables tab. | {{newUserId}}, {{authToken}} |
| Global / Environment Variables | Entire workspace and all suites. | Configured in Workspace Settings → Variables. | {{baseUrl}}, {{adminPassword}} |
| Dynamic Random Generators | Re-evaluated on every run. | Built-in template tags provided by Robonito. | {{$randomEmail}}, {{$randomName}} |
Extracting Variables from an API Response
To extract a dynamic value from a response:
- Open the API test case step that produces the data.
- Navigate to the Variables tab in the step configuration pane.
- Click Extract Variable.
- Configure the extraction parameters:
- Variable Name: Enter an identifier (e.g.,
accessTokenoruserId). You will use this identifier downstream as{{accessToken}}. - Source:
Response Body (JSON)— Extract values from structured JSON payloads using JSONPath.Response Header— Extract values from HTTP response headers (e.g.,Set-Cookie,Location).Status Code— Capture the numeric HTTP status code.
- JSONPath Expression: Provide a path that isolates the exact property.
- Variable Name: Enter an identifier (e.g.,

JSONPath Syntax Reference
When extracting from a JSON response body, Robonito uses standard JSONPath expressions:
| JSON Response Structure | JSONPath Expression | Extracted Value |
|---|---|---|
{ "token": "xyz123" } | $.token | "xyz123" |
{ "user": { "id": 42 } } | $.user.id | 42 |
{ "items": ["apple", "banana"] } | $.items[0] | "apple" |
{ "data": [{ "id": 10 }, { "id": 20 }] } | $.data[1].id | 20 |
{ "meta": { "total": 150 } } | $.meta.total | 150 |
JSONPath Best Practice:
Always use specific paths (e.g., $.data.user.id) rather than recursive wildcards ($..id) to prevent extraction ambiguity when response structures contain multiple nested objects with similar keys.
Injecting Variables Downstream
Once extracted, a variable is immediately available to all subsequent steps in the test case. You inject it by enclosing the variable name in double curly braces: {{variableName}}.
Supported Injection Locations
- Endpoint URLs:
https://api.example.com/v1/users/{{userId}}/orders - Query Parameters:
Key: search Value: {{searchTerm}} - HTTP Headers:
Key: Authorization Value: Bearer {{authToken}} - JSON Request Body:
{ "customerId": "{{userId}}", "items": [ { "productId": "{{productId}}", "quantity": 1 } ], "email": "{{userEmail}}" }
Variable Propagation to Web UI Tests
Robonito's architecture allows API test cases to be embedded directly inside Web UI test flows using the Reuse Test step:
- Run an API authentication test case to extract
{{authToken}}. - In subsequent Web test steps, the token is available to local scripts or storage state injectors.
- This saves significant execution time by allowing test suites to bypass repetitive web login forms.
Related Documentation
- API Chaining — Building end-to-end multi-step API flows.
- Global Variables — Workspace-level environment variables.
- Fake Data Generation — Built-in dynamic data generators (
{{$email}},{{$uuid}}). - Configuring an API Endpoint — Headers, parameters, and authentication.