Wednesday, March 29, 2006

Running the Selenium Twisted server on Linux

A recent issue that surfaced on the selenium-users mailing list was related to running Selenium in "Driven Mode" (soon to be dubbed Remote Control or RC mode) by using the Twisted-based Selenium server on Linux. Normand Savard had followed my initial instructions, but was getting CGI "premature end of script" errors. I tried to follow my own instructions using the latest Selenium code and I got the same error. I managed to get it to work, so I'm posting the steps I went through to solve it.

My setup was a Linux box running Ubuntu Breezy with Python 2.4.2.

1. Download and install Twisted version 1.3 (this is important, because things have been known not to work so well with Twisted 2.x). Old versions of Twisted, including 1.3, can be downloaded from here.

2. Check out the Selenium source code:

svn co http://svn.openqa.org/svn/selenium/trunk selenium

3. Let's assume you checked out the code in ~/proj/selenium. You need to copy the contents of ~/proj/selenium/code/javascript (the contents, not that directory itself) into the ~/proj/selenium/code/python/twisted/src/selenium/selenium_driver directory.

4. Cd into ~/proj/selenium/code/python/twisted/src/selenium/cgi-bin and do:

# dos2unix nph-proxy.cgi
# chmod +x nph-proxy.cgi


Now edit nph-proxy.cgi and replace the path to perl in the first line from the Windows-specific path that's in there by default, to the real path to perl on your Linux box (in my case it was /usr/bin/perl).

5. Cd into ~/proj/selenium/code/python/twisted/src/selenium and start the Selenium Twisted server:

# python selenium_server.py


To verify that the server is up and running, open this URL in a browser:

http://localhost:8080/selenium-driver/SeleneseRunner.html

You should see the Selenium Functional Test Runner page at this point. You can then close the browser.

6. Cd into ~/proj/selenium/code/python/twisted/src/examples and edit the file google-test-xmlrpc.py. Replace the line:

os.system('start run_firefox.bat')

with:

os.system("/usr/bin/firefox http://localhost:8080/selenium-driver/SeleneseRunner
.html &")


(you might need to replace /usr/bin/firefox with the actual path to firefox on your Linux box)

7. Run

# python google-test-xmlrpc.py

At this point, a Firefox window will be automatically opened, the browser will connect to the SeleneseRunner.html page and will execute the test commands specified in the google-test-xmlrpc.py script. You should see the bottom frame of the SeleneseRunner.html page open the Google home page, then enter a search phrase and run the search.

That's it. You're now the proud owner of a Driven Selenium installation.

For instructions on running the Selenium Twisted server on Windows, see this post. For resolutions of other various issues that people were faced with, see this other post.

2 comments:

John Mudd said...

I checked out the Selenium source code as suggested:
svn co http://svn.openqa.org/svn/selenium/trunk selenium

I found this directory:
~/proj/selenium/code/javascript

But not these:
~/proj/selenium/code/python/twisted/src/selenium/selenium_driver
~/proj/selenium/code/python/twisted/src/selenium/cgi-bin

Any suggestion?

John

John Mudd said...

Thanks anyway, I have Selenium-RC workng now.

http://johnmudd.infogami.com/blog/5be6

John

Modifying EC2 security groups via AWS Lambda functions

One task that comes up again and again is adding, removing or updating source CIDR blocks in various security groups in an EC2 infrastructur...