Set Request Header

Set Request Header #

client.setRequestHeader(headerName, headerValue);

This function allows updating the header values for any requests that browser sends out. The parameter headerName is the name of the request header to be changed. The parameter headerValue is used to set a new value for the specified header.

To reset request header to its default value, passnullas the new header value.
Setting headerValueto an empty string will actually update the request header value to an empty string.
client => {
    // Example of setting custom request header value
    client
        // Open page and create screenshot with default request header
        .url('https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending')
        .waitForElementVisible('#content-base', 10 * 1000)
        .takeScreenshot('default_headers.png')

        // Set custom request header, reload the page and create screenshot
        .setRequestHeader('Accept-Language', 'lv-LV')
        .refresh()
        .waitForElementVisible('#content-base', 10 * 1000)
        .takeScreenshot('custom_headers.png')

        // Reset request header, reload the page and create screenshot
        .setRequestHeader('Accept-Language', null)
        .refresh()
        .waitForElementVisible('#content-base', 2000)
        .takeScreenshot('reset_headers.png');
}