Appearance
UI.httpGet()
Performs an HTTP GET request in the browser's context.
Because the request is executed in the browser, any cookies associated with the current page's domain are automatically included. This is useful for scenarios such as making authenticated requests after a user logs in.
If the HTTP response status code is 400 or above, the command fails and the test is marked as failed. To ignore such errors in the test, use UI.httpGet$ instead.
INFO
Performing HTTP requests can be useful for retrieving test data or setting up application state during UI tests. We do not recommend using these commands for API testing — instead use dedicated tools that are efficient and purpose-built.
Usage
js
var response = UI.httpGet(url: string, options: object)
var response = UI.httpGet(options: object)Parameters
The options object includes the following configuration properties:
| Parameter | Type | Description |
|---|---|---|
| url | string | The URL to send the HTTP request to. Required if not passed as the first argument. |
| params | object | Key-value map for URL query parameters. E.g. Given {product: 1, currency: ['USD', 'JPY']}, this sets the url search parameter to ?product=1¤cy=USD¤cy=JPY.If you need custom array serialization, pass values as strings instead. |
| responseType | string | Expected response type. By default, the response's data object will contain the raw response body as a string.If set to "json", the response's data object will be automatically parsed to JSON. |
| headers | object | Map of HTTP request headers. |
| auth | object | Basic authentication credentials. This should be a map containing values for username and password. Overrides the Authorization header. |
| withCredentials | boolean | Defaults to true. Allows requests to include credentials such as cookies and authorization headers. Setting this to false may result in CORS or network errors, depending on the browser. |
Returns
An object with the following contents:
| Parameter | Type | Description |
|---|---|---|
| status | number | The status code, e.g. 200, 404, 500. |
| statusText | string | The status text, e.g. "OK", "Not Found", "Internal Server Error". |
| responseType | string | The response type, e.g. "json". |
| data | object | The response body. If responseType is "json", this is automatically parsed into JSON object. Otherwise, this is a string containing the raw response body. |
Example
js
// go to the pet store
I.goTo("https://petstore.swagger.io")
// get a pet using its ID
let res = UI.httpGet("https://petstore.swagger.io/v2/pet/9216678377732869000")
// log the response data
if(res.status === 404){
TEST.log.fail("Pet not found")
} else {
TEST.log.info("Response from API is: ", res.data)
}