[python] [rc] Please help with selenium.addCustomRequestHeader

464 views
Skip to first unread message

Robert Rollins

unread,
Sep 23, 2010, 7:06:40 PM9/23/10
to Selenium Users
Hi all. I was recently introduced to selenium, and I love it. I used
the IDE to make several tests to run against my web app, and it was so
easy and intuitive. However, I've now moved on to using Selenium RC
for more complex testing, and I've run into nothing but failure.

My main issue is that my web app requires a certain set of headers to
be present in the HTTP requests it gets. For my manual testing, I add
the headers with the Modify Headers addon for Firefox. However, for
some unknown reason, the instances of Firefox that the Selenium Server
launches consider Modify Headers to be "incompatible with Firefox
3.6.10". This makes no sense at all, because when I run Firefox with
the same profile, Modify Headers works just fine (I created a firefox
profile specifically for Selenium to use, and specified it with the -
firefoxProfileTemplate flag when I started the server).

So, with no access to the Modify Headers addon, I tried to find
another solution for adding custom headers, and I thought I'd found it
in the addCustomRequestHeader method of the selenium class.
Unfortunately, I must be using it wrong, or missing a step, or
something, because my web app still isn't getting the headers it
needs.

Here's my entire Python Selenium RC script:
from selenium.selenium import selenium
import unittest, time, re

class ConstantsArePresent(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox",
"http://localhost/")
self.selenium.addCustomRequestHeader("user", "jsmith")
self.selenium.addCustomRequestHeader("user_cn", "John Smith")
self.selenium.addCustomRequestHeader("UID", "87893478237")
self.selenium.addCustomRequestHeader("user_mail",
"OMI...@OMITTED.com")
self.selenium.start()

def test_constants_are_present(self):
sel = self.selenium
sel.open("events/contact/ranks")
try: self.assertEqual("Events: Ranks", sel.get_title())
except AssertionError, e:
self.verificationErrors.append(str(e))
try: self.assertEqual("----- Aenean", sel.get_text("ranks"))
except AssertionError, e:
self.verificationErrors.append(str(e))
try: self.assertEqual("List All People",
sel.get_text("link=List All People"))
except AssertionError, e:
self.verificationErrors.append(str(e))
try: self.assertEqual("List People By Division",
sel.get_text("link=List People By Division"))
except AssertionError, e:
self.verificationErrors.append(str(e))

def tearDown(self):
# This closes the browser instance, which for now I don't want
to do,
# so I can see what the browser display actually is.
#self.selenium.stop()

self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()


This code runs just fine, but my app fails when it discovers that the
headers are missing.

In my scouring of google for an answer to this problem, I read
something about an "addCustomRequestHeaders=true" argument to the
selenium.start() method... but selenium.start() doesn't take any
arguments in the python client code. I've looked through the java
code for Selenium Server, and I can tell that it's looking for that
"addCustomRequestHeaders=true" flag in the browserConfigurationOptions
object, but it's failing to find it because I can't figure out how to
specify that I want that option turned on.

The docstring for selenium.addCustomRequestHeader() says "This only
works if the browser is configured to use the built in Selenium
proxy." What is the built in Selenium proxy? How do I configure
firefox to use it?

I figure that I'm just missing some vital step that's blatantly
obvious to expert Selenium RC users, but the internet has completely
failed me so far, so I'm asking here. Please help!

Jayakumar C

unread,
Sep 24, 2010, 3:51:16 AM9/24/10
to seleniu...@googlegroups.com
Hi,

Im not yet used addCustomRequestHeader option in python client driver.however i can help you at some extend.

Get the latest selenium.py from,
http://selenium.googlecode.com/svn/trunk/selenium/src/py/selenium.py
There you can find the fix in start() method and you can pass the argument in that.

I believe ' built in Selenium proxy' meant for proxyInjectionMode.
For that you need to start the server as follows,
java -jar selenium-server.jar -proxyInjectionMode
and have to use the browser mode as  *pifirefox

Good luck!!



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Jayakumar

Robert Rollins

unread,
Sep 24, 2010, 1:01:31 PM9/24/10
to Selenium Users
Thank you so much for the quick response!! All I had to do was
install that new selenium.py file and call
selenium.start("addCustomRequestHeaders=true"), and it all works now!

On Sep 24, 12:51 am, Jayakumar C <jayakumaree...@gmail.com> wrote:
> Hi,
>
> Im not yet used addCustomRequestHeader option in python client
> driver.however i can help you at some extend.
>
> Get the latest selenium.py from,http://selenium.googlecode.com/svn/trunk/selenium/src/py/selenium.py
> There you can find the fix in start() method and you can pass the argument
> in that.
>
> I believe ' built in Selenium proxy' meant for proxyInjectionMode.
> For that you need to start the server as follows,
> java -jar selenium-server.jar -proxyInjectionMode
> and have to use the browser mode as  *pifirefox
>
> Good luck!!
>
> > "OMIT...@OMITTED.com")
> > selenium-user...@googlegroups.com<selenium-users%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages