Class: AutomationObject::Driver::AppiumAdapter::Driver

Inherits:
Proxy::Proxy
  • Object
show all
Includes:
CommonSelenium::Driver
Defined in:
lib/automation_object/driver/appium_adapter/driver.rb

Overview

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

Constant Summary

DOCUMENT_COMPLETE_LOOPS =
5
DOCUMENT_COMPLETE_SLEEP =
0.2

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommonSelenium::Driver

#back, #execute_script, #forward, #inner_window_height, #refresh, #scroll_position

Methods inherited from Proxy::Proxy

#method_missing

Constructor Details

#initialize(driver) ⇒ Driver

Returns a new instance of Driver

Parameters:

  • driver (Appium::Driver)

    Appium Driver



25
26
27
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 25

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 Attribute Details

#browserBoolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 88

def browser
  @browser
end

Instance Method Details

#accept_promptvoid

This method returns an undefined value.



78
79
80
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 78

def accept_prompt
  @subject.alert_accept
end

#browser?Boolean

Returns whether or not browser is being used

Returns:

  • (Boolean)

    whether or not browser is being used



97
98
99
100
101
102
103
104
105
106
107
108
# 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

#closevoid

This method returns an undefined value.

Close current window



163
164
165
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 163

def close
  @subject.close
end

#dismiss_promptvoid

This method returns an undefined value.



83
84
85
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 83

def dismiss_prompt
  @subject.alert_dismiss
end

#document_complete?Boolean

Returns document is complete

Returns:

  • (Boolean)

    document is complete



149
150
151
152
153
154
155
156
157
158
159
# 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) ⇒ Boolean

Returns exists or not

Parameters:

  • selector_type (Symbol)

    selector type (:css, :xpath, etc...)

  • selector_path (String)

    path to element

Returns:

  • (Boolean)

    exists or not



52
53
54
# 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) ⇒ AutomationObject::Driver::Element

Returns element

Parameters:

  • selector_type (Symbol)

    selector type, :css, :xpath, etc...

  • selector_path (String)

    path to element

Returns:



59
60
61
62
63
# 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) ⇒ Array<AutomationObject::Driver::Element>

Returns element

Parameters:

  • selector_type (Symbol)

    selector type, :css, :xpath, etc...

  • selector_path (String)

    path to element

Returns:



68
69
70
71
72
73
74
75
# 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) ⇒ void

This method returns an undefined value.

Navigates current window to a given url

Parameters:

  • url (String)

    navigate to the following url



32
33
34
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 32

def get(url)
  @subject.get(url)
end

#quitvoid

This method returns an undefined value.



168
169
170
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 168

def quit
  @subject.driver_quit
end

#titleString

Get the title of the document

Returns:



38
39
40
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 38

def title
  @subject.title
end

#wait(timeout = nil) ⇒ void

This method returns an undefined value.

Set timeout wait

Parameters:

  • timeout (Integer) (defaults to: nil)

    the timeout in seconds



45
46
47
# File 'lib/automation_object/driver/appium_adapter/driver.rb', line 45

def wait(timeout = nil)
  @subject.set_wait(timeout)
end

#window_handleString

Get window handle override

Returns:

  • (String)

    current window handle



129
130
131
132
133
134
135
# 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) ⇒ void

This method returns an undefined value.

Set window handle override

Parameters:

  • handle_value (String)

    window handle value



140
141
142
143
144
145
146
# 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_handlesArray<String>

Window Handles Override

Returns:

  • (Array<String>)

    array of window handles



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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