Class: Maze::Hooks::AppiumHooks
- Inherits:
-
InternalHooks
- Object
- InternalHooks
- Maze::Hooks::AppiumHooks
- Defined in:
- lib/maze/hooks/appium_hooks.rb
Overview
Hooks for Appium mode use
Constant Summary collapse
- APPIUM_DRIVER_FAILED_ERRORS =
[ Selenium::WebDriver::Error::UnknownError, Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::WebDriverError ]
Instance Method Summary collapse
- #after(scenario) ⇒ Object
- #after_all ⇒ Object
- #at_exit ⇒ Object
- #before(scenario) ⇒ Object
- #before_all ⇒ Object
Methods inherited from InternalHooks
Instance Method Details
#after(scenario) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/maze/hooks/appium_hooks.rb', line 32 def after(scenario) if scenario.failed? Maze.driver = nil if driver_has_failed? $logger.warn('The appium driver has failed, removing it to prevent future errors') end if Maze.config.os == 'macos' # Close the app - without the sleep, launching the app for the next scenario intermittently fails system("killall -KILL #{Maze.config.app} && sleep 1") elsif [:bb, :bs, :local].include? Maze.config.farm # Reset the server to ensure that test fixtures cannot fetch # commands from the previous scenario (in idempotent mode). begin Maze.driver.terminate_app Maze.driver&.app_id rescue Selenium::WebDriver::Error::UnknownError, Selenium::WebDriver::Error::InvalidSessionIdError if Maze.config.appium_version && Maze.config.appium_version.to_f < 2.0 $logger.warn 'terminate_app failed, using the slower but more forceful close_app instead' Maze.driver&.close_app else $logger.warn 'terminate_app failed, future errors may occur if the application did not close remotely' end end Maze::Server.reset! Maze.driver.activate_app Maze.driver.app_id end rescue => error # Notify and re-raise for Cucumber to handle Bugsnag.notify error raise end |
#after_all ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/maze/hooks/appium_hooks.rb', line 63 def after_all if $success Maze::Plugins::DatadogMetricsPlugin.send_increment('appium.test_succeeded') else Maze::Plugins::DatadogMetricsPlugin.send_increment('appium.test_failed') end rescue => error # Notify and re-raise for Cucumber to handle Bugsnag.notify error raise end |
#at_exit ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/maze/hooks/appium_hooks.rb', line 75 def at_exit if @client @client.log_run_outro $logger.info 'Stopping the Appium session' @client.stop_session end end |
#before(scenario) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/maze/hooks/appium_hooks.rb', line 24 def before(scenario) @client.start_scenario rescue => error # Notify and re-raise for Cucumber to handle Bugsnag.notify error raise end |
#before_all ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/maze/hooks/appium_hooks.rb', line 15 def before_all Maze::Plugins::DatadogMetricsPlugin.send_increment('appium.test_started') @client = Maze::Client::Appium.start rescue => error # Notify and re-raise for Cucumber to handle Bugsnag.notify error raise end |