API Request¶
Purpose: send an HTTP request from inside a test and optionally save what comes back.
Use it for the parts of a scenario that do not need a browser: seeding a record before the UI test runs, checking that a posted transaction reached the backend, or tearing down data afterwards.
Not the same as the External API
This command calls your systems from a test. The External API is the other direction: it lets your systems trigger elevaite365 scenarios.
The step is split into two sections, Input and Save Response, chosen with the toggle at the top.
Input¶
| Field | Purpose |
|---|---|
| Method | The HTTP verb, for example GET |
| URL | The endpoint to call. Required |
| Headers | Key and value pairs. Use Add row for each one. Starts empty |
| Authentication | How to authenticate. See below |
| Body type | Empty, JSON or XML. Picking JSON or XML reveals a Body field to paste the payload into |
Changing the payload each run
Keep the JSON or XML body in a variable, swap the field that changes with Update Value, then put the result variable in the Body field.
Variables can be used throughout, so a URL like https://api.example.com/orders/{{OrderId}} picks up an ID captured earlier in the run.
Authentication¶
Picking an option adds its own fields to the step.
Nothing extra. Use it for open endpoints, or when you are passing a credential yourself as a header.
- Username
- Password
- Bearer token: the token to send
- Token URL: where to fetch the token from
- Client ID
- Client Secret
- Scope
The step fetches a token, then makes the call with it.
Save Response¶
Each field saves part of the response to a variable. All three are optional: leave one blank and that part is thrown away.
| Field | Saves |
|---|---|
| Status Code | The HTTP status the call returned |
| Response time | How long the call took |
| Response Body | The body the endpoint returned |
Nothing is checked here. The step stores the values, and you assert on them afterwards with Verify Variable.
Working with the response¶
The body arrives as one lump of text, JSON or XML depending on the endpoint. To get at a single field, follow the API Request with Extract Value and set its format to match:
| # | Step |
|---|---|
| 1 | API Request, saving the body to a variable |
| 2 | Extract Value, format JSON, path $.id |
| 3 | Verify Variable, or use the value in a later step |
| # | Step |
|---|---|
| 1 | API Request, saving the body to a variable |
| 2 | Extract Value, format XML, XPath /order/id |
| 3 | Verify Variable, or use the value in a later step |
Checking the call succeeded
Save the status code, then assert on it with Verify Variable. A test that posts data and never checks the response will pass while the data quietly fails to arrive.