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.message)
  raise e
end

#click_element_if_present(element_id) ⇒ Object

Clicks a given element if present.

Parameters:

  • element_id (String)

    the element to click



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/maze/api/appium/ui_manager.rb', line 56

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.message)
  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.message)
  raise e
end