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

#initialize, #maze_address, #start_driver, #start_session

Constructor Details

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

Instance Method Details

#dashboard_capabilitiesHash

Determines capabilities used to organise sessions in the BitBar dashboard.

Returns:

  • (Hash)

    A hash containing the capabilities.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/maze/client/appium/bb_client.rb', line 72

def dashboard_capabilities

  # Determine project name
  if ENV['BUILDKITE']
    $logger.info 'Using BUILDKITE_PIPELINE_SLUG for BitBar project name'
    project = ENV['BUILDKITE_PIPELINE_SLUG']
  else
    # Attempt to use the current git repo
    output, status = Maze::Runner.run_command('git rev-parse --show-toplevel')
    if status == 0
      project = File.basename(output[0].strip)
    else
      $logger.warn 'Unable to determine project name, consider running Maze Runner from within a Git repository'
      project = 'Unknown'
    end
  end

  # Test run
  if ENV['BUILDKITE']
    bk_retry = ENV['BUILDKITE_RETRY_COUNT']
    retry_string = if !bk_retry.nil? && bk_retry.to_i > 1
                     " (#{bk_retry})"
                   else
                     ''
                   end
    test_run = "#{ENV['BUILDKITE_BUILD_NUMBER']} - #{ENV['BUILDKITE_LABEL']}#{retry_string}"
  else
    test_run = Maze.run_uuid
  end

  $logger.info "BitBar project name: #{project}"
  $logger.info "BitBar test run: #{test_run}"
  {
    'bitbar:options' => {
      bitbar_project: project,
      bitbar_testrun: test_run
    }
  }
end

#device_capabilitiesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/maze/client/appium/bb_client.rb', line 27

def device_capabilities
  config = Maze.config
  prefix = BitBarDevices.caps_prefix(config.appium_version)
  capabilities = {
    "#{prefix}noReset" => true,
    "#{prefix}newCommandTimeout" => 0,
    '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! dashboard_capabilities
  capabilities.deep_merge! BitBarDevices.get_available_device(config.device)
  capabilities.deep_merge! JSON.parse(config.capabilities_option)
  capabilities
end

#log_run_introObject



48
49
50
# File 'lib/maze/client/appium/bb_client.rb', line 48

def log_run_intro
  # Nothing to log at the start
end

#log_run_outroObject



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

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::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



16
17
18
19
20
21
22
23
24
25
# File 'lib/maze/client/appium/bb_client.rb', line 16

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



62
63
64
65
66
67
# File 'lib/maze/client/appium/bb_client.rb', line 62

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