Thursday, November 18, 2010

Specifying firefox path in selenium

Selenium sometimes throw the error saying it cannot open firefox and asks the user to set the path.
Please add the directory containing ''firefox.exe'' to your PATH environment
variable
, or explicitly specify a path to Firefox 3 like this:
*firefox3c:\blah\firefox.exe
I tried setting the path of firefox in the environment variable PATH but somehow it didn't work. So here is how to explictly specify it

@selenium = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
:url => "http://abc.com"

This solved the issue and opened firefox.

There was another issue of firefox opening in a small window during a test run and I wanted it to open a maximized size. In ruby this is how I solved this :-

In setup section after opening browser session, say window_maximize

@selenium.start_new_browser_session
@selenium.window_maximize