Class: Maze::Api::Appium::UiManager

Inherits:
Manager
  • Object
show all
Defined in:
lib/maze/api/appium/ui_manager.rb

Overview

Provides operations for working with the app.

Instance Method Summary collapse

Methods inherited from Manager

#fail_driver, #failed_driver?, #initialize

Constructor Details

This class inherits a constructor from Maze::Api::Appium::Manager

Instance Method Details

#click_element(element_id) ⇒ Object

Clicks a given element.

Parameters:

  • element_id (String)

    the element to click



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/maze/api/appium/ui_manager.rb', line 36

def click_element(element_id)
  if failed_driver?
    $logger.error 'Cannot click element - Appium driver failed.'
    return false
  end

  @driver.click_element(element_id)
  true
rescue Selenium::WebDriver::Error::ServerError => e
  $logger.error "Error clicking element #{element_id}: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e)
  raise e
end

#click_element_if_present(element_id) ⇒ Object

Clicks a given element if present.

Parameters:

  • element_id (String)

    the element to click



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/maze/api/appium/ui_manager.rb', line 82

def click_element_if_present(element_id)
  if failed_driver?
    $logger.error 'Cannot click element - Appium driver failed.'
    return false
  end

  @driver.click_element_if_present(element_id)
rescue Selenium::WebDriver::Error::ServerError => e
  $logger.error "Error clicking element #{element_id}: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e)
  raise e
end

#touch_at(x, y) ⇒ Object

Performs a touch operation at the given coordinates, using W3C actions.

Parameters:

  • x (Integer)

    X coordinate

  • y (Integer)

    Y coordinate



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/maze/api/appium/ui_manager.rb', line 57

def touch_at(x, y)
  if failed_driver?
    $logger.error 'Cannot perform touch - Appium driver failed.'
    return false
  end

  f1 = ::Selenium::WebDriver::Interactions.pointer(:touch, name: 'finger1')
  f1.create_pointer_move(duration: 1, x: x, y: y,
                         origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
  f1.create_pointer_down(:left)
  f1.create_pointer_up(:left)
  @driver.perform_actions([f1])
  true
rescue Selenium::WebDriver::Error::ServerError => e
  $logger.error "Error performing touch: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e)
  raise e
end

#wait_for_element(element_id, timeout = 15, retry_if_stale = true) ⇒ Object

Checks for an element, waiting until it is present or the method times out

Parameters:

  • element_id (String)

    the element to search for

  • timeout (Integer) (defaults to: 15)

    the maximum time to wait for an element to be present in seconds

  • retry_if_stale (Boolean) (defaults to: true)

    enables the method to retry acquiring the element if a StaleObjectException occurs



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/maze/api/appium/ui_manager.rb', line 17

def wait_for_element(element_id, timeout = 15, retry_if_stale = true)
  if failed_driver?
    $logger.error 'Cannot wait for element - Appium driver failed.'
    return false
  end

  @driver.wait_for_element(element_id, timeout, retry_if_stale)
rescue Selenium::WebDriver::Error::ServerError => e
  $logger.error "Error waiting for element #{element_id}: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e)
  raise e
end