So I been digging the web (google, stackoverflow, github) trying to find a simple way to add custom headers to my tests. So far nothing pop out. Maybe some thing for java or firefox, but nothing clear.
I'm using:
So what i would like is that headers would propagate in all tests including 302 Redirects
before: {
this.setHeaders = {
"X-CUSTOM-HEADER-A": "Data-A",
"X-CUSTOM-HEADER-B": "Data-B",
}
}
Is there something like this avaliable? Any chromedriver args maybe?
The new Nightwatch 2.x release supports talking to CDP. So for Chrome, you can use the following. You have to call 'Network.enable' first to enable the Network dev commands. (This took a little trial-and-error.)
await browser.chrome.sendDevToolsCommand('Network.enable')
await browser.chrome.sendDevToolsCommand('Network.setExtraHTTPHeaders',
{
headers:
{
"X-CUSTOM-HEADER-A": "Data-A",
"X-CUSTOM-HEADER-B": "Data-B"
}
})
More info on the dev tool commands in Nightwatch: https://nightwatchjs.org/api/commands/#using-chrome-devtools-protocol
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With