Class: Sauce::Selenium2

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sauce/selenium.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Selenium2

Returns a new instance of Selenium2.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sauce/selenium.rb', line 54

def initialize(opts={})
  @config = Sauce::Config.new(opts)
  http_client = ::Selenium::WebDriver::Remote::Http::Persistent.new
  http_client.timeout = 300 # Browser launch can take a while

  @driver = Sauce.webdriver_method.call(:remote,
                  :url => "http://#{@config.username}:#{@config.access_key}@#{@config.host}:#{@config.port}/wd/hub",
                  :desired_capabilities => @config.to_desired_capabilities,
                  :http_client => http_client)
  http_client.timeout = 90 # Once the browser is up, commands should time out reasonably

  @watir = defined?(Watir::Browser) && @driver.is_a?(Watir::Browser)
  @raw_driver = watir ? @driver.driver : @driver

  raw_driver.file_detector = lambda do |args|
    file_path = args.first.to_s
    File.exist?(file_path) ? file_path : false
  end

  Sauce::Selenium2.used_at_least_once
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



76
77
78
# File 'lib/sauce/selenium.rb', line 76

def method_missing(meth, *args)
  @driver.send(meth, *args)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



42
43
44
# File 'lib/sauce/selenium.rb', line 42

def config
  @config
end

#driverObject (readonly)

Returns the value of attribute driver.



42
43
44
# File 'lib/sauce/selenium.rb', line 42

def driver
  @driver
end

#raw_driverObject (readonly)

Returns the value of attribute raw_driver.



42
43
44
# File 'lib/sauce/selenium.rb', line 42

def raw_driver
  @raw_driver
end

#watirObject (readonly)

Returns the value of attribute watir.



42
43
44
# File 'lib/sauce/selenium.rb', line 42

def watir
  @watir
end

Class Method Details

.used_at_least_onceObject



50
51
52
# File 'lib/sauce/selenium.rb', line 50

def self.used_at_least_once
  @used_at_least_once = true
end

.used_at_least_once?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/sauce/selenium.rb', line 46

def self.used_at_least_once?
  @used_at_least_once || false
end

Instance Method Details

#current_urlObject



84
85
86
# File 'lib/sauce/selenium.rb', line 84

def current_url
  raw_driver.current_url
end

#session_idObject



80
81
82
# File 'lib/sauce/selenium.rb', line 80

def session_id
  raw_driver.send(:bridge).session_id
end

#stopObject



88
89
90
# File 'lib/sauce/selenium.rb', line 88

def stop
  @driver.quit
end