Class: Maze::Client::Appium::BrowserStackClient

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

Direct Known Subclasses

BrowserStackLegacyClient

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/maze/client/appium/bs_client.rb', line 44

def device_capabilities
  config = Maze.config
  capabilities = {
    'app' => config.app,
    'deviceOrientation' => 'portrait',
    'noReset' => 'true',
    'bstack:options' => {}
  }
  device_caps = Maze::Client::Appium::BrowserStackDevices::DEVICE_HASH[config.device]
  capabilities.deep_merge! device_caps
  capabilities.deep_merge! JSON.parse(config.capabilities_option)
  capabilities.merge! project_name_capabilities
  capabilities['bstack:options']['appiumVersion'] = config.appium_version unless config.appium_version.nil?
  unless device_caps['platformName'] == 'android' && device_caps['platformVersion'].to_i <= 6
    capabilities['bstack:options']['disableAnimations'] = 'true'
  end
  if Maze.config.start_tunnel
    capabilities['bstack:options']['local'] = 'true'
    capabilities['bstack:options']['localIdentifier'] = Maze.run_uuid
  end

  capabilities
end

#handle_error(error) ⇒ Object

On BrowserStack, wait 10 seconds before retrying if there is another device in the list



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/maze/client/appium/bs_client.rb', line 19

def handle_error(error)
  Bugsnag.notify error unless error.nil?
  config = Maze.config
  if config.device_list.nil? || config.device_list.empty?
    $logger.error 'No further devices to try'
    nil
  else
    config.device = config.device_list.first
    config.device_list = config.device_list.drop(1)
    $logger.warn "Retrying driver initialisation using next device: #{config.device}"
    10
  end
end

#log_run_introObject



68
69
70
71
72
# File 'lib/maze/client/appium/bs_client.rb', line 68

def log_run_intro
  # Log a link to the BrowserStack session search dashboard
  url = "https://app-automate.browserstack.com/dashboard/v2/search?query=#{Maze.run_uuid}&type=builds"
  $logger.info Maze::Loggers::LogUtil.linkify(url, 'BrowserStack session(s)')
end

#log_run_outroObject



74
75
76
77
78
# File 'lib/maze/client/appium/bs_client.rb', line 74

def log_run_outro
  $logger.info 'Appium session(s) created:'
  @session_ids.each { |id| $logger.info "  #{id}" }
  log_run_intro
end

#prepare_sessionObject



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

def prepare_session
  # Upload the app and start the secure tunnel
  config = Maze.config
  config.app = Maze::Client::BrowserStackClientUtils.upload_app config.username,
                                                                config.access_key,
                                                                config.app
  if Maze.config.start_tunnel
    Maze::Client::BrowserStackClientUtils.start_local_tunnel config.bs_local,
                                                             Maze.run_uuid,
                                                             config.access_key
  end
end

#start_scenarioObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/maze/client/appium/bs_client.rb', line 33

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

  super
end

#stop_sessionObject



80
81
82
83
# File 'lib/maze/client/appium/bs_client.rb', line 80

def stop_session
  super
  Maze::Client::BrowserStackClientUtils.stop_local_tunnel if Maze.config.start_tunnel
end