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

[FR] Specify headers #3

Open
gravis opened this issue Jun 3, 2009 · 12 comments
Open

[FR] Specify headers #3

gravis opened this issue Jun 3, 2009 · 12 comments

Comments

@gravis
Copy link

gravis commented Jun 3, 2009

Hi,

would it be possible to define custom headers for selenium-client ?
I'm especially thinking to something like the webrat header method (http://gitrdoc.com/rdoc/brynary/webrat/481bfe03c0829a7d858443ceb6a51e1587a0d931/classes/Webrat/Session.html#M000101)
Ex : header
Thanks !

@gravis
Copy link
Author

gravis commented Jun 3, 2009

(ps : the idea is to be able to set the "Accept-Language" header to something like "fr")

@aptinio
Copy link

aptinio commented Jun 9, 2009

AFAIK, this is not possible, since selenium only drives the browser. An alternative is to modify the headers on the browser i.e. by using the Modify Headers addon for firefox.

@scnaegle
Copy link

I tried using the Modify Headers addon for firefox and it works great when I open it up by hand, but whenever I run it through Selenium it tells me that the Modify Headers addon is "Not compatible with Firefox 3.5.8". I'm not sure what the problem is. Does Selenium automatically disable this addon for firefox or am I just missing something? Any ideas?

@aptinio
Copy link

aptinio commented May 28, 2010

You'll need to create a Firefox profile just for Selenium. Add the Modify Headers addon to that profile. Then tell Selenium RC server to use this profile, i.e.:
java -jar selenium-server.jar -firefoxProfileTemplate "path/to/profile"

@scnaegle
Copy link

scnaegle commented Jun 3, 2010

Ok, So I have done all of that. I created a selenium profile and I'm using the selenium-rc gem so the way I start selenium looks like this:

selenium-rc -debug -timeout 60 -firefoxProfileTemplate "/home/scnaegl/.mozilla/firefox/4ufai4g9.selenium/"

However, just to make sure, I went and got the profile switcher addon for firefox from here:

https://nic-nac-project.org/~kaosmos/profileswitcher-en.html

I installed the profile switcher addon on my default profile first and when I ran the selenium it didn't show as if I even had the addon. Then I installed the addon for my selenium profile and ran it again. This time, I could see that the profile switcher addon was indeed installed, however it showed as not having any profile at all.

So here is how I am setting up the Selenium Client Driver if that helps:

$selenium = Selenium::Client::Driver.new(
:host => "localhost",
:port => 4444,
:browser => "*firefox",
:url => "http://localhost:8888/wctool",
:timeout_in_seconds => 60)

I have tried using :browser => "*custom /usr/lib/firefox-3.5.8/firefox -P selenium" but whenever I do that the browser comes up, but the second browser for selenium controls never comes up and it just hangs and eventually times out.

I'm not sure what I am doing wrong, but as you can see I've tried all kinds of things and nothing seems to work completely.

@glitterylally
Copy link

Hallo, I'm having exactly the same problem, did you manage to solve it?
Thanks Laura :)

@scnaegle
Copy link

Oh good, so someone else is having the same problem and I'm not just crazy lol Well I haven't been able to fix the problem yet. I've run out of ideas and I'm hesitating trying to drill into the heart of the java selenium source, which is where I think the problem really is. Let me know if you come up with a solution.

@coredumperror
Copy link

I'm having the exact same problem. Did anyone ever manage to fix this issue? It's a total showstopper for my use of Selenium RC.

@aptinio
Copy link

aptinio commented Sep 24, 2010

The Modify Headers add-on will have to be installed by manually launching your Firefox profile for selenium first. If you add the Modify Headers add-on during a Selenium RC session, it will be discarded after you close Selenium RC.

Here are the steps:

  1. Close all Firefox instances and stop all Selenium RC server instances.
  2. In a terminal run "firefox -ProfileManager"
  3. Click "Create Profile"
  4. Click "Next"
  5. Enter a new profile name, e.g. "selenium_profile"
  6. Click "Choose Folder" and browse to (or create) a folder for your selenium profile, e.g. /home/user/path/to/selenium_profile
  7. Click "Finish"
  8. Exit the Firefox profile manager
  9. Back in the terminal, run "firefox -P selenium_profile"
  10. Firefox will start using your selenium_profile. Add the Modify Headers addon here. Now is also the time to modify any settings or options for your Firefox profile for Selenium
  11. Close Firefox
  12. Tell Selenium RC to use your customized Firefox profile:

java -jar selenium-server.jar -firefoxProfileTemplate "/home/user/path/to/selenium_profile"

I hope this helps.

@coredumperror
Copy link

Thanks for the quick reply, aptinio! Unfortunately, I already did exactly that, and it didn't help. My initial problem was in fact because of the way selenium uses a throw-away profile unless told otherwise, but I figured that out and did the steps you described to make a profile specifcally for Selenium RC to use. However, even when Selenium was using this profile (I could tell it worked because Firebug is installed and working when Selenium runs my tests), Modify Headers still didn't work. For some reason Firefox considers Modify Headers to be "Incompatible with Firefox 3.6.10" when Selenium launches the browser. However, when I launch it, using firefox -P selenium_profile, Modify Headers works fine. I can only assume that this is some kind of bug in Selenium RC.

@coredumperror
Copy link

Ah HA! I posted on the selenium-users google group, and a wonderful responder showed me how to get around this issue with Modify Headers. There is an API in the Selenium RC client driver that allows us to specify custom headers. Here's how to do it in python code:
self.selenium = selenium("localhost", 4444, "*firefox", "http://localhost/")
self.selenium.addCustomRequestHeader("user", "user_name")
self.selenium.addCustomRequestHeader("user_cn", "User Name")
self.selenium.addCustomRequestHeader("UID", "87893478237")
self.selenium.addCustomRequestHeader("user_mail", "[email protected]")
self.selenium.start("addCustomRequestHeaders=true")

It should be fairly similar in other languages. Until this problem with Modify Headers being erroneously detected as incompatible is resolved, this seems to be the only way to get custom headers in your HTTP requests for Selenium RC tests.

@aptinio
Copy link

aptinio commented Sep 28, 2010

There's one more thing you can possibly try: Disable extension compatibility checking in Firefox (using your Selenium profile):

http://kb.mozillazine.org/Extensions.checkCompatibility

  1. Type about:config in the address bar and hit enter
  2. Click "I'll be careful".
  3. Right-click anywhere on the list.
  4. Select New > Boolean
  5. Enter "extensions.checkCompatibility.3.6" as the preference name
  6. Select false

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

No branches or pull requests

5 participants