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



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

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
# 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
  else
    # Do not retry in any other case
  end

  Bugsnag.notify error if notify
  interval
end

#log_run_introObject



87
88
89
# File 'lib/maze/client/appium/bb_client.rb', line 87

def log_run_intro
  # Nothing to log at the start
end

#log_run_outroObject



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

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



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

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



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

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