-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathandroid_firebase_test.rb
More file actions
186 lines (162 loc) · 6.18 KB
/
android_firebase_test.rb
File metadata and controls
186 lines (162 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
require 'securerandom'
module Fastlane
module Actions
module SharedValues
FIREBASE_TEST_RESULT = :FIREBASE_TEST_LOG_FILE
FIREBASE_TEST_LOG_FILE_PATH = :FIREBASE_TEST_LOG_FILE_PATH
end
class AndroidFirebaseTestAction < Action
def self.run(params)
# Preflight – ensure the system is set up correctly
Fastlane::FirebaseTestRunner.verify_has_gcloud_binary
# Log in to Firebase (and validate credentials)
test_runner = Fastlane::FirebaseTestRunner.new(key_file: params[:key_file])
# Set up the log file and output directory
FileUtils.mkdir_p(params[:results_output_dir])
Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH] = File.join(params[:results_output_dir], 'output.log')
device = Fastlane::FirebaseDevice.new(
model: params[:model],
version: params[:version],
locale: params[:locale],
orientation: params[:orientation]
)
result = test_runner.run_tests(
apk_path: params[:apk_path],
test_apk_path: params[:test_apk_path],
device: device,
type: params[:type]
)
# Download all of the outputs from the job to the local machine
test_runner.download_result_files(
result: result,
destination: params[:results_output_dir],
project_id: params[:project_id],
key_file_path: params[:key_file]
)
FastlaneCore::UI.test_failure! "Firebase Tests failed – more information can be found at #{result.more_details_url}" unless result.success?
UI.success 'Firebase Tests Complete'
end
#####################################################
# @!group Documentation
#####################################################
def self.description
'Runs the specified tests in Firebase Test Lab'
end
def self.details
description
end
def self.available_options
run_uuid = SecureRandom.uuid
[
FastlaneCore::ConfigItem.new(
key: :project_id,
env_name: 'GCP_PROJECT',
description: 'The Project ID to test in',
type: String
),
FastlaneCore::ConfigItem.new(
key: :key_file,
env_name: 'GOOGLE_APPLICATION_CREDENTIALS',
description: 'The key file used to authorize with Google Cloud',
type: String,
verify_block: proc do |value|
next if File.file? value
UI.user_error!("Invalid key file path: #{value}")
end
),
FastlaneCore::ConfigItem.new(
key: :apk_path,
description: 'The application APK',
type: String,
verify_block: proc do |value|
next if File.file? value
UI.user_error!("Invalid application APK: #{value}")
end
),
FastlaneCore::ConfigItem.new(
key: :test_apk_path,
description: 'The test APK',
type: String,
verify_block: proc do |value|
next if File.file? value
UI.user_error!("Invalid test APK: #{value}")
end
),
FastlaneCore::ConfigItem.new(
key: :model,
description: 'The device model to run',
type: String,
verify_block: proc do |value|
model_names = Fastlane::FirebaseDevice.valid_model_names
next if model_names.include? value
UI.user_error!("Invalid Model Name: #{value}. Valid Model Names: #{model_names}")
end
),
FastlaneCore::ConfigItem.new(
key: :version,
description: 'The device version to run',
type: Integer,
verify_block: proc do |value|
version_numbers = Fastlane::FirebaseDevice.valid_version_numbers
next if version_numbers.include? value
UI.user_error!("Invalid Version Number: #{value}. Valid Verison Numbers: #{version_numbers}")
end
),
FastlaneCore::ConfigItem.new(
key: :locale,
description: 'The locale code to run in',
type: String,
default_value: 'en',
verify_block: proc do |value|
locale_codes = Fastlane::FirebaseDevice.valid_locales
next if locale_codes.include? value
UI.user_error!("Invalid Locale: #{value}. Valid Locales: #{locale_codes}")
end
),
FastlaneCore::ConfigItem.new(
key: :orientation,
description: 'Which orientation to run the device in',
type: String,
default_value: 'portrait',
verify_block: proc do |value|
orientations = Fastlane::FirebaseDevice.valid_orientations
next if orientations.include? value
UI.user_error!("Invalid Orientation: #{value}. Valid Orientations: #{orientations}")
end
),
FastlaneCore::ConfigItem.new(
key: :type,
description: 'Which type of test are we running?',
type: String,
default_value: 'instrumentation',
verify_block: proc do |value|
types = Fastlane::FirebaseTestRunner::VALID_TEST_TYPES
next if types.include? value
UI.user_error!("Invalid Test Type: #{value}. Valid Types: #{types}")
end
),
FastlaneCore::ConfigItem.new(
key: :test_run_id,
description: 'A unique ID used to identify this test run',
type: String,
default_value: run_uuid,
default_value_dynamic: true
),
FastlaneCore::ConfigItem.new(
key: :results_output_dir,
description: 'Where should we store the results of this test run?',
type: String,
default_value: File.join(Dir.tmpdir(), run_uuid),
default_value_dynamic: true
),
]
end
def self.authors
['Automattic']
end
def self.is_supported?(platform)
platform == :android
end
end
end
end