Class: Maze::Hooks::AppiumHooks

Inherits:
InternalHooks show all
Defined in:
lib/maze/hooks/appium_hooks.rb

Overview

Hooks for Appium mode use

Instance Method Summary collapse

Methods inherited from InternalHooks

#pre_complete

Instance Method Details

#after(scenario) ⇒ Object



26
27
28
29
30
31
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
# File 'lib/maze/hooks/appium_hooks.rb', line 26

def after(scenario)
  $logger.debug "Appium after hook"

  manager = Maze::Api::Appium::AppManager.new
  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
    close_fallback = Maze.config.appium_version && Maze.config.appium_version.to_f < 2.0
    begin
      manager.terminate(!close_fallback)
    rescue Selenium::WebDriver::Error::UnknownError, Selenium::WebDriver::Error::InvalidSessionIdError => e
      if close_fallback
        Bugsnag.notify(e)
        $logger.warn 'terminate_app failed, using the slower but more forceful close_app instead'
        manager.close
      else
        $logger.warn 'terminate_app failed, future errors may occur if the application did not close properly'
      end
    end

    # Reset the server before relaunching the app to ensure that test fixtures cannot fetch
    # commands from the previous scenario (in idempotent mode).
    Maze::Server.reset!
    manager.activate
  end
rescue => error
  # Notify and re-raise for Cucumber to handle
  Bugsnag.notify error
  raise
end

#after_allObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/maze/hooks/appium_hooks.rb', line 58

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_exitObject



70
71
72
73
74
75
76
# File 'lib/maze/hooks/appium_hooks.rb', line 70

def at_exit
  if @client
    @client.log_run_outro
    $logger.info 'Stopping the Appium session'
    @client.stop_session
  end
end

#before(scenario) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/maze/hooks/appium_hooks.rb', line 18

def before(scenario)
  @client.start_scenario
rescue => error
  # Notify and re-raise for Cucumber to handle
  Bugsnag.notify error
  raise
end

#before_allObject



9
10
11
12
13
14
15
16
# File 'lib/maze/hooks/appium_hooks.rb', line 9

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