Appearance
TEST.setRequestHeaders()
Sets global HTTP request headers on the browser proxy.
TEST.setRequestHeaders() supports two usage patterns:
- Bulk Object Map: Passing a key-value object to set multiple headers at once.
- Key-Value Pair: Passing two strings representing the header name and value.
When headers are set, they are merged into the active proxy configuration and attached to all subsequent outbound HTTP/HTTPS requests originating from the browser (page navigations, sub-resources, asynchronous fetch/XHR, and iframes).
TIP
Existing headers not included in the call will remain active. To completely reset all headers, call TEST.clearRequestHeaders() first.
Usage
js
// Signature 1: Object map of headers
TEST.setRequestHeaders(headers)
TEST.setRequestHeaders(headers, options)
// Signature 2: Key and value pair
TEST.setRequestHeaders(name, value)
TEST.setRequestHeaders(name, value, options)Parameters
Signature 1: Object Map
| Parameter | Type | Description |
|---|---|---|
headers | object | Required. An object map where keys are header names and values are header values. Keys and values are converted to strings. |
options | object | Optional configuration options (see below). |
Signature 2: Key and Value Pair
| Parameter | Type | Description |
|---|---|---|
name | string | Required. Name of the HTTP request header to set. |
value | string | Required. Value of the request header. |
options | object | Optional configuration options (see below). |
Options Object
| Option | Type | Description |
|---|---|---|
msg | string | Custom description message displayed for this step in the test report. |
Variants
TEST.setRequestHeaders(): Standard execution. Logs the step to the test report and throws an error if arguments are invalid or the proxy fails.TEST.setRequestHeaders$(): Error suppression mode. If an error occurs, catches the error, logs a warning, and continues test execution without failing the step.TEST.setRequestHeaders$$(): Silent mode. Suppresses errors and hides the command step from the test report logs.
Examples
Bulk Set Multiple Request Headers
js
// Set authentication, environment routing, and bot mitigation headers together
TEST.setRequestHeaders({
"Authorization": "Bearer admin_token_xyz123",
"X-Environment": "staging",
"X-Shopify-Access-Token": "shpat_test_token_456",
"X-Feature-Gate": "beta-v2"
})
I.goTo("https://store.example.com/admin")
I.see("Admin Dashboard")Set a Single Header with Positional Arguments
js
TEST.setRequestHeaders("X-Correlation-ID", "corr-run-9876")Provide a Custom Step Message
js
TEST.setRequestHeaders({
"X-Test-Suite": "e2e-regression",
"X-Client-Platform": "web-automated-test"
}, {
msg: "Apply test suite routing and platform headers"
})Silent Mode ($$)
js
// Apply proxy headers silently without creating clutter in the test report
TEST.setRequestHeaders$$({
"X-Internal-Secret": "secret-bypass-token"
})