Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting request headers #740

Closed
mmaquevice opened this issue Apr 23, 2014 · 27 comments
Closed

setting request headers #740

mmaquevice opened this issue Apr 23, 2014 · 27 comments

Comments

@mmaquevice
Copy link

Hey,

I'm having difficulties setting headers in my requests (browser.get('/path');)
Is there a way to do so ?

Thanks !

@juliemr
Copy link
Member

juliemr commented Apr 23, 2014

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.

@juliemr juliemr closed this as completed Apr 23, 2014
@mmaquevice
Copy link
Author

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...

@YukonSaint
Copy link

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.

@armw4
Copy link

armw4 commented Jan 24, 2015

Custom headers would be more than nice. 👍

@sksamuel
Copy link

+1 using headers to enable things in non-prod env is very common. Please add this feature.

@sonata82
Copy link

sonata82 commented May 8, 2015

+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.

@stefanvangastel
Copy link

+1; We use SSO / Kerberos and I would like to imitate another user than me. Hence I need to set the Authorization header.

@ch0wdan
Copy link

ch0wdan commented Jun 9, 2015

+1 on adding headers

@nobso
Copy link

nobso commented Jul 15, 2015

+1 for modifying headers

@peterjcaulfield
Copy link

+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.

@britez
Copy link

britez commented Nov 3, 2015

+1 We don't want to log allways... we have a test case testing it. We need to bypass them. We want setting headers!

@ghost
Copy link

ghost commented Dec 16, 2015

+1

@sjelin
Copy link
Contributor

sjelin commented Dec 17, 2015

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.

@jackspaniel
Copy link

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.

@sjelin
Copy link
Contributor

sjelin commented Dec 17, 2015

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

@finspin
Copy link

finspin commented Feb 4, 2016

+1 for having the possibility to set request headers

@jackspaniel for setting a cookie you can use the browser.manage().addCookie() method.

@fabien7474
Copy link

+1 for setting/modifying request headers.

BTW, why this issue has been closed ?

@sjelin
Copy link
Contributor

sjelin commented Apr 1, 2016

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.

@g2graman
Copy link

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', '/')

@jackspaniel
Copy link

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.

@ch0wdan
Copy link

ch0wdan commented May 19, 2016

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.

SeleniumHQ/selenium#2131

@qualityshepherd
Copy link

+1 for modheaders - we use modheaders to access our app during a release... so this would make that easy.

@Schemiii
Copy link

+1

1 similar comment
@anderserikpersson
Copy link

+1

@ORESoftware
Copy link

ORESoftware commented Nov 7, 2017

workaround, just put the "headers" in the url

GET localhost:6969?my_headers={"a":"b"}

@ganqqwerty
Copy link

our app uses two-factor authentication and sends you an sms. It would be hard (impossible?) to login as user would normally login.

@tymfear
Copy link

tymfear commented May 16, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests