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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sauce/selenium.rb', line 47

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 = ::Selenium::WebDriver.for(: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

  @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



66
67
68
# File 'lib/sauce/selenium.rb', line 66

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config



35
36
37
# File 'lib/sauce/selenium.rb', line 35

def config
  @config
end

#driverObject (readonly)

Returns the value of attribute driver



35
36
37
# File 'lib/sauce/selenium.rb', line 35

def driver
  @driver
end

Class Method Details

.used_at_least_onceObject



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

def self.used_at_least_once
  @used_at_least_once = true
end

.used_at_least_once?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/sauce/selenium.rb', line 39

def self.used_at_least_once?
  @used_at_least_once || false
end

Instance Method Details

#current_urlObject



74
75
76
# File 'lib/sauce/selenium.rb', line 74

def current_url
  @driver.current_url
end

#session_idObject



70
71
72
# File 'lib/sauce/selenium.rb', line 70

def session_id
  @driver.send(:bridge).session_id
end

#stopObject



78
79
80
# File 'lib/sauce/selenium.rb', line 78

def stop
  @driver.quit
end