My application requires custom http headers for getting authorised. Without that i can't load the home page. While doing so not able to set custom headers anywhere in Night watch config
That is beside the scope of an automated UI test. You cannot do that with Selenium.
@beatfactor
Are you really sure about that or you just assumed it?
Setting the headers on requests, is for sure a requirement for automated UI tests.
You can do this with the Java selenium webdriver, so I'm not sure what lead you to jump into this assumption.
Could you elaborate a bit on this ? I really need to set some headers for testing and I'm finding it difficult to follow you here.
Cheers.
Any news on this ? @beatfactor
It's still not possible, and I am maintaining my point that is beyond the scope of a UI test. The link posted above provides a workaround for achieving that through a Firefox extension. Defining a custom Firefox profile (which contains the extension) should be possible with Nightwatch as well.
I disagree that it's beyond the scope. If in order to test your UI you must authenticate, and to authenticate you need to set auth headers (such as is the case with Cloudflare) then it makes sense that there should be support for setting headers. We run our e2e tests against locally running servers as a pre push step, sure, but we also target a remote staging environment that requires headers. I can imagine a few other cases where it would be useful as well, such as setting a header that puts your UI in to a test mode, or that alters behavior on a production site so that your tests are non destructive.
Route your requests through a proxy that adds headers. It's a more portable option that doesn't require messing around with extensions and browser profiles that might break between versions
Most helpful comment
@beatfactor
Are you really sure about that or you just assumed it?
Setting the headers on requests, is for sure a requirement for automated UI tests.
You can do this with the Java selenium webdriver, so I'm not sure what lead you to jump into this assumption.
https://eveningsamurai.wordpress.com/2013/11/21/changing-http-headers-for-a-selenium-webdriver-request/
Could you elaborate a bit on this ? I really need to set some headers for testing and I'm finding it difficult to follow you here.
Cheers.