Class: SeleniumPlus::Driver

Inherits:
Object
  • Object
show all
Includes:
Finders
Defined in:
lib/selenium_plus/driver.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ :browser => :firefox }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Finders

#find, #find_all

Constructor Details

#initialize(options = {}) ⇒ Driver

Returns a new instance of Driver.



10
11
12
13
14
# File 'lib/selenium_plus/driver.rb', line 10

def initialize(options={})
  @native = nil
  @exit_status = nil
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#nativeSelenium::Webdriver::Driver (readonly)

Start Selenium::Webdriver::Driver

Returns:

  • (Selenium::Webdriver::Driver)


19
20
21
# File 'lib/selenium_plus/driver.rb', line 19

def native
  @native
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/selenium_plus/driver.rb', line 8

def options
  @options
end

Instance Method Details

#active_elementObject



38
39
40
# File 'lib/selenium_plus/driver.rb', line 38

def active_element
  native.switch_to.active_element
end

#evaluate_script(script) ⇒ Object



50
51
52
# File 'lib/selenium_plus/driver.rb', line 50

def evaluate_script(script)
  native.execute_script("return #{script}")
end

#execute_script(script) ⇒ Object



46
47
48
# File 'lib/selenium_plus/driver.rb', line 46

def execute_script(script)
  native.execute_script(script)
end

#highlight_element(element) ⇒ Object



42
43
44
# File 'lib/selenium_plus/driver.rb', line 42

def highlight_element(element)
  native.execute_script("arguments[0].setAttribute('style', '#{element[:style]}; border: 2px solid red;')", element)
end

#quitObject



71
72
73
74
75
# File 'lib/selenium_plus/driver.rb', line 71

def quit
  @native.quit
rescue Errno::ECONNREFUSED
  # Browser must have already gone
end

#reset!Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/selenium_plus/driver.rb', line 58

def reset!
  # Use instance variable directly so we avoid starting the browser just to reset the session
  if @native
    begin @native.manage.delete_all_cookies
    rescue Selenium::WebDriver::Error::UnhandledError
      # delete_all_cookies fails when we've previously gone
      # to about:blank, so we rescue this error and do nothing
      # instead.
    end
    @native.navigate.to('about:blank')
  end
end

#save_screenshot(path, options = {}) ⇒ Object



54
55
56
# File 'lib/selenium_plus/driver.rb', line 54

def save_screenshot(path, options={})
  native.save_screenshot(path)
end

#visit(url) ⇒ Object



34
35
36
# File 'lib/selenium_plus/driver.rb', line 34

def visit(url)
  native.get(url)
end