Class: Fastlane::Saucectl::IosSuites
- Inherits:
-
Object
- Object
- Fastlane::Saucectl::IosSuites
show all
- Includes:
- FileUtils
- Defined in:
- lib/fastlane/plugin/saucectl/helper/ios_suites.rb
Overview
This class will create test suites for ios applications based on user specified configuration properties
Constant Summary
collapse
- UI =
FastlaneCore::UI
Constants included
from FileUtils
FileUtils::CLASS_NAME_REGEX, FileUtils::FILE_TYPE_REGEX
Instance Method Summary
collapse
Methods included from FileUtils
#find, #read_file, #search_retrieve_test_classes, #syscall
Constructor Details
#initialize(config) ⇒ IosSuites
17
18
19
20
21
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 17
def initialize(config)
UI.user_error!("❌ For the ios platform you must specify `devices` array") if config[:devices].nil?
UI.user_error!("❌ #{config[:kind]} is not a supported test framework for iOS. Use xcuitest") unless config[:kind].eql?('xcuitest')
@config = config
end
|
Instance Method Details
#check_for_android_params ⇒ Object
35
36
37
38
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 35
def check_for_android_params
type = @config[:annotation] ? 'annotation' : 'size'
UI.user_error!("❌ execution by #{type} is not supported on the iOS platform!") if @config[:size] || @config[:annotation]
end
|
#create_test_distribution_suite ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 40
def create_test_distribution_suite
if @config[:test_distribution].eql?('shard')
shard_real_device_suites
else
test_distribution_suite
end
end
|
#custom_test_class_suite ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 86
def custom_test_class_suite
test_suites = []
@config[:devices].each do |device|
device_options = real_device_options(device)
test_classes = @config[:test_class].reject(&:empty?).join(',')
test_suites << {
'name' => suite_name(device[:name]).downcase,
'testOptions' => default_test_options(test_classes.split(','))
}.merge(device_options)
end
test_suites
end
|
#default_test_options(test_type) ⇒ Object
159
160
161
162
163
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 159
def default_test_options(test_type)
unless test_type.nil?
{ 'class' => test_type }
end
end
|
#device_options(device) ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 151
def device_options(device)
{
'carrierConnectivity' => device[:carrier_connectivity],
'deviceType' => device[:device_type].upcase!,
'private' => device[:private]
}
end
|
#generate ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 23
def generate
check_for_android_params
if @config[:test_distribution] || @config[:test_plan]
create_test_distribution_suite
elsif @config[:test_class].kind_of?(Array)
custom_test_class_suite
else
test_runner_suite
end
end
|
#rdc_options(device) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 136
def rdc_options(device)
device_type_key = device.key?(:id) ? 'id' : 'name'
name = device.key?(:id) ? device[:id] : device[:name]
base_device_hash = {
device_type_key => name,
'orientation' => device[:orientation]
}.merge('options' => device_options(device))
unless device[:platform_version].nil?
base_device_hash = base_device_hash.merge({ 'platformVersion' => device[:platform_version] })
end
base_device_hash
end
|
#real_device_options(device) ⇒ Object
132
133
134
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 132
def real_device_options(device)
{ 'devices' => [rdc_options(device)] }
end
|
#shard_real_device_suites ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 60
def shard_real_device_suites
test_suites = []
arr = test_distribution_array
shards = arr.each_slice((arr.size / @config[:devices].size.to_f).round).to_a
shards.each_with_index do |suite, i|
device_name = @config[:devices][i].key?(:id) ? @config[:devices][i][:id] : @config[:devices][i][:name]
test_suites << {
'name' => suite_name("#{device_name}-shard-#{i + 1}").downcase,
'testOptions' => default_test_options(suite)
}.merge(real_device_options(@config[:devices][i]))
end
test_suites
end
|
#suite_name(name) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 52
def suite_name(name)
if ENV['JOB_NAME'].nil? && ENV['BUILD_NUMBER'].nil?
"#{@config[:kind]}-#{name}"
else
"#{ENV['JOB_NAME']}-#{ENV['BUILD_NUMBER']}-#{name}"
end
end
|
#test_distribution_array ⇒ Object
#test_distribution_suite ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 99
def test_distribution_suite
test_suites = []
if @config[:test_plan]
@config[:devices].each do |device|
test_suites << {
'name' => suite_name(@config[:test_plan]).downcase,
'testOptions' => default_test_options(test_distribution_array)
}.merge(real_device_options(device))
end
else
@config[:devices].each do |device|
test_distribution_array.each do |test_type|
test_suites << {
'name' => suite_name(test_type).downcase,
'testOptions' => default_test_options(test_type)
}.merge(real_device_options(device))
end
end
end
test_suites
end
|
#test_plan_distribution ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 121
def test_plan_distribution
test_suites = []
@config[:devices].each do |device|
test_suites << {
'name' => suite_name(@config[:test_plan]).downcase,
'testOptions' => default_test_options(test_distribution_array)
}.merge(real_device_options(device))
end
test_suites
end
|
#test_runner_suite ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/fastlane/plugin/saucectl/helper/ios_suites.rb', line 74
def test_runner_suite
test_suites = []
@config[:devices].each do |device|
device_name = device.key?(:id) ? device[:id] : device[:name]
test_suites << {
'name' => suite_name(device_name),
'testOptions' => default_test_options(nil)
}.merge(real_device_options(device))
end
test_suites
end
|