Firefoxdriver and authorizing all plugins

Hello,

I am working on the automation of tests with ruby using watir-webdriver
and selenium environment. I am refactoring code that was designed for
older firefox versions. But it seems that on the latest version (v34),
the plugins are disabled by default, which impacts my tests.

I figured out that I have to set the created borwser preference
‘plugin.default.state’ to the value “2” in order to bypass this. But I
don’t managed to do it properly.

For other browsers like chrome we are using capabilities to set
properties as we need, but I didn’t find if I can do the same for
firefox : I think I have to set up a dedicated profile and here is where
I am stuck.

Here is my code before refactoring (extract):

require ‘watir-webdriver’
(…)
def open_browser
$problem_browser = false
case $browsername
when ‘firefox’
caps = Selenium::WebDriver::Remote::Capabilities.firefox
(…)
if $problem_browser == false
caps[“platform”] = $os_without_version
$b = Watir::Browser.new(
:remote,
:url => “http://my_url/wd/hub”,
:desired_capabilities => caps
)
end
end
(…)

and now, I have modified it to this :

require ‘watir-webdriver’
(…)
def open_browser
$problem_browser = false
case $browsername
when ‘firefox’
caps = Selenium::WebDriver::Remote::Capabilities.firefox
aFirefoxprofile = Selenium::WebDriver::Firefox::Profile.new
aFirefoxProfile[‘plugin.default.state’] = 2
caps =
Selenium::WebDriver::Remote::Capabilities.firefox(“firefox_profile” =>
aFirefoxProfile)
(…)
if $problem_browser == false
caps[“platform”] = $os_without_version
$b = Watir::Browser.new(
:remote,
:url => “http://my_url/wd/hub”,
:desired_capabilities => caps
)
end
end
(…)

But it seems that the “new” method does not create the profile I want.

the assignment Selenium::WebDriver::Remote::Capabilities.firefox is
working without requiring the selenium gem, but not the
Selenium::WebDriver::Firefox::Profile.new ? Am I doing it wrong ?

Sorry for my ignorance and thank you by advance for your attention.

When you say:

“the assignment Selenium::WebDriver::Remote::Capabilities.firefox is
working without requiring the selenium gem, but not the
Selenium::WebDriver::Firefox::Profile.new”;

What error message do you get? What line of code does it point to?

As below, it works for me:

irb(main):001:0> require ‘watir-webdriver’
=> true
irb(main):002:0> profile = Selenium::WebDriver::Firefox::Profile.new
=> #<Selenium::WebDriver::Firefox::Profile:0x2c03d90 @model=nil,
@native_events=true, @secure_ssl=false, @untrusted_issuer=true,
@load_no_focus_lib=false, @additional_prefs={}, @extensions={}>

Generally if I want to load my standard plugins, I just use the default
profile:

profile = Selenium::WebDriver::Firefox::Profile.from_name(‘default’)
=> #<Selenium::WebDriver::Firefox::Profile:0x3c9c510 …
b = Watir::Browser.new :firefox, :profile => profile
=> #<Watir::Browser:0x5b5a3372 url=“about:blank” title=“”>
b.goto ‘about:robots’
=> “about:robots”

I put some webdriver code from an old project on Github. I think I could
probably write better code now, but you might be able to pick up some
ideas from it: