fastlane-plugin-testdroid_runner 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f16ce9b557eeeebabcfff7b66d2a0e5e78f2a0b123d3fe60fd68ea1e2cc6e14
4
+ data.tar.gz: b4ec4035cb1a231bcbf064b8658045f83d15a53eb381d362813f792298900dc6
5
+ SHA512:
6
+ metadata.gz: 69e98928b795a57ccf70f5fc7ac590a56ee3957b881ac56477bea722cee3ba8fdd16e76afe64a19ae7325c7b0d0c9e455b8bc6b48fcd3ba36e5055c590249bad
7
+ data.tar.gz: 6931504731c0a50c61f9d8e343de488783117a4bf6ed263b07d892633f5686ae3d89d8c0a666c35033dbec1581e9eb43cec02f278f5f1edaf968da4a9665eac2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 josepmc <jmateu.clemente@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # testdroid_runner plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-testdroid_runner)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-testdroid_runner`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin testdroid_runner
11
+ ```
12
+
13
+ ## About testdroid_runner
14
+
15
+ Allows to run BitBar tests on fastlane. It has two lanes, testdroid_runner (which runs the tests) and upload_testdroid (uploads a binary to testdroid to use as a live test).
16
+
17
+ ## Example
18
+
19
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. The Fastfile includes 4 lanes ready to plugin to your project with a few variables.
20
+ Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
21
+
22
+ ## Run tests for this plugin
23
+
24
+ If you want to run the tests, you need the following variables defined in your environment:
25
+
26
+ - TESTDROID_RUNNER_API_KEY: The API Key from Bitbar
27
+ - TESTDROID_RUNNER_APPLICATION_FILE: The Application to Test
28
+ - TESTDROID_RUNNER_TEST_FILE: An Espresso/XCUITest runner binary
29
+ - TESTDROID_RUNNER_PROJECT: A BitBar Project
30
+ - TESTDROID_RUNNER_DEVICE_GROUP: A BitBar Device Group
31
+ - TESTDROID_RUNNER_REPORT_DIR: The directory where all the files produced in BitBar will be stored
32
+
33
+ To run both the tests, and code style validation, run
34
+
35
+ ```
36
+ rake
37
+ ```
38
+
39
+ To automatically fix many of the styling issues, use
40
+ ```
41
+ rubocop -a
42
+ ```
43
+
44
+ ## Issues and Feedback
45
+
46
+ For any other issues and feedback about this plugin, please submit it to this repository.
47
+
48
+ ## Troubleshooting
49
+
50
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
51
+
52
+ ## Using _fastlane_ Plugins
53
+
54
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
55
+
56
+ ## About _fastlane_
57
+
58
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/testdroid_runner/version'
2
+
3
+ module Fastlane
4
+ module TestdroidRunner
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::TestdroidRunner.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,87 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/testdroid_runner_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class TestdroidRunnerAction < Action
7
+ def self.run(params)
8
+ $stdout.sync = true
9
+ Helper::RunTest.run(params)
10
+ end
11
+
12
+ def self.description
13
+ "BitBar Test Runner"
14
+ end
15
+
16
+ def self.authors
17
+ ["josepmc"]
18
+ end
19
+
20
+ def self.return_value
21
+ # If your method provides a return value, you can describe here what it does
22
+ end
23
+
24
+ def self.details
25
+ # Optional:
26
+ "A quick test runner for BitBar that allows either Espresso or XCUITests to be ran through fastlane"
27
+ end
28
+
29
+ def self.available_options
30
+ [
31
+ FastlaneCore::ConfigItem.new(key: :api_key,
32
+ env_name: "TESTDROID_RUNNER_API_KEY",
33
+ description: "The API key used to connect to BitBar",
34
+ optional: false,
35
+ type: String),
36
+ FastlaneCore::ConfigItem.new(key: :application_file,
37
+ env_name: "TESTDROID_RUNNER_APPLICATION_FILE",
38
+ description: "Either an IPA or APK containing the core application",
39
+ optional: false,
40
+ type: String),
41
+ FastlaneCore::ConfigItem.new(key: :test_file,
42
+ env_name: "TESTDROID_RUNNER_TEST_FILE",
43
+ description: "Either an IPA or APK containing the test code",
44
+ optional: true,
45
+ type: String),
46
+ FastlaneCore::ConfigItem.new(key: :project,
47
+ env_name: "TESTDROID_RUNNER_PROJECT",
48
+ description: "A BitBar project where to store the test run",
49
+ optional: true,
50
+ type: String),
51
+ FastlaneCore::ConfigItem.new(key: :device_group,
52
+ env_name: "TESTDROID_RUNNER_DEVICE_GROUP",
53
+ description: "The BitBar device group to use as target devices",
54
+ optional: true,
55
+ type: String),
56
+ FastlaneCore::ConfigItem.new(key: :wait_complete,
57
+ env_name: "TESTDROID_RUNNER_WAIT_COMPLETE",
58
+ description: "Whether to wait for the tests execution to be complete",
59
+ optional: true,
60
+ default_value: true,
61
+ is_string: false),
62
+ FastlaneCore::ConfigItem.new(key: :report_dir,
63
+ env_name: "TESTDROID_RUNNER_REPORT_DIR",
64
+ description: "The directory where to download the report files. If :wait_complete is false, this setting will be ignored",
65
+ optional: true,
66
+ type: String),
67
+ FastlaneCore::ConfigItem.new(key: :concurrency,
68
+ env_name: "TESTDROID_RUNNER_CONCURRENCY",
69
+ description: "Number of purchased concurrency lanes. Testdroid jobs have a maximum device amount of 2x purchased lanes. The runner will split the selected lists into smaller runs in order to fit around this restriction",
70
+ optional: true,
71
+ type: Integer,
72
+ default_value: 2),
73
+ FastlaneCore::ConfigItem.new(key: :scheduler,
74
+ env_name: "TESTDROID_RUNNER_SCHEDULER",
75
+ description: "Which type of scheduler to use, by default it will only run one device at a time",
76
+ optional: true,
77
+ type: String,
78
+ default_value: "SERIAL")
79
+ ]
80
+ end
81
+
82
+ def self.is_supported?(platform)
83
+ [:ios, :android].include?(platform)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,50 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/upload_file_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class UploadTestdroidAction < Action
7
+ def self.run(params)
8
+ $stdout.sync = true
9
+ Helper::UploadFile.run(params)
10
+ end
11
+
12
+ def self.description
13
+ "Uploads a file to bitbar"
14
+ end
15
+
16
+ def self.authors
17
+ ["josepmc"]
18
+ end
19
+
20
+ def self.return_value
21
+ # If your method provides a return value, you can describe here what it does
22
+ "Returns the uploaded file id"
23
+ end
24
+
25
+ def self.details
26
+ # Optional:
27
+ "Uploads a file to bitbar"
28
+ end
29
+
30
+ def self.available_options
31
+ [
32
+ FastlaneCore::ConfigItem.new(key: :api_key,
33
+ env_name: "TESTDROID_RUNNER_API_KEY",
34
+ description: "The API key used to connect to BitBar",
35
+ optional: false,
36
+ type: String),
37
+ FastlaneCore::ConfigItem.new(key: :application_file,
38
+ env_name: "TESTDROID_RUNNER_APPLICATION_FILE",
39
+ description: "Either an IPA or APK containing the core application",
40
+ optional: false,
41
+ type: String)
42
+ ]
43
+ end
44
+
45
+ def self.is_supported?(platform)
46
+ [:ios, :android].include?(platform)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,39 @@
1
+ require 'testdroid-api-client'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ class TestdroidRunnerHelper
6
+ @user = nil
7
+ def self.get_user(params)
8
+ if @user.nil?
9
+ client = TestdroidAPI::ApikeyClient.new(params[:api_key])
10
+ @user = client.authorize
11
+ end
12
+ @user
13
+ end
14
+
15
+ def self.get_os(params)
16
+ if params[:application_file].end_with?(".apk")
17
+ return { name: "ANDROID", framework: "s_osType_eq_ANDROID;s_name_like_%Instrumentation", extname: "apk" }
18
+ end
19
+ if params[:application_file].end_with?(".ipa", ".app")
20
+ # XCTest would be return { name: "IOS", framework: "s_osType_eq_IOS;s_name_like_%XCTest", extname: "ipa" }
21
+ return { name: "IOS", framework: "s_osType_eq_IOS;s_name_like_%XCUITest", extname: "ipa" }
22
+ end
23
+ raise "Unknown extension for #{params.application_file}"
24
+ end
25
+
26
+ def self.upload_file(file)
27
+ file_name = File.basename(file)
28
+ duplicated_files = @user.files.list({ filter: "s_name_eq_#{file_name}" })
29
+ unless duplicated_files.nil? || duplicated_files.length == 0
30
+ puts("[testdroid] Deleting duplicated files with ids: #{duplicated_files.collect(&:id)}")
31
+ duplicated_files.each(&:delete)
32
+ end
33
+ uploaded_file = @user.files.upload(file)
34
+ puts("[testdroid] Uploaded: #{uploaded_file.id}")
35
+ uploaded_file
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,67 @@
1
+ require_relative './shared'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ class RunTest
6
+ def self.run(params)
7
+ # source: https://github.com/bitbar/testdroid-api-client-ruby/blob/master/sample/sample.rb
8
+ user = Helper::TestdroidRunnerHelper.get_user(params)
9
+ os_config = Helper::TestdroidRunnerHelper.get_os(params)
10
+ puts("[testdroid] Starting test run with:\napp #{os_config[:extname]}: #{params[:application_file]}\ntest #{os_config[:extname]}: #{params[:test_file]}")
11
+ # Create project
12
+ project = user.projects.list.detect { |proj| proj.name.casecmp(params[:project]) == 0 }
13
+
14
+ # get all the devices to run on
15
+ device_group = user.device_groups.list.detect { |group| group.display_name.casecmp(params[:device_group]) == 0 }
16
+ run_devices = device_group.devices.list.select { |device| device.os_type.casecmp(os_config[:name]) == 0 }
17
+ puts("[testdroid] Running on devices #{run_devices.collect(&:display_name)}")
18
+
19
+ # get IDs of the devices
20
+ id_list = run_devices.collect(&:id)
21
+
22
+ # get the framework id
23
+ framework_id = user.available_frameworks.list({ filter: os_config[:framework] })[0].id
24
+
25
+ # Upload file
26
+ puts("[testdroid] Uploading app #{os_config[:extname]}...")
27
+ file_app = Helper::TestdroidRunnerHelper.upload_file(params[:application_file])
28
+ # instrumentation package
29
+ puts("[testdroid] Uploading test #{os_config[:extname]}...")
30
+ file_test = Helper::TestdroidRunnerHelper.upload_file(params[:test_file])
31
+
32
+ i = 0
33
+ until id_list[i, i + params[:concurrency] * 2].nil?
34
+ list = id_list[i, i + params[:concurrency] * 2]
35
+ i += params[:concurrency] * 2
36
+ # start test run
37
+ test_run = user.runs.create("{\"osType\": \"#{os_config[:name]}\", \"projectId\": #{project.id}, \"frameworkId\":#{framework_id},
38
+ \"deviceIds\": #{list}, \"scheduler\": \"#{params[:scheduler] || 'SERIAL'}\", \"files\": [{\"id\": #{file_app.id}, \"action\": \"INSTALL\" },
39
+ {\"id\": #{file_test.id}, \"action\": \"RUN_TEST\" }]}")
40
+ puts("[testdroid] Started test run, access it using this link: https://cloud.bitbar.com/#testing/projects/#{project.id}/#{test_run.id}")
41
+
42
+ # wait until the whole test run is completed
43
+ next unless params[:wait_complete]
44
+ until test_run.refresh.state == "FINISHED"
45
+ print(".")
46
+ sleep(20)
47
+ end
48
+
49
+ print("\n")
50
+
51
+ puts("[testdroid] Test run finished with success ratio: #{test_run.success_ratio * 100}% [executed:#{test_run.execution_ratio * 100}%]")
52
+ # download all files from all device sessions
53
+
54
+ next unless params[:report_dir]
55
+ puts("[testdroid] Downloading files...")
56
+ test_run.device_sessions.list({ limit: 0 })
57
+ .each { |ds| ds.download_all_files(params[:report_dir]) }
58
+ puts("[testdroid] All files downloaded")
59
+ end
60
+ ensure
61
+ puts("[testdroid] Cleaning up...")
62
+ file_app.delete unless file_app.nil?
63
+ file_test.delete unless file_test.nil?
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ require_relative './shared'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ class UploadFile
6
+ def self.run(params)
7
+ Helper::TestdroidRunnerHelper.get_user(params)
8
+ os_config = Helper::TestdroidRunnerHelper.get_os(params)
9
+ puts("[testdroid] Uploading #{os_config[:extname]} for live services: #{params[:application_file]}...")
10
+ file_app = Helper::TestdroidRunnerHelper.upload_file(params[:application_file])
11
+
12
+ puts("[testdroid] Test the app on a live device: https://cloud.bitbar.com/#testing/interactive-choose-device")
13
+ file_app.id
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module TestdroidRunner
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-testdroid_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - josepmc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: testdroid-api-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.49.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.49.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-require_tools
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: fastlane
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.148.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 2.148.1
153
+ description:
154
+ email: jmateu.clemente@gmail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE
160
+ - README.md
161
+ - lib/fastlane/plugin/testdroid_runner.rb
162
+ - lib/fastlane/plugin/testdroid_runner/actions/testdroid_runner_action.rb
163
+ - lib/fastlane/plugin/testdroid_runner/actions/upload_testdroid_action.rb
164
+ - lib/fastlane/plugin/testdroid_runner/helper/shared.rb
165
+ - lib/fastlane/plugin/testdroid_runner/helper/testdroid_runner_helper.rb
166
+ - lib/fastlane/plugin/testdroid_runner/helper/upload_file_helper.rb
167
+ - lib/fastlane/plugin/testdroid_runner/version.rb
168
+ homepage: https://github.com/josepmc/fastlane-plugin-testdroid_runner
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubygems_version: 3.0.3
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Allows to run BitBar tests on fastlane
191
+ test_files: []