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, #report_session, #retry_start_driver?, #start_driver, #start_session, #write_device_info

Constructor Details

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

Instance Method Details

#device_capabilitiesObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/maze/client/appium/bb_client.rb', line 62

def device_capabilities
  config = Maze.config
  common_caps = {
    'noReset' => true,
    'newCommandTimeout' => 600
  }
  capabilities = {
    'bitbar:options' => {
      'apiKey' => config.access_key,
      'app' => config.app,
      'findDevice' => false,
      'testTimeout' => 7200
    }
  }
  if Maze.config.appium_version && Maze.config.appium_version.to_f < 2.0
    capabilities.merge!(common_caps)
  else
    capabilities['appium:options'] = common_caps
  end
  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
44
45
46
47
48
49
# 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
  elsif error.message.include? 'Could not find a connected Android device'
    interval = 10
  elsif error.message.include? '\'platformVersion\' must be a valid version number.'
    interval = 10
  elsif error.message.include?('Device model with name') && error.message.include?('is currently unavailable')
    interval = 10
  else
    # Do not retry in any other case
  end

  Bugsnag.notify error if notify
  interval
end

#log_run_introObject



89
90
91
# File 'lib/maze/client/appium/bb_client.rb', line 89

def log_run_intro
  # Nothing to log at the start
end

#log_run_outroObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/maze/client/appium/bb_client.rb', line 93

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

  info = api_client.get_device_session_info(@session_metadata.id)
  if info
    link = Maze::Loggers::LogUtil.linkify(info[:dashboard_link], "BitBar session: #{@session_metadata.id}")
    $logger.info link
    @session_metadata.device = info[:device_name]
    $logger.info "Device used: #{@session_metadata.device}"
  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



51
52
53
54
55
56
57
58
59
60
# File 'lib/maze/client/appium/bb_client.rb', line 51

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



105
106
107
108
109
110
# File 'lib/maze/client/appium/bb_client.rb', line 105

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