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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/maze/hooks/appium_hooks.rb', line 25

def after(scenario)

  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
    write_device_logs(scenario) if scenario.failed?

    # 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
      $logger.warn 'terminate_app failed, using the slower but more forceful close_app instead'
      Maze.driver.close_app
    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_allObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/maze/hooks/appium_hooks.rb', line 50

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



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

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

#before(scenario) ⇒ Object



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

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

#before_allObject



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

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