Class: Maze::Client::Appium::BitBarClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/maze/client/appium/bb_client.rb

Constant Summary

Constants inherited from BaseClient

Maze::Client::Appium::BaseClient::FIXTURE_CONFIG

Instance Method Summary collapse

Methods inherited from BaseClient

#attempt_start_driver, #initialize, #maze_address, #retry_start_driver?, #start_driver, #start_session

Constructor Details

This class inherits a constructor from Maze::Client::Appium::BaseClient

Instance Method Details

#device_capabilitiesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/maze/client/appium/bb_client.rb', line 56

def device_capabilities
  # Doubling up on capabilities in both the `appium:options` and `appium` sub dictionaries.
  # See PLAT-11087
  config = Maze.config
  common_caps = {
    'noReset' => true,
    'newCommandTimeout' => 600
  }
  capabilities = {
    'appium:options' => common_caps,
    'appium' => common_caps,
    'bitbar:options' => {
      # Some capabilities probably belong in the top level
      # of the hash, but BitBar picks them up from here.
      'apiKey' => config.access_key,
      'app' => config.app,
      'findDevice' => false,
      'testTimeout' => 7200
    }
  }
  capabilities.deep_merge! common_caps
  capabilities.deep_merge! BitBarClientUtils.dashboard_capabilities
  capabilities.deep_merge! BitBarDevices.get_available_device(config.device)
  capabilities['bitbar:options']['appiumVersion'] = config.appium_version unless config.appium_version.nil?
  capabilities.deep_merge! JSON.parse(config.capabilities_option)

  capabilities
end

#handle_error(error) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/maze/client/appium/bb_client.rb', line 16

def handle_error(error)
  # Retry interval depends on the error message
  return nil if error.nil?

  interval = nil
  notify = true

  if error.message.include? 'no sessionId in returned payload'
    # This will happen naturally due to a race condition in how we access devices
    # Do not notify, but wait long enough for most ghost sessions on BitBar to terminate.
    interval = 60
    notify = false
  elsif error.message.include? 'You reached the account concurrency limit'
    # In theory this shouldn't happen, but back off if it does
    interval = 300
  elsif error.message.include? 'There are no devices available'
    interval = 120
  elsif error.message.include? 'Appium Settings app is not running'
    interval = 10
  elsif error.message.include? 'Could not proxy command to the remote server'
    interval = 10
  else
    # Do not retry in any other case
  end

  Bugsnag.notify error if notify
  interval
end

#log_run_introObject



85
86
87
# File 'lib/maze/client/appium/bb_client.rb', line 85

def log_run_intro
  # Nothing to log at the start
end

#log_run_outroObject



89
90
91
92
93
94
95
96
97
# File 'lib/maze/client/appium/bb_client.rb', line 89

def log_run_outro
  api_client = BitBarApiClient.new(Maze.config.access_key)

  $logger.info 'Appium session(s) created:'
  @session_ids.each do |id|
    link = api_client.get_device_session_ui_link(id)
    $logger.info Maze::Loggers::LogUtil.linkify(link, "BitBar session: #{id}") if link
  end
end

#prepare_sessionObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/maze/client/appium/bb_client.rb', line 5

def prepare_session
  config = Maze.config
  config.app = Maze::Client::BitBarClientUtils.upload_app config.access_key,
                                                          config.app
  if Maze::Client::BitBarClientUtils.use_local_tunnel?
    Maze::Client::BitBarClientUtils.start_local_tunnel config.sb_local,
                                                       config.username,
                                                       config.access_key
  end
end

#start_scenarioObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/maze/client/appium/bb_client.rb', line 45

def start_scenario
  unless Maze.config.legacy_driver?
    # Write Maze's address to file and push to the device
    maze_address = Maze.public_address || "local:#{Maze.config.port}"
    Maze::Api::Appium::FileManager.new.write_app_file(JSON.generate({ maze_address: maze_address }),
                                                      FIXTURE_CONFIG)
  end

  super
end

#stop_sessionObject



99
100
101
102
103
104
# File 'lib/maze/client/appium/bb_client.rb', line 99

def stop_session
  super
  if Maze::Client::BitBarClientUtils.use_local_tunnel?
    Maze::Client::BitBarClientUtils.stop_local_tunnel
  end
end