Running tests in multiple browsers with ruby + watir-webdriver + cucumber and stone parallel_tests
I am currently using the parallel profile in cucumber.yml to download the environment specific file and hooks.rb to install the browser. I am running my tests using the parallel_cucumber functions. There are not many in my hooks.rb file:
Before do
@browser = Watir::Browser.new :firefox
end
After do
@browser.close
end
The profile looks like this:
parallel: FIG_NEWTON_FILE=local.yml --no-source --color --format pretty
Is there a way to modify the hooks.rb file so that all functionality runs against multiple browsers (firefox, chrome, safari)? Is it possible to pass the filename or environment through the command line?
+1
source to share
1 answer
You can pass the environment name through the command line. Check the env.rb file:
case ENV['BROWSER']
when 'ff', 'Firefox'
browser = Selenium::WebDriver.for :firefox
browser_name = 'Firefox'
when 'chrome'
browser = Selenium::WebDriver.for :chrome
browser_name = 'Chrome'
when 'debug'
debug_profile = Selenium::WebDriver::Firefox::Profile.new
debug_profile.add_extension "firebug-1.9.1-fx.xpi"
browser = Selenium::WebDriver.for :firefox, :profile => debug_profile
browser_name = 'Firefox (Firebug)'
when 'mobile'
mobile_profile = Selenium::WebDriver::Firefox::Profile.new
mobile_profile['general.useragent.override'] = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
AppleWebKit/420+ (KHTML, like Gecko) Version/3.0
Mobile/1A535b Safari/419.3"
browser = Selenium::WebDriver.for :firefox, :profile => mobile_profile
browser_name = 'Mobile'
when 'headless'
headless_profile = Headless.new
headless_profile.start
browser = Selenium::WebDriver.for :firefox
browser_name = 'Firefox'
else
browser = Selenium::WebDriver.for :firefox
browser_name = 'Firefox'
end
if URLS[ENV['URL']].nil?
environment = 'dev'
url = 'http://' + URLS['dev']
domain = URLS['dev']
else
environment = ENV['URL'].upcase
url = 'http://' + URLS[ENV['URL']]
domain = URLS[ENV['URL']]
end
if ENV['CLIENT'].nil?
client = 'user/password'
else
client = ENV['CLIENT']
end
puts "Browser " + browser_name
puts "URL " + url
puts "Environment: " + environment
puts "Client: " + client
puts "Domain: " + domain
test_env = { :browser => browser,
:browser_name => browser_name,
:url => url,
:env => environment,
:client => client,
:login => nil,
:domain => domain }
Now when I run the cucumber, I call the environment by doing:
Cucumber BROWSER = ff
+4
source to share