Class: Maze::Client::Appium::BrowserStackDevices

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

Overview

Provides a source of capabilities used to run tests against specific BrowserStack devices noinspection RubyStringKeysInHashInspection

Constant Summary collapse

DEVICE_HASH =

The hash of device capabilities, accessible by simple names

create_hash

Class Method Summary collapse

Class Method Details

.add_android(device, version, hash) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/maze/client/appium/bs_devices.rb', line 41

def add_android(device, version, hash)
  # Key format is "ANDROID_<version>_<device>", with:
  # - dots in versions and all spaces replaced with underscores
  # - device made upper case
  name = device.upcase.gsub ' ', '_'
  new_version = version.gsub '.', '_'
  key = "ANDROID_#{new_version}_#{name}"
  hash[key] = make_android_hash device, version
end

.add_ios(device, version, hash) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/maze/client/appium/bs_devices.rb', line 60

def add_ios(device, version, hash)
  # Key format is "IOS_<version>_<device>", with:
  # - dots in versions and all spaces replaced with underscores
  # - device made upper case
  name = device.upcase.gsub ' ', '_'
  name = name.gsub '.', '_'
  new_version = version.gsub '.', '_'
  key = "IOS_#{new_version}_#{name}"
  hash[key] = make_ios_hash device, version
end

.create_hashObject



71
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
111
112
113
114
115
# File 'lib/maze/client/appium/bs_devices.rb', line 71

def create_hash
  hash = {
    # Classic, non-specific devices for each Android version
    'ANDROID_15' => make_android_hash('Google Pixel 9', '15.0'),
    'ANDROID_14' => make_android_hash('Google Pixel 8', '14.0'),
    'ANDROID_13' => make_android_hash('Google Pixel 6 Pro', '13.0'),
    'ANDROID_12' => make_android_hash('Google Pixel 5', '12.0'),
    'ANDROID_11' => make_android_hash('Google Pixel 4', '11.0'),
    'ANDROID_10' => make_android_hash('Google Pixel 4', '10.0'),
    'ANDROID_9' => make_android_hash('Google Pixel 3', '9.0'),
    'ANDROID_8' => make_android_hash('Samsung Galaxy S9', '8.0'),
    'ANDROID_7' => make_android_hash('Samsung Galaxy S8', '7.0'),

    # iOS devices
    'IOS_18' => make_ios_hash('iPhone 14', '18'),
    'IOS_17' => make_ios_hash('iPhone 15', '17'),
    'IOS_16' => make_ios_hash('iPhone 14', '16'),
    'IOS_15' => make_ios_hash('iPhone 13', '15'),
    'IOS_14' => make_ios_hash('iPhone 11', '14'),
    'IOS_13' => make_ios_hash('iPhone 11', '13'),
    'IOS_12' => make_ios_hash('iPhone XS', '12'),
  }

  # Specific Android devices
  add_android 'Google Pixel 4', '11.0', hash                        # ANDROID_11_0_GOOGLE_PIXEL_4

  add_android 'Xiaomi Redmi Note 9', '10.0', hash                   # ANDROID_10_0_XIAOMI_REDMI_NOTE_9
  add_android 'Samsung Galaxy Note 20', '10.0', hash                # ANDROID_10_0_SAMSUNG_GALAXY_NOTE_20
  add_android 'Motorola Moto G9 Play', '10.0', hash                 # ANDROID_10_0_MOTOROLA_MOTO_G9_PLAY
  add_android 'OnePlus 8', '10.0', hash                             # ANDROID_10_0_ONEPLUS_8

  add_android 'Samsung Galaxy S9', '8.0', hash                      # ANDROID_8_0_SAMSUNG_GALAXY_S9

  add_android 'Samsung Galaxy S8', '7.0', hash                      # ANDROID_7_0_SAMSUNG_GALAXY_S8

  # Specific iOS devices
  add_ios 'iPhone 15', '17.0', hash                                 # IOS_17_0_IPHONE_15
  add_ios 'iPhone 12 Pro', '17.0', hash                             # IOS_17_0_IPHONE_12_PRO

  add_ios 'iPhone 14 Plus', '16.0', hash                            # IOS_16_0_IPHONE_14_PLUS
  add_ios 'iPhone 14 Pro', '16.0', hash                             # IOS_16_0_IPHONE_14_PRO
  add_ios 'iPhone 14 Pro Max', '16.0', hash                         # IOS_16_0_IPHONE_14_PRO_MAX

  hash
end

.list_devices(os) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/maze/client/appium/bs_devices.rb', line 11

def list_devices(os)
  puts "BrowserStack #{os} devices available:"
  devices = DEVICE_HASH.dup
  devices.select { |key, device|
    device['platformName'].eql?(os)
  }.map { |key, device|
    new_device = device.dup
    new_device['key'] = key
    new_device
  }.sort { |dev_1, dev_2|
    dev_1['platformVersion'].to_f <=> dev_2['platformVersion'].to_f
  }.each{ |device|
    puts '------------------------------'
    puts "Device key: #{device['key']}"
    puts "Device:     #{device['deviceName']}"
    puts "OS:         #{device['platformName']}"
    puts "OS version: #{device['platformVersion']}"
  }
end

.make_android_hash(device, version) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/maze/client/appium/bs_devices.rb', line 31

def make_android_hash(device, version)
  hash = {
    'platformName' => 'android',
    'platformVersion' => version,
    'deviceName' => device,
    'autoGrantPermissions' => 'true',
  }
  hash.freeze
end

.make_ios_hash(device, version) ⇒ Object



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

def make_ios_hash(device, version)
  {
    'appium:autoAcceptAlerts' => 'true',
    'platformName' => 'ios',
    'platformVersion' => version,
    'deviceName' => device
  }.freeze
end