class AutomationObject::Driver::AppiumAdapter::Driver

Driver proxy for Appium Conform Appium driver interface to what's expected of the Driver Port

Constants

DOCUMENT_COMPLETE_LOOPS
DOCUMENT_COMPLETE_SLEEP

Attributes

browser[RW]

@return [Boolean]

Public Class Methods

new(driver) click to toggle source

@param driver [Appium::Driver] Appium Driver

# File lib/automation_object/driver/appium_adapter/driver.rb, line 25
def initialize(driver)
  @subject = driver
end

Public Instance Methods

accept_prompt() click to toggle source

@return [void]

# File lib/automation_object/driver/appium_adapter/driver.rb, line 78
def accept_prompt
  @subject.alert_accept
end
browser?() click to toggle source

@return [Boolean] whether or not browser is being used

# File lib/automation_object/driver/appium_adapter/driver.rb, line 97
def browser?
  # Now we need to check Appium's contexts to see if WEBVIEW is in available_contexts
  available_contexts = @subject.available_contexts
  available_contexts.each do |context|
    if context =~ /^WEBVIEW_\d+$/
      self.browser = true
      break
    end
  end

  browser
end
close() click to toggle source

Close current window @return [void]

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

@return [void]

# File lib/automation_object/driver/appium_adapter/driver.rb, line 83
def dismiss_prompt
  @subject.alert_dismiss
end
document_complete?() click to toggle source

@return [Boolean] document is complete

# File lib/automation_object/driver/appium_adapter/driver.rb, line 149
def document_complete?
  return true unless browser? # Skip for non-browser Appium sessions

  # 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/appium_adapter/driver.rb, line 52
def exists?(selector_type, selector_path)
  @subject.exists { @subject.find_element(selector_type, selector_path) }
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 [AutomationObject::Driver::Element] element

# File lib/automation_object/driver/appium_adapter/driver.rb, line 59
def find_element(selector_type, selector_path)
  element = @subject.find_element(selector_type, selector_path)
  # Wrap element in the 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 [Array<AutomationObject::Driver::Element>] element

# File lib/automation_object/driver/appium_adapter/driver.rb, line 68
def find_elements(selector_type, selector_path)
  elements = @subject.find_elements(selector_type, selector_path)

  elements.map do |element|
    # Wrap element in the adapter interface
    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/appium_adapter/driver.rb, line 32
def get(url)
  @subject.get(url)
end
quit() click to toggle source

@return [void]

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

Get the title of the document @return [String]

# File lib/automation_object/driver/appium_adapter/driver.rb, line 38
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/appium_adapter/driver.rb, line 45
def wait(timeout = nil)
  @subject.set_wait(timeout)
end
window_handle() click to toggle source

Get window handle override @return [String] current window handle

# File lib/automation_object/driver/appium_adapter/driver.rb, line 129
def window_handle
  return @subject.current_context unless browser?

  return @subject.window_handle if @subject.device_is_android?

  @subject.current_context
end
window_handle=(handle_value) click to toggle source

Set window handle override @param handle_value [String] window handle value @return [void]

# File lib/automation_object/driver/appium_adapter/driver.rb, line 140
def window_handle=(handle_value)
  if @subject.device_is_android?
    @subject.switch_to.window(handle_value)
  else
    @subject.set_context(handle_value)
  end
end
window_handles() click to toggle source

Window Handles Override @return [Array<String>] array of window handles

# File lib/automation_object/driver/appium_adapter/driver.rb, line 112
def window_handles
  if @subject.device_is_android? && browser?
    window_handles = @subject.window_handles
  else
    return @subject.available_contexts unless browser?

    window_handles = []
    @subject.available_contexts.each do |context|
      window_handles.push(context) if context =~ /^WEBVIEW_\d+$/
    end
  end

  window_handles
end