Class: SeleniumPlus::Driver
- Inherits:
-
Object
- Object
- SeleniumPlus::Driver
- Includes:
- Finders
- Defined in:
- lib/selenium_plus/driver.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :browser => :firefox }
Instance Attribute Summary collapse
-
#native ⇒ Selenium::Webdriver::Driver
readonly
Start Selenium::Webdriver::Driver.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #active_element ⇒ Object
- #evaluate_script(script) ⇒ Object
- #execute_script(script) ⇒ Object
- #highlight_element(element) ⇒ Object
-
#initialize(options = {}) ⇒ Driver
constructor
A new instance of Driver.
- #quit ⇒ Object
- #reset! ⇒ Object
- #save_screenshot(path, options = {}) ⇒ Object
- #switch_to_frame(frame) ⇒ Object
- #switch_to_page ⇒ Object
- #visit(url) ⇒ Object
Methods included from Finders
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(={}) @native = nil @exit_status = nil @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#native ⇒ Selenium::Webdriver::Driver (readonly)
Start Selenium::Webdriver::Driver
19 20 21 |
# File 'lib/selenium_plus/driver.rb', line 19 def native @native end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/selenium_plus/driver.rb', line 8 def @options end |
Instance Method Details
#active_element ⇒ Object
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 |
#quit ⇒ Object
79 80 81 82 83 |
# File 'lib/selenium_plus/driver.rb', line 79 def quit @native.quit rescue Errno::ECONNREFUSED # Browser must have already gone end |
#reset! ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/selenium_plus/driver.rb', line 66 def reset! # Use instance variable directly so we avoid starting the browser just to reset the session if @native begin @native.manage. 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, ={}) native.save_screenshot(path) end |
#switch_to_frame(frame) ⇒ Object
58 59 60 |
# File 'lib/selenium_plus/driver.rb', line 58 def switch_to_frame(frame) native.switch_to.frame(frame) end |
#switch_to_page ⇒ Object
62 63 64 |
# File 'lib/selenium_plus/driver.rb', line 62 def switch_to_page native.switch_to.default_content end |
#visit(url) ⇒ Object
34 35 36 |
# File 'lib/selenium_plus/driver.rb', line 34 def visit(url) native.get(url) end |