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

new(driver) click to toggle source

@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() click to toggle source

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
browser?() click to toggle source

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() click to toggle source

Close current window @return [void]

# File lib/automation_object/driver/selenium_adapter/driver.rb, line 126
def close
  @subject.close
end
dismiss_prompt() click to toggle source

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
document_complete?() click to toggle source

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
exists?(selector_type, selector_path) click to toggle source

@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
find_element(selector_type, selector_path) click to toggle source

@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
find_elements(selector_type, selector_path) click to toggle source

@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
get(url) click to toggle source

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
quit() click to toggle source

Destroy the driver

# File lib/automation_object/driver/selenium_adapter/driver.rb, line 143
def quit
  @subject.quit
end
title() click to toggle source

Get the title of the document @return [String]

# File lib/automation_object/driver/selenium_adapter/driver.rb, line 36
def title
  @subject.title
end
wait(timeout = nil) click to toggle source

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
window_handle() click to toggle source

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
window_handle=(handle_value) click to toggle source

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() click to toggle source

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