Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Firefox Extension I added in Selenium Webdriver?

I know that you can load up either an existing Firefox profile, or create one using Ruby Bindings in the selenium-webdriver gem, as described here:

http://code.google.com/p/selenium/wiki/RubyBindings

And then use add_extension to add any number of Firefox extensions to the instance, but then what? The window for the extension I'm using does not appear during the test. How do I use the extension?

Is there a way to have the extension be open by default when the driver opens Firefox?

Here is the code I'm using:

#!/usr/bin/env ruby
require "rubygems"
require "selenium-webdriver"

default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.add_extension("/Users/******/Library/Application Support/Firef\
ox/Profiles/wvon3h99.default/extensions/{9c51bd27-6ed8-4000-a2bf-36cb95c0c947}.\
xpi")

driver = Selenium::WebDriver.for(:firefox, :profile => default_profile)
driver.navigate.to "http://google.com"

element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit

puts driver.title

driver.quit
like image 690
Kotsu Avatar asked Jul 20 '11 20:07

Kotsu


1 Answers

It depends on extension. Usually the extension's behaviour can be to some extent controlled by setting appropriate properties (the ones you can find in about:config) when creating an FF profile. For instance to have Firebug window open by default after FF starts I would include the following line in my code:

default_profile["extensions.firebug.allPagesActivation"] = true

The extensions I use usually have some kind of auto-export feature that automatically sends data to server or saves it on disk. I am afraid there is no way of controlling an extension with WebDriver so not all extensions will be usable in automated tests.

like image 91
JacekM Avatar answered Oct 16 '22 21:10

JacekM