class SauceLabs::SauceBrowserFactory

This class has the code necessary to create an instance of browser after making a connection to saucelabs. This class can also be used to create browser instance for local connections

Attributes

options[RW]
persistent_http[RW]
url[RW]

Public Instance Methods

selenium_driver(browser,browser_options) click to toggle source

Creates a Selenium driver session and returns the driver object

@example SauceLabs.selenium_driver(browser = :chrome, browser_options = {}) @param [String] the browser string passed into the method @param [Hash] the optional hash to specify browser options @return [Object] browser session

# File lib/saucelabs/sauce_browser_factory.rb, line 40
def selenium_driver(browser,browser_options)
  target,options = browser_caps(browser,browser_options)
  create_selenium_driver(target,options)
end
watir_browser(browser,browser_options) click to toggle source

Creates a watir browser session and returns the browser object

@example SauceLabs.watir_browser(browser = :chrome, browser_options = {}) @param [String] the browser string passed into the method @param [Hash] the optional hash to specify browser options @return [Object] browser session

# File lib/saucelabs/sauce_browser_factory.rb, line 25
def watir_browser(browser,browser_options)
  target,options = browser_caps(browser,browser_options)
  create_watir_browser(target,options)
end

Private Instance Methods

browser_caps(browser,browser_options) click to toggle source

Returns the target and options including the capabilities

@param [String] the browser string passed into the method @param [Hash] the optional hash to specify browser options @return [Symbol,Hash] browser as symbol and options as Hash

# File lib/saucelabs/sauce_browser_factory.rb, line 81
def browser_caps(browser,browser_options)
  target = (browser.to_sym if ENV['BROWSER'].nil? or ENV['browser'].empty?) || (ENV['BROWSER'].to_sym)
  browser,version,platform,device = extract_values_from(target)
  options = {}
  options.merge! browser_options
  caps = capabilities(browser,version,platform,device)
  options[:url] = url if url
  if options.include? :url
    browser = :remote
    options[:desired_capabilities] = caps
  end
  options[:http_client] = http_client if persistent_http or options.delete(:persistent_http)
  return browser,options
end
capabilities(browser, version, platform,device={}) click to toggle source
# File lib/saucelabs/sauce_browser_factory.rb, line 97
def capabilities(browser, version, platform,device={})
  capabilities = Selenium::WebDriver::Remote::Capabilities.send browser
  capabilities.version = version unless version.nil? or version.empty?
  capabilities.platform = platform unless platform.nil? or platform.empty?
  capabilities.device = device unless device.nil? or device.empty?
  capabilities
end
create_selenium_driver(target,options) click to toggle source
# File lib/saucelabs/sauce_browser_factory.rb, line 65
def create_selenium_driver(target,options)
  if options.empty?
    Selenium::WebDriver.for target
  else
    Selenium::WebDriver.for target,options
  end
end
create_watir_browser(target,options) click to toggle source

def capybara_driver(browser,browser_options) Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => browser) end Capybara.default_driver = :selenium target,options = browser_caps(browser,browser_options) create_selenium_driver(target,options) end

# File lib/saucelabs/sauce_browser_factory.rb, line 57
def create_watir_browser(target,options)
  if options.empty?
    Watir::Browser.new target
  else
    Watir::Browser.new target,options
  end
end
http_client() click to toggle source

Returns a persistent http connection object

@return [Object] Persistent http connection object

# File lib/saucelabs/sauce_browser_factory.rb, line 111
def http_client
 client = Selenium::WebDriver::Remote::Http::Persistent.new
 #client.proxy_uri="http://abc"
 #client.read_timeout = 180
 #client.socket_options = {}
 client
end