Class: AutomationObject::Driver::SeleniumAdapter::Driver
- Inherits:
-
Proxy::Proxy
- Object
- Proxy::Proxy
- AutomationObject::Driver::SeleniumAdapter::Driver
- Includes:
- CommonSelenium::Driver
- Defined in:
- lib/automation_object/driver/selenium_adapter/driver.rb
Overview
Driver proxy for Selenium Conform Selenium driver interface to what's expected of the Driver Port
Constant Summary
- DOCUMENT_COMPLETE_LOOPS =
5
- DOCUMENT_COMPLETE_SLEEP =
0.2
Instance Method Summary collapse
-
#accept_prompt ⇒ Object
Accept prompt either in browser or mobile.
-
#browser? ⇒ Boolean
Check if browser, more useful for Appium but can be generic here.
-
#close ⇒ void
Close current window.
-
#dismiss_prompt ⇒ Object
Dismiss the prompt.
-
#document_complete? ⇒ Boolean
Run script in browser to check if document in JS is complete.
-
#exists?(selector_type, selector_path) ⇒ Boolean
Exists or not.
-
#find_element(selector_type, selector_path) ⇒ Object
Element.
-
#find_elements(selector_type, selector_path) ⇒ Object
Element.
-
#get(url) ⇒ void
Navigates current window to a given url.
-
#initialize(driver) ⇒ Driver
constructor
A new instance of Driver.
-
#quit ⇒ Object
Destroy the driver.
-
#title ⇒ String
Get the title of the document.
-
#wait(timeout = nil) ⇒ void
Set timeout wait.
-
#window_handle ⇒ String
Current window handle.
-
#window_handle=(handle_value) ⇒ Object
Set current window handle to, will switch windows.
-
#window_handles ⇒ Array<String>
Window Handles.
Methods included from CommonSelenium::Driver
#back, #execute_script, #forward, #inner_window_height, #refresh, #scroll_position
Methods inherited from Proxy::Proxy
Constructor Details
#initialize(driver) ⇒ Driver
Returns a new instance of Driver
23 24 25 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 23 def initialize(driver) @subject = driver end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AutomationObject::Proxy::Proxy
Instance Method Details
#accept_prompt ⇒ Object
Accept prompt either in browser or mobile
87 88 89 90 91 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 87 def accept_prompt alert = @subject.switch_to.alert alert.accept @subject.switch_to.default_content end |
#browser? ⇒ Boolean
Check if browser, more useful for Appium but can be generic here
102 103 104 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 102 def browser? true end |
#close ⇒ void
This method returns an undefined value.
Close current window
126 127 128 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 126 def close @subject.close end |
#dismiss_prompt ⇒ Object
Dismiss the prompt
94 95 96 97 98 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 94 def dismiss_prompt alert = @subject.switch_to.alert alert.dismiss @subject.switch_to.default_content end |
#document_complete? ⇒ Boolean
Run script in browser to check if document in JS is complete
132 133 134 135 136 137 138 139 140 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 132 def document_complete? # Loop through a few times to double check correctness DOCUMENT_COMPLETE_LOOPS.times do sleep(DOCUMENT_COMPLETE_SLEEP) return false unless @subject.execute_script('return document.readyState;') == 'complete' end true end |
#exists?(selector_type, selector_path) ⇒ Boolean
Returns exists or not
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 51 def exists?(selector_type, selector_path) exists = false begin element_objects = @subject.find_elements(selector_type, selector_path) exists = true unless element_objects.empty? rescue StandardError => e puts e return false end exists end |
#find_element(selector_type, selector_path) ⇒ Object
Returns element
68 69 70 71 72 73 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 68 def find_element(selector_type, selector_path) element = @subject.find_element(selector_type, selector_path) # Wrap in adapter interface AutomationObject::Driver::Element.new(Element.new(self, element)) end |
#find_elements(selector_type, selector_path) ⇒ Object
Returns element
78 79 80 81 82 83 84 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 78 def find_elements(selector_type, selector_path) elements = @subject.find_elements(selector_type, selector_path) elements.map do |element| AutomationObject::Driver::Element.new(Element.new(self, element)) end end |
#get(url) ⇒ void
This method returns an undefined value.
Navigates current window to a given url
30 31 32 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 30 def get(url) @subject.navigate.to(url) end |
#quit ⇒ Object
Destroy the driver
143 144 145 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 143 def quit @subject.quit end |
#title ⇒ String
Get the title of the document
36 37 38 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 36 def title @subject.title end |
#wait(timeout = nil) ⇒ void
This method returns an undefined value.
Set timeout wait
43 44 45 46 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 43 def wait(timeout = nil) timeout = 0 unless timeout @subject.manage.timeouts.implicit_wait = timeout end |
#window_handle ⇒ String
Current window handle
114 115 116 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 114 def window_handle @subject.window_handle end |
#window_handle=(handle_value) ⇒ Object
Set current window handle to, will switch windows
120 121 122 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 120 def window_handle=(handle_value) @subject.switch_to.window(handle_value) end |
#window_handles ⇒ Array<String>
Window Handles
108 109 110 |
# File 'lib/automation_object/driver/selenium_adapter/driver.rb', line 108 def window_handles @subject.window_handles end |