class AutomationObject::Driver::SeleniumAdapter::Driver
Driver
proxy for Selenium Conform Selenium driver interface to what's expected of the Driver
Port
Constants
- DOCUMENT_COMPLETE_LOOPS
- DOCUMENT_COMPLETE_SLEEP
Public Class Methods
@param driver [Selenium::WebDriver::Driver] Selenium Web Driver
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 23 def initialize(driver) @subject = driver end
Public Instance Methods
Accept prompt either in browser or mobile
# 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
Check if browser, more useful for Appium but can be generic here @return [Boolean] whether or not browser is being used
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 102 def browser? true end
Close current window @return [void]
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 126 def close @subject.close end
Dismiss the prompt
# 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
Run script in browser to check if document in JS is complete @return [Boolean] document is complete
# 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
@param selector_type [Symbol] selector type (:css, :xpath, etc…) @param selector_path [String] path to element @return [Boolean] exists or not
# 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
@param selector_type [Symbol] selector type, :css, :xpath, etc… @param selector_path [String] path to element @return [Object] element
# 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
@param selector_type [Symbol] selector type, :css, :xpath, etc… @param selector_path [String] path to element @return [Object] element
# 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
Navigates current window to a given url @param url [String] navigate to the following url @return [void]
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 30 def get(url) @subject.navigate.to(url) end
Destroy the driver
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 143 def quit @subject.quit end
Get the title of the document @return [String]
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 36 def title @subject.title end
Set timeout wait @param timeout [Integer] the timeout in seconds @return [void]
# 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
Current window handle @return [String] handle id
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 114 def window_handle @subject.window_handle end
Set current window handle to, will switch windows @param handle_value [String] window handle value
# 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 @return [Array<String>] array of window handle ids
# File lib/automation_object/driver/selenium_adapter/driver.rb, line 108 def window_handles @subject.window_handles end