Class: Maze::Client::Appium::BitBarDevices
- Inherits:
-
Object
- Object
- Maze::Client::Appium::BitBarDevices
- Defined in:
- lib/maze/client/appium/bb_devices.rb
Overview
Provides a source of capabilities used to run tests against specific BitBar devices noinspection RubyStringKeysInHashInspection
Class Method Summary collapse
- .android_base_hash ⇒ Object
-
.get_available_device(device_or_group_names) ⇒ Object
Uses the BitBar API to find an available device from the group name given, or a device of that name device.
- .ios_base_hash ⇒ Object
- .list_device_groups(access_key) ⇒ Object
- .list_devices_for_group(device_group, access_key) ⇒ Object
- .make_android_hash(device, group_id = false) ⇒ Object
- .make_ios_hash(device, group_id = false) ⇒ Object
Class Method Details
.android_base_hash ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/maze/client/appium/bb_devices.rb', line 115 def android_base_hash = { 'automationName' => 'UiAutomator2', 'autoGrantPermissions' => true, 'uiautomator2ServerInstallTimeout' => 60000, 'uiautomator2ServerLaunchTimeout' => 60000 } ['appActivity'] = Maze.config.app_activity unless Maze.config.app_activity.nil? ['appPackage'] = Maze.config.app_package unless Maze.config.app_package.nil? hash = { 'platformName' => 'Android', 'deviceName' => 'Android Phone' } if Maze.config.appium_version && Maze.config.appium_version.to_f < 2.0 hash.merge!() else hash['appium:options'] = end hash.dup end |
.get_available_device(device_or_group_names) ⇒ Object
Uses the BitBar API to find an available device from the group name given, or a device of that name device. Multiple device group names can be separated by a pipe.
15 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/maze/client/appium/bb_devices.rb', line 15 def get_available_device(device_or_group_names) api_client = BitBarApiClient.new(Maze.config.access_key) device_group_ids = api_client.get_device_group_ids(device_or_group_names) if device_group_ids # Device group found - find a free device in it $logger.trace "Got group ids #{device_group_ids} for #{device_or_group_names}" if device_group_ids.size > 1 group_id = false group_count, device = api_client.find_device_in_groups(device_group_ids) if device.nil? raise 'There are no devices available' else $logger.info "#{group_count} device(s) currently available in group(s) '#{device_or_group_names}'" end else # Since there is only one group, we can use it verbatim $logger.info "Using device group #{device_or_group_names}" group_id = true device_name = device_group_ids.first end else # See if there is a device with the given name device = api_client.find_device device_or_group_names end # If a single device has been identified use that to determine other characteristics if device device_name = device['displayName'] platform = device['platform'].downcase platform_version = device['softwareVersion']['releaseVersion'] $logger.info "Selected device: #{device_name} (#{platform} #{platform_version})" else # If a device group has been identified, extrapolate characteristics from the group name if android_match = Regexp.new('(ANDROID|android)_(\d{1,2})').match(device_or_group_names) platform = 'android' platform_version = android_match[2] elsif ios_match = Regexp.new('(IOS|ios)_(\d{1,2})').match(device_or_group_names) platform = 'ios' platform_version = ios_match[2] end $logger.info "Selected device group: #{device_or_group_names} (#{platform} #{platform_version})" end # TODO: Setting the config here is rather a side effect and factoring it out would be better. # For now, though, it means not having to provide the --os and --os-version options on the command line. Maze.config.os = platform Maze.config.os_version = platform_version.to_f.floor case platform when 'android' make_android_hash(device_name, group_id) when 'ios' make_ios_hash(device_name, group_id) else throw "Invalid device platform specified #{platform}" end end |
.ios_base_hash ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/maze/client/appium/bb_devices.rb', line 150 def ios_base_hash = { 'automationName' => 'XCUITest', 'shouldTerminateApp' => 'true', 'autoAcceptAlerts' => 'true' } hash = { 'platformName' => 'iOS', 'deviceName' => 'iPhone device', } if Maze.config.appium_version && Maze.config.appium_version.to_f < 2.0 hash.merge!() else hash['appium:options'] = end hash.dup end |
.list_device_groups(access_key) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/maze/client/appium/bb_devices.rb', line 75 def list_device_groups(access_key) api_client = BitBarApiClient.new(access_key) device_groups = api_client.get_device_group_list unless device_groups['data'] && !device_groups['data'].empty? puts 'There are no device groups available for the given user access key' exit 1 end puts "BitBar device groups available:" device_groups['data'].sort_by{|g| g['displayName']}.each do |group| puts '------------------------------' puts "Group name : #{group['displayName']}" puts "OS : #{group['osType']}" puts "Device count : #{group['deviceCount']}" end end |
.list_devices_for_group(device_group, access_key) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/maze/client/appium/bb_devices.rb', line 91 def list_devices_for_group(device_group, access_key) api_client = BitBarApiClient.new(access_key) group_id = api_client.get_device_group_id(device_group) unless group_id puts "No device groups were found with the given name #{device_group}" return end devices = api_client.get_device_list_for_group(group_id) if devices['data'].empty? puts "There are no devices available for the #{device_group} device group" return end puts "BitBar devices available for device group #{device_group}:" devices['data'].sort_by{|d| d['displayName']}.each do |device| puts '------------------------------' puts "Device name : #{device['displayName']}" puts "OS : #{device['platform']} #{device['softwareVersion']['releaseVersion']}" if device['platform'].eql? 'ANDROID' puts "API level : #{device['softwareVersion']['apiLevel']}" end end end |
.make_android_hash(device, group_id = false) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/maze/client/appium/bb_devices.rb', line 136 def make_android_hash(device, group_id = false) hash = android_base_hash if group_id hash['bitbar:options'] = { 'deviceGroupId' => device } else hash['bitbar:options'] = { 'device' => device } end hash.freeze end |
.make_ios_hash(device, group_id = false) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/maze/client/appium/bb_devices.rb', line 168 def make_ios_hash(device, group_id = false) hash = ios_base_hash if group_id hash['bitbar:options'] = { 'deviceGroupId' => device } else hash['bitbar:options'] = { 'device' => device } end hash.freeze end |