Class: Maze::Api::Appium::UiManager
- Defined in:
- lib/maze/api/appium/ui_manager.rb
Overview
Provides operations for working with the app.
Instance Method Summary collapse
-
#click_element(element_id) ⇒ Object
Clicks a given element.
-
#click_element_if_present(element_id) ⇒ Object
Clicks a given element if present.
-
#touch_at(x, y) ⇒ Object
Performs a touch operation at the given coordinates, using W3C actions.
-
#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.
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.
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.}" # 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.
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.}" # 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.
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.}" # 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
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.}" # Assume the remote appium session has stopped, so crash out of the session fail_driver(e) raise e end |