Monday, November 24, 2008

Getting Selenium & Firefox3 to Work on Ubuntu

(BACKGROUND: I've upgraded my notebook & since i hope to focus more time on software development, this time round, i've decided to install something that just work out of the box, and i've chosen to install ubuntu instead of debian, despite being a debian user for the past 5 years.)

Since i'm a BDD fan these days, and i simply love writing cucumber's features, so there i was trying to get the bundled selenium example to run:

#$ git-clone git://
#$ cd /examples/selenium
#$ rake features

And i got stack trace screaming "/usr/lib/ruby/1.8/net/http.rb:560:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)" ... OOPS, seems that i've forgotten to install selenium & run selenium:

#$ sudo gem install Selenium
#$ selenium

And i see the console displaying positive dump:
java  -jar /usr/lib/ruby/gems/1.8/gems/Selenium-1.1.14/lib/selenium/openqa/selenium-server.jar.txt 
20:47:29.661 INFO - Java: Sun Microsystems Inc. 1.6.0_0-b12
20:47:29.662 INFO - OS: Linux 2.6.27-7-generic amd64
So far so good, and rolling up my sleeves:

#$ rake features

After getting some green steps, i got a stack trace ... Switching to my selenium console shows:
java.lang.RuntimeException: Firefox couldn't be found in the path!
Please add the directory containing 'firefox-bin' to your PATH environment
variable, or explicitly specify a path to Firefox like this:
*firefox /blah/blah/firefox-bin
OK, its turns out that i need to specify the binary for firefox, as indicated by 'firefox-bin'. Having done some fishing round, i open up /examples/selenium/features/step_definitons/stories_steps.rb to edit the "*chrome" string to "*chrome /usr/lib/firefox-3.0.4/firefox-3.0", thus getting the following block:
Before do
@browser =
"localhost", 4444, "*chrome /usr/lib/firefox-3.0.4/firefox-3.0",
"http://localhost", 15000 )
Confident that things should work as expected this time, i did:

#$ rake features

Arrgghh, this time selenium console hangs at:
21:00:29.455 INFO - creating new remote session
21:00:29.627 INFO - Allocated session 202cd7534d044c81a66e027960e3d79b for http://localhost, launching...
21:00:29.745 INFO - Preparing Firefox profile...
After some googling round, i've found a solution, it turns out that the selenium bundled selenium-server.jar.txt (yup, the *.txt is intentional) needs some tweaking, and fortunately for me, there is already a one available for me to use, and i simply did:

#$ cd /usr/lib/ruby/gems/1.8/gems/Selenium-1.1.14/lib/selenium/openqa
#$ sudo mv selenium-server.jar.txt selenium-server.jar.txt.orig
#$ sudo wget

And after restarting my selenium, and running the rake tasks, i'm assured i have the environment for writing features using cucumber+selenium :] ... 3 cheers !!

No comments: