Skip to content

TEST.setRequestHeader() ​

Sets the value of a single HTTP request header on the browser proxy.

When configured, this header is automatically attached to all subsequent outbound HTTP/HTTPS requests originating from the browser session, including:

  • Page navigations (I.goTo())
  • Sub-resource asset downloads (stylesheets, JavaScript files, images, fonts)
  • Asynchronous API calls (fetch, XMLHttpRequest) made by web pages
  • Embedded <iframe> document requests

Setting the value to null or undefined deletes the header from the proxy.

TIP

To set multiple headers at once, use TEST.setRequestHeaders().

Usage ​

js
TEST.setRequestHeader(name, value)
TEST.setRequestHeader(name, value, options)

Parameters ​

ParameterTypeDescription
namestringRequired.
Name of the HTTP request header to set. Must be a non-empty string.
valuestring | nullRequired.
Value of the request header. Non-string values will be converted to string. Setting to null or undefined deletes the header.
optionsobjectOptional configuration options (see below).

Options Object ​

OptionTypeDescription
msgstringCustom description message displayed for this step in the test report.

Variants ​

  • TEST.setRequestHeader(): Standard execution. Logs the step to the test report and throws an error if the header name is invalid or the proxy fails.
  • TEST.setRequestHeader$(): Error suppression mode. If an error occurs (e.g. invalid header name), the error is caught, a warning is logged, and execution continues without failing the test.
  • TEST.setRequestHeader$$(): Silent mode. Suppresses errors and hides the command step from test report logs.

Examples ​

Set an Authorization Header ​

js
// Set Bearer authentication token before navigating to protected portal
TEST.setRequestHeader("Authorization", "Bearer eyJhbGciOiJIUzI1Ni...")
I.goTo("https://app.example.com/dashboard")
I.see("Welcome back")

Set a Custom Bot Mitigation Token ​

js
// Attach Shopify Web Bot Access Token for automated storefront testing
TEST.setRequestHeader("X-Shopify-Access-Token", "shpat_test_access_token_123")
I.goTo("https://store.example.com")
I.see("Featured Products")

Delete a Header by Setting Value to null ​

js
// Remove authorization header to test unauthenticated guest flow
TEST.setRequestHeader("Authorization", null)
I.goTo("https://app.example.com/login")
I.see("Please sign in")

Provide a Custom Step Message ​

js
TEST.setRequestHeader("X-Feature-Gate", "new-checkout-v2", {
    msg: "Enable new checkout feature gate"
})

Use Error Suppression for Optional Headers ​

js
// Attempt to set header without failing the test if the proxy is unavailable
TEST.setRequestHeader$("X-Optional-Trace-ID", "trace-98765")