Chamz Des
Chamz Des

Reputation: 183

Force selenium to use the portable firefox application

I have installed firefox 14 and has firefox portable version 25.0.1 on the machine, where I run tests for a web site.

Due to a limitation in the site I'm testing, I cannot run my tests on firefox 14 installation. Also I cannot upgrade the firefox 14 installation.

So I'm looking into a solution where I can use this portable firefox version instead of the installed firefox 14 version.

How should I force selenium to use this portable version and not the installed version? If someone could direct me to some descriptive article/blog that would be great.

My code goes like:-

* Variables *

${SELENIUM_HUB}     remote_url=http://127.0.0.1:4444/wd/hub
${BROWSER}      firefox D:\\Firefox Portable\\FirefoxPortable\\firefox.exe
${CLIENT_URL}       https://abcd.aline.local

Open Browser    ${CLIENT_URL}    ${BROWSER}   ${SELENIUM_HUB}

Specifying path as, D:/Firefox Portable/FirefoxPortable/firefox.exe does not work because '/' get's removed. Any thoughts?

PS: python is the used language

Upvotes: 8

Views: 8682

Answers (2)

Andrew Adams
Andrew Adams

Reputation: 71

You can specify the path to the firefox binary you want with the FirefoxBinary class passed as the firefox_binary parameter when instantiating your Firefox webdriver.

http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_binary.html

and

http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.webdriver.html#module-selenium.webdriver.firefox.webdriver

Make sure the path to the binary is correct with something like:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

firefox_binary = FirefoxBinary("D:\\Firefox Portable\\FirefoxPortable\\firefox.exe")
driver = webdriver.Firefox(firefox_binary=firefox_binary)

Using robotframework something like:

${firefox_binary}=  Evaluate    sys.modules['selenium.webdriver.firefox.firefox_binary'].FirefoxBinary("D:\\Firefox Portable\\FirefoxPortable\\firefox.exe")    sys, selenium.webdriver.firefox_binary
Create Webdriver    Firefox    firefox_binary=${firefox_binary}

may work.

Upvotes: 6

Harri
Harri

Reputation: 2732

Selenium2Library does not let you specify browser path in the Open Browser keyword, but it does have remote_url argument that can be useful. Before Selenium2Library got proper PhantomJS support the way to use PhantomJS was through that remote_url, like this http://spage.fi/phantomjs

So in theory we should be able to use portable Firefox first by launching our Firefox and then connecting to that using the remote_url. Something like this.

Start Process    c:\\path\\to\\portable\\firefox.exe
Open Browser    http://google.com    firefox    main browser    http://localhost:${firefox webdriver port}

The problem is that I do not know what webdriver port Firefox uses by default or how to specify it. Also installing the webdriver.xpi addon for Firefox might be necessary. The add-on can be found from here C:\Python27\Lib\site-packages\selenium\webdriver\firefox or what ever is the place where your python installation is.

There is a Create Webdriver keyword in Selenium2Library which does allow us to specify firefox_binary (among other arguments). So in theory

Create Webdriver    Firefox    firefox_binary=c:\\path\\to\\portable\\firefox.exe

Should work, but all I get from that is "AttributeError: 'str' object has no attribute 'launch_browser'".

Sorry that I could not figure out way to do this, but by digging a bit deeper about Firefox webdriver port or how Create Webdriver actually works you might get further.

Upvotes: 1

Related Questions