Hey,
I'm having difficulties setting headers in my requests (browser.get('/path');)
Is there a way to do so ?
Thanks !
Protractor (and webdriver, which it is built on top of) are intended to test your application like a user interacting with your page, so the meaning of browser.get is something like 'do what would happen if a user opened up a new tab and entered this URL'. So, there's no way to interact with under the hood things like setting headers, except for in the way that it would normally get done for your user.
Thanks for your quick reply. I suspected this reason, but it would have been useful for me to bypass our login system (a non angular page provided by a reverse proxy) by setting headers. I will find another way...
Well this may answer my question in another thread. I would like to suggest that in some cases it might be very useful to be able to either set request headers or somehow persist cookies across tests. We have a lot of annoying things like Take a Tour, surveys, etc. that pop up for a completely anonymous user.
We can direct our tests to close these things. But when you factor in load time of the feature, this adds several seconds to every test, which adds up when you have 1000s of tests eventually.
Custom headers would be more than nice. :+1:
+1 using headers to enable things in non-prod env is very common. Please add this feature.
+1
In my case the browsers in prod env have to go through proxy and authentication servers, which set a number of HTTP headers. Currently our solution is to proxy all requests from protractor through connect.
+1; We use SSO / Kerberos and I would like to imitate another user than me. Hence I need to set the Authorization header.
+1 on adding headers
+1 for modifying headers
+1 on adding headers. In my case, I want to be able to control different responses from the same user action coming back from a mocked API.
+1 We don't want to log allways... we have a test case testing it. We need to bypass them. We want setting headers!
+1
We'd need webdriver to implement this feature, which they've already rejected doing. You could try contacting them on their github but I don't think it will get you anywhere.
The selenium issue you linked does not seem to be the same thing we are asking for. People in that thread are asking to be able to test response headers going to protractor. We are asking to be able to set request headers coming from protractor to the server at the start of the test.
This functionality is to do things like simulate a logged in or "cookied" user w/o having to take the extra step of explicitly logging in every time.
Also in our case it could be used to bypass an annoying resource-consuming overlay which sets a cookie when the user closes it - telling it to not to show up the next time the page is loaded. As a workaround we have created dummy pages to set these cookies. But it slows the tests down when protractor first has to hit these dummy pages before every test.
We also use a WURFL-based tool called Scientia which sets a header to indicate the make, model, browser and OS of the various devices we support. It would be nice to be able to spoof this to test different device-specific behaviors.
Sorry, sounds like I linked to the wrong issue. This has been raised with WebDriver though and they have rejected it. @juliemr is probably more able to find the exact issue, but you could just make a new issue on their github
+1 for having the possibility to set request headers
@jackspaniel for setting a cookie you can use the browser.manage().addCookie() method.
+1 for setting/modifying request headers.
BTW, why this issue has been closed ?
It was closed because we'd need webdriver to implement this feature, which they've already rejected doing. You could try contacting them on their github but I don't think it will get you anywhere.
To add, though it does not seem possible to arbitrarily set request headers, if you just want to set cookies, that is at least possible with browser.manage().addCookie('foo', 'bar', '/')
It's been a while but if I recall correctly that doesn't actually send a cookie to the server with the request - it just registers in the browser that it received a cookie.
If you support having the ability to set request headers on tests, please go to this ticket and add +1 to the request. I just created it as it inherently has and is affecting the way i have to create tests.
+1 for modheaders - we use modheaders to access our app during a release... so this would make that easy.
+1
+1
workaround, just put the "headers" in the url
GET localhost:6969?my_headers={"a":"b"}
our app uses two-factor authentication and sends you an sms. It would be hard (impossible?) to login as user would normally login.
our app uses two-factor authentication and sends you an sms. It would be hard (impossible?) to login as user would normally login.
Just use Twilio number (they have even free one). Using Twilio API get an sms with the code. That's not difficult. https://www.twilio.com/docs/usage/api
Most helpful comment
If you support having the ability to set request headers on tests, please go to this ticket and add +1 to the request. I just created it as it inherently has and is affecting the way i have to create tests.
https://github.com/SeleniumHQ/selenium/issues/2131