Reputation: 47
my learning for ruby and watir webdriver is ongoing and i was wondering if there is a way to set the browser to be used from the command line when running a rb script, eg c:\ruby login.rb --set browser
I've done some looking around and can find nothing specific, any help would be greatly appreciated.
thanks
Upvotes: 0
Views: 1134
Reputation: 115
I do the same with an environment variable; taking from @Skjoldan code, this would be the minimal to set your browser via environment variable:
case ENV['BROWSER']
when 'ff'
@b = Watir::Browser.new :firefox
else
@b = Watir::Browser.new :chrome
end
No environment variable set, defaults to chrome.
Upvotes: 1
Reputation: 58
This is what I do.
My code has the following:
case ENV['BROWSER']
when 'ff', 'Firefox'
@b = Watir::Browser.new :firefox
browser_name = 'Firefox'
when 'chrome'
@b = Watir::Browser.new :chrome
browser_name = 'Chrome'
when 'debug'
debug_profile = Selenium::WebDriver::Firefox::Profile.new
debug_profile.add_extension "firebug-1.9.1-fx.xpi"
@b = Watir::Browser.new :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"
@b = Watir::Browser.new :firefox, :profile => mobile_profile
browser_name = 'Mobile'
when 'ie'
@b = Watir::Browser.new :ie
browser_name = 'Chrome'
when 'headless'
@b ||= Watir::Browser.new :phantomjs
browser_name = 'phantomjs'
else
@b = Watir::Browser.new :firefox
browser_name = 'Firefox'
#@b ||= Watir::Browser.new :chrome
end
I can then set the browser variable in the cmd prompt before I run the test:
set BROWSER=Environment_ID
Upvotes: 3