Currently, here is part of my configuration with testing using Chrome:
prefs = {
'download' => {
'default_directory' => "#{$myRoot}/PDF",
'prompt_for_download' => false,
},
'credentials_enable_service' => false,
'profile' => {
'default_content_settings' => {'multiple-automatic-downloads' => 1}, #for chrome version older ~42
'default_content_setting_values' => {'automatic_downloads' => 1}, #for chrome new 46
'password_manager_enabled' => false
}
}
caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps['chromeOptions'] = {:prefs => prefs}
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 600 # seconds – default is 60
client.open_timeout = 600 # seconds – default is 60
# @headless = Headless.new
driver = Watir::Browser.new :chrome, :desired_capabilities => caps, :http_client => client
Before do
@browser = driver
I am attempting to allow for use of Firefox as well using a similar set up as I found at http://www.agiletrailblazers.com/blog/advanced-selenium-multiple-browsers-and-environments , specifically by defining a getDriver method which uses a "BROWSER=" parameter in the command line:
Before do |scenario|
$url = getSiteURL
$driver = getDriver
$wait = Selenium::WebDriver::Wait.new(:timeout => 5) # seconds
end
def getDriver
driverPath = ENV['DRIVERPATH']
if ENV['BROWSER'] == "firefox"
if ENV['DRIVERPATH']
driverPath = ENV['DRIVERPATH'] + '/geckodriver'
return Selenium::WebDriver.for :firefox, driver_path: driverPath
else
return Selenium::WebDriver.for :firefox
end
elsif ENV['BROWSER'] == "chrome"
if ENV['DRIVERPATH']
driverPath = ENV['DRIVERPATH'] + '/chromedriver'
return Selenium::WebDriver.for :chrome, driver_path: driverPath
else
# This may not work with newer versions of Selenium and firefox
return Selenium::WebDriver.for :chrome
end
else
raise Exception.new("Unsupported browser: " + browser)
end
end
I made some changes where I set prefs, caps and client inside the definition, as well as expanding the definition for firefox, however, when I did that, I found that multiple Browser instances were being opened for each Scenario of the feature.
What should I change to avoid this, and how do I configure firefox to behave the same as how I have set up Chrome in the prefs?