Module: LapisLazuli::BrowserModule::Remote
- Included in:
- LapisLazuli::Browser
- Defined in:
- lib/lapis_lazuli/browser/remote.rb
Instance Method Summary collapse
-
#remote_browser_config(settings) ⇒ Object
Convert settings to a valid remote driver argument.
Instance Method Details
#remote_browser_config(settings) ⇒ Object
Convert settings to a valid remote driver argument
Features:
- settings hash can be case insensitive "URL","Url", "url"
- caps.firefox_profile will be converted to a Selenium::WebDriver::Firefox::Profile
- caps.proxy / caps.firefox_profile.proxy will be converted to a Selenium::WebDriver::Proxy
- Hashes can have a String or a Symbol as key
Example:
args = remote_browser_config(
{
"url"=>"http://test.com",
"user"=>"user21",
"password"=>"jehwiufhewuf",
"caps"=> {
"browser_name"=>"firefox",
"version"=>"37",
"firefox_profile"=>{
"plugin.state.flash"=>0,
"secure_ssl"=>true,
"proxy"=>{"http"=>"test.com:9000"}
},
"proxy"=>{:http=>"test.com:7000"},
:css_selectors_enabled => true
}
})
Watir::Browser.new :remote, args
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/lapis_lazuli/browser/remote.rb', line 39 def remote_browser_config(settings) require "uri" require "selenium-webdriver" if !settings.is_a? Hash world.error("Missing Remote Browser Settings") end # Fetch the URl url = hash_get_case_insensitive(settings,"url") # Test if its a valid URL if not (url.to_s =~ /\A#{URI::regexp(["http", "https"])}\z/) raise "Incorrect Remote URL: '#{url.to_s}'" end # Create URI object uri = URI.parse(url) # Add user if needed user = hash_get_case_insensitive(settings,"user") if !user.nil? uri.user = user end # Add password if needed password = hash_get_case_insensitive(settings,"password") if !password.nil? uri.password = password end # Create capabil # Check ities caps = Selenium::WebDriver::Remote::Capabilities.new # Fetch the settings caps_settings = hash_get_case_insensitive(settings,"caps") # If we have settings if !caps_settings.nil? and caps_settings.is_a? Hash caps_settings.each do |key, val| # Convert to proxy if key.to_s == "proxy" set_proxy(caps, val) # Convert to FF profile elsif key.to_s == "firefox_profile" profile = Selenium::WebDriver::Firefox::Profile.new # Set all the options val.each do |fkey, fval| # Convert to proxy if fkey.to_s == "proxy" set_proxy(profile,fval) else set_key(profile, fkey, fval) end end # Set the profile caps[:firefox_profile] = profile else # Use set_key to assign the key set_key(caps, key, val) end end end world.log.debug("Using remote browser: #{url} (#{uri.user}) #{caps.to_json}") return { :url => uri.to_s, :desired_capabilities => caps } end |