fastlane-plugin-cordova_screenshots 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +136 -0
- data/lib/fastlane/plugin/cordova_screenshots.rb +17 -0
- data/lib/fastlane/plugin/cordova_screenshots/actions/init_cordova_screenshots_android_action.rb +51 -0
- data/lib/fastlane/plugin/cordova_screenshots/actions/init_cordova_screenshots_ios_action.rb +52 -0
- data/lib/fastlane/plugin/cordova_screenshots/actions/retrofit_cordova_screenshots_android_action.rb +50 -0
- data/lib/fastlane/plugin/cordova_screenshots/actions/retrofit_cordova_screenshots_ios_action.rb +275 -0
- data/lib/fastlane/plugin/cordova_screenshots/constants.rb +11 -0
- data/lib/fastlane/plugin/cordova_screenshots/helper/cordova_screenshots_helper.rb +85 -0
- data/lib/fastlane/plugin/cordova_screenshots/resources/android/AndroidManifest.xml +12 -0
- data/lib/fastlane/plugin/cordova_screenshots/resources/android/ScreengrabTest.java +92 -0
- data/lib/fastlane/plugin/cordova_screenshots/resources/android/build-extras.gradle +13 -0
- data/lib/fastlane/plugin/cordova_screenshots/resources/ios/ui-snapshots/Info.plist +22 -0
- data/lib/fastlane/plugin/cordova_screenshots/resources/ios/ui-snapshots/SnapshotHelper.swift +163 -0
- data/lib/fastlane/plugin/cordova_screenshots/resources/ios/ui-snapshots/ui-snapshots.swift +41 -0
- data/lib/fastlane/plugin/cordova_screenshots/version.rb +5 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aafc4b9a74f7891a5a1a5d8853caa0e97b574923
|
4
|
+
data.tar.gz: 5edf75c164ff292c1f35e7d5031aa83a8c8bed43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d108d7faefdaa70d1e2c0eda3f9bdc20502fd050ee04f42b168e0105f889a190ebae42ecb9061f66ff00abc3a503054177c0a8f3154760db8dd85e05e9e743c7
|
7
|
+
data.tar.gz: c490e2e3d6861e3135da3ebea4d7ad4c139231754da8e09fca7b2ce08500123e32496907a8e0861ccebc04e4011c9eaa9461dba96f784603d656a1ae1dc6c1e7
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jan Piotrowski <piotrowski@gmail.com>
|
4
|
+
Copyright (c) 2017 Adrian Regan <adrian@littlevista.net>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# cordova_screenshots plugin
|
2
|
+
|
3
|
+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-cordova_screenshots)
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-cordova_screenshots`, add it to your project by running:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
fastlane add_plugin cordova_screenshots
|
11
|
+
```
|
12
|
+
|
13
|
+
## About cordova_screenshots
|
14
|
+
|
15
|
+
This plugin enables you to create automated screenshots of your Cordova (or Ionic) project, both for iOS or Android, with _fastlane_ using the normal [`capture_ios_screenshots`](https://docs.fastlane.tools/actions/capture_ios_screenshots/) and [`capture_android_screenshots`](https://docs.fastlane.tools/actions/capture_android_screenshots/) actions or [`fastlane snapshot`](https://docs.fastlane.tools/actions/snapshot/) (iOS) or [`fastlane screengrab`](https://docs.fastlane.tools/actions/screengrab/) (Android) commands.
|
16
|
+
|
17
|
+
This usually is a challenge, as both require you to modify your native projects and add some files. As Cordova projects are generated for you and not tracked by version control, those changes (including the test files your wrote) would get lost frequently.
|
18
|
+
|
19
|
+
By keeping your test files in your `fastlane` folder and offering an action to "retrofit" them to your native projects each time before running the screenshot creation actions, this plugin offers a way around that.
|
20
|
+
|
21
|
+
## Actions
|
22
|
+
|
23
|
+
- [`init_cordova_screenshots_ios`](#init_cordova_screenshots_ios)
|
24
|
+
- [`retrofit_cordova_screenshots_ios`](#retrofit_cordova_screenshots_ios)
|
25
|
+
- [`init_cordova_screenshots_android`](#init_cordova_screenshots_android)
|
26
|
+
- [`retrofit_cordova_screenshots_android`](#retrofit_cordova_screenshots_android)
|
27
|
+
|
28
|
+
### iOS
|
29
|
+
|
30
|
+
#### `init_cordova_screenshots_ios`
|
31
|
+
|
32
|
+
This action creates a sample iOS UI Test file in `fastlane/cordova_screenshots/ios`. It takes an optional `scheme_name` parameter, that defines the scheme name that will be used when retrofitting the test file into your Xcode project later.
|
33
|
+
|
34
|
+
You can run it either manually with `fastlane run init_cordova_screenshots_ios scheme_name:"another_scheme_name"` (which will create the folder `fastlane/cordova_screenshots/ios/another_scheme_name`) or a lane in your `Fastfile`.
|
35
|
+
|
36
|
+
#### `retrofit_cordova_screenshots_ios`
|
37
|
+
|
38
|
+
After iOS the test files are created, you can [edit them and write some tests to take screenshots](WRITING_TESTS.md).
|
39
|
+
|
40
|
+
Then you retrofit the tests into your Xcode project using this action: It scans the `fastlane/cordova_screenshots/ios` folder for sub folders and retrofits each into the Cordova iOS Xcode project by linking them absolutely. (It then creates a UI Test Target and Scheme based on the name of the subfolder. The files are not copied over to the project, so the Xcode project refers to the files in your `fastlane` folder.)
|
41
|
+
|
42
|
+
The action has multiple options:
|
43
|
+
|
44
|
+
- `team_id` is automatically set if it is specified in your fastlane `Appfile`.
|
45
|
+
- `bundle_id` is set automatically if the `package_name` parameter is set in your fastlane `Appfile`.
|
46
|
+
- `ios_xcode_path` specifies which Xcode project to use. By default it attempts to pick the Xcode project from the `platforms/ios` folder.
|
47
|
+
- `min_target_ios` defines the minimum iOS version
|
48
|
+
|
49
|
+
All these parameters can be overridden by specifying them in the call to the action.
|
50
|
+
|
51
|
+
This action should be executed each time before you use [`capture_ios_screenshots` action](https://docs.fastlane.tools/actions/capture_ios_screenshots/) (or command [`fastlane snapshot`](https://docs.fastlane.tools/actions/snapshot/) on the command line) to create screenshots as it makes sure the test files are linked into the current project.
|
52
|
+
|
53
|
+
### Android
|
54
|
+
|
55
|
+
#### `init_cordova_screenshots_android`
|
56
|
+
|
57
|
+
Copy over test file to `fastlane/cordova_screenshots/android` to be edited by the user.
|
58
|
+
|
59
|
+
This action creates a sample Android Test file and saves it to `fastlane/cordova_screenshots/android`. It needs a `package_name` parameter (for use in the created test file), that is read from your `Appfile` if set.
|
60
|
+
|
61
|
+
You can run it either manually with `fastlane run init_cordova_screenshots_android` or a lane in your `Fastfile`.
|
62
|
+
|
63
|
+
#### `retrofit_cordova_screenshots_android`
|
64
|
+
|
65
|
+
After the Android test files are created, you can [edit them and write some tests to take screenshots](WRITING_TESTS.md).
|
66
|
+
|
67
|
+
Then you retrofit the tests into your Android Studio project using this action.
|
68
|
+
|
69
|
+
**Note:** Right now, this action actually copies (!) the test file from its location into your Android project. A later version of this plugin will also link the Android test files into the project as it does for the iOS tests.
|
70
|
+
|
71
|
+
This action should be executed each time before you use [`capture_android_screenshots` action](https://docs.fastlane.tools/actions/capture_android_screenshots/) (or command [`fastlane screengrab`](https://docs.fastlane.tools/actions/screengrab/) on the command line) to create screenshots as it makes sure the test files are <!-- linked into --> present in the current project.
|
72
|
+
|
73
|
+
Note that you also have to build the test and debug APK manually before taking screenshots:
|
74
|
+
|
75
|
+
```shell
|
76
|
+
gradlew assembleDebug assembleAndroidTest
|
77
|
+
```
|
78
|
+
|
79
|
+
Or in your screenshot lane:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
gradle(
|
83
|
+
task: 'assemble',
|
84
|
+
build_type: 'Debug',
|
85
|
+
project_dir: 'platforms/android'
|
86
|
+
)
|
87
|
+
gradle(
|
88
|
+
task: 'assemble',
|
89
|
+
build_type: 'AndroidTest',
|
90
|
+
project_dir: 'platforms/android'
|
91
|
+
)
|
92
|
+
```
|
93
|
+
|
94
|
+
The action has no parameters.
|
95
|
+
|
96
|
+
## Example
|
97
|
+
|
98
|
+
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin.
|
99
|
+
|
100
|
+
## Why it works the way it does
|
101
|
+
|
102
|
+
Why do these actions not just copy over a test template to the native project before each run of the screenshots actions? Because then the user couldn't use the Xcode and Android Studio built in test recorders or editors to improve the tests. The tests would be saved only in `platforms` and overwritten or thrown away with the next platform regeneration. By linking the tests files from the `fastlane` folder, this can not happen.
|
103
|
+
|
104
|
+
## Acknowledgement
|
105
|
+
|
106
|
+
The iOS part of this plugin is fully based on knocknarea's excellent [`fastlane-plugin-ionic_integration`](https://github.com/knocknarea/fastlane-plugin-ionic_integration). I forked and simplified his existing plugin and added the Android implementation.
|
107
|
+
|
108
|
+
## Run tests for this plugin
|
109
|
+
|
110
|
+
To run both the tests, and code style validation, run
|
111
|
+
|
112
|
+
```shell
|
113
|
+
rake
|
114
|
+
```
|
115
|
+
|
116
|
+
To automatically fix many of the styling issues, use
|
117
|
+
|
118
|
+
```shell
|
119
|
+
rubocop -a
|
120
|
+
```
|
121
|
+
|
122
|
+
## Issues and Feedback
|
123
|
+
|
124
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
125
|
+
|
126
|
+
## Troubleshooting
|
127
|
+
|
128
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
|
129
|
+
|
130
|
+
## Using _fastlane_ Plugins
|
131
|
+
|
132
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
|
133
|
+
|
134
|
+
## About _fastlane_
|
135
|
+
|
136
|
+
_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,17 @@
|
|
1
|
+
require 'fastlane/plugin/cordova_screenshots/version'
|
2
|
+
require 'fastlane/plugin/cordova_screenshots/constants'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module CordovaScreenshots
|
6
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
7
|
+
def self.all_classes
|
8
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# By default we want to import all available actions and helpers
|
14
|
+
# A plugin can contain any number of actions and plugins
|
15
|
+
Fastlane::CordovaScreenshots.all_classes.each do |current|
|
16
|
+
require current
|
17
|
+
end
|
data/lib/fastlane/plugin/cordova_screenshots/actions/init_cordova_screenshots_android_action.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fastlane/plugin/cordova_screenshots/constants'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Actions
|
5
|
+
class InitCordovaScreenshotsAndroidAction < Action
|
6
|
+
def self.run(params)
|
7
|
+
package_name = params[:package_name]
|
8
|
+
|
9
|
+
UI.message("Creating new Android UI test in '#{CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH}'")
|
10
|
+
Fastlane::Helper::CordovaScreenshotsHelper.copy_android_sample_test(package_name)
|
11
|
+
|
12
|
+
UI.success("Done. Call the `retrofit_cordova_screenshots_android` action to integrate it into your Cordova Android project.")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.description
|
16
|
+
"Creates an Android UI test in '#{CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH}'"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.authors
|
20
|
+
['Jan Piotrowski']
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.return_value
|
24
|
+
# If your method provides a return value, you can describe here what it does
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.details
|
28
|
+
# Optional:
|
29
|
+
''
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.available_options
|
33
|
+
[
|
34
|
+
FastlaneCore::ConfigItem.new(key: :package_name,
|
35
|
+
env_name: 'CORDOVA_SCREENSHOTS_PACKAGE_NAME',
|
36
|
+
description: "The package name of the app under test (e.g. com.yourcompany.yourapp)",
|
37
|
+
default_value: CredentialsManager::AppfileConfig.try_fetch_value(:package_name),
|
38
|
+
optional: false)
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.is_supported?(platform)
|
43
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
44
|
+
# See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
|
45
|
+
#
|
46
|
+
# [:ios, :mac, :android].include?(platform)
|
47
|
+
[:android].include?(platform)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
require 'fastlane/plugin/cordova_screenshots/constants'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class InitCordovaScreenshotsIosAction < Action
|
7
|
+
def self.run(params)
|
8
|
+
scheme_name = params[:scheme_name]
|
9
|
+
|
10
|
+
UI.message("Creating new iOS UI Unit Test (with scheme '#{scheme_name}') in '#{CordovaScreenshots::CORDOVA_SCREENSHOTS_IOS_CONFIG_PATH}'")
|
11
|
+
Fastlane::Helper::CordovaScreenshotsHelper.copy_ios_sample_tests(scheme_name)
|
12
|
+
|
13
|
+
UI.success("Done. Call the `retrofit_cordova_screenshots_ios` action to integrate it into your Cordova iOS Xcode project.")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.description
|
17
|
+
"Creates an iOS UI Unit Tests in '#{CordovaScreenshots::CORDOVA_SCREENSHOTS_IOS_CONFIG_PATH}'"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.authors
|
21
|
+
['Adrian Regan', 'Jan Piotrowski']
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.return_value
|
25
|
+
# If your method provides a return value, you can describe here what it does
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.details
|
29
|
+
# Optional:
|
30
|
+
""
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.available_options
|
34
|
+
[
|
35
|
+
FastlaneCore::ConfigItem.new(key: :scheme_name,
|
36
|
+
env_name: 'CORDOVA_SCREENSHOTS_IOS_TEST_SCHEME',
|
37
|
+
description: 'Scheme Name of the UI Unit Tests',
|
38
|
+
default_value: CordovaScreenshots::CORDOVA_SCREENSHOTS_DEFAULT_IOS_UNIT_TEST_NAME,
|
39
|
+
optional: false)
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.is_supported?(platform)
|
44
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
45
|
+
# See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
|
46
|
+
#
|
47
|
+
# [:ios, :mac, :android].include?(platform)
|
48
|
+
[:ios].include?(platform)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/fastlane/plugin/cordova_screenshots/actions/retrofit_cordova_screenshots_android_action.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Actions
|
5
|
+
class RetrofitCordovaScreenshotsAndroidAction < Action
|
6
|
+
def self.run(params)
|
7
|
+
UI.message("Retrofitting Android UI test from '#{CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH}' into Cordova Android project.")
|
8
|
+
|
9
|
+
package_name = Fastlane::Helper::CordovaScreenshotsHelper.read_package_name_from_android_test
|
10
|
+
package_name_path = package_name.gsub('.', '/')
|
11
|
+
|
12
|
+
Fastlane::Helper::CordovaScreenshotsHelper.copy_android_test(package_name_path)
|
13
|
+
Fastlane::Helper::CordovaScreenshotsHelper.copy_android_build_extras_gradle
|
14
|
+
Fastlane::Helper::CordovaScreenshotsHelper.copy_android_manifest(package_name)
|
15
|
+
|
16
|
+
UI.success("Done. Build your test app (TODO) and then run `fastlane screengrab` to take screenshots.")
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.description
|
20
|
+
'Retrofit test into Android project'
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.authors
|
24
|
+
['Jan Piotrowski']
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.return_value
|
28
|
+
# If your method provides a return value, you can describe here what it does
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.details
|
32
|
+
# Optional:
|
33
|
+
''
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.available_options
|
37
|
+
[
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.is_supported?(platform)
|
42
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
43
|
+
# See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
|
44
|
+
#
|
45
|
+
# [:ios, :mac, :android].include?(platform)
|
46
|
+
[:android].include?(platform)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/fastlane/plugin/cordova_screenshots/actions/retrofit_cordova_screenshots_ios_action.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Actions
|
5
|
+
class RetrofitCordovaScreenshotsIosAction < Action
|
6
|
+
def self.run(params)
|
7
|
+
UI.message("Retrofitting iOS UI test from '#{CordovaScreenshots::CORDOVA_SCREENSHOTS_IOS_CONFIG_PATH}' into Cordova iOS Xcode project.")
|
8
|
+
|
9
|
+
(!params.nil? && !params[:ios_xcode_path].nil?) || UI.user_error!("Mandatory parameter :ios_xcode_path not specified")
|
10
|
+
|
11
|
+
#
|
12
|
+
# Params
|
13
|
+
#
|
14
|
+
xcode_project_path = params[:ios_xcode_path]
|
15
|
+
team_id = params[:team_id]
|
16
|
+
bundle_id = params[:bundle_id]
|
17
|
+
target_os = params[:min_target_ios]
|
18
|
+
|
19
|
+
File.exist?(xcode_project_path) || UI.user_error!("Xcode project '#{xcode_project_path}' does not exist!")
|
20
|
+
|
21
|
+
#
|
22
|
+
# Find all preconfigured UI Unit Tests
|
23
|
+
#
|
24
|
+
schemes = Dir.glob("#{CordovaScreenshots::CORDOVA_SCREENSHOTS_IOS_CONFIG_PATH}/*/").reject do |d|
|
25
|
+
d =~ /^\.{1,2}$/ # excludes . and ..
|
26
|
+
end
|
27
|
+
UI.message("Found schemes: #{schemes}")
|
28
|
+
|
29
|
+
# TODO: Error message if no schemes were found, refer to `init_cordova_screenshots_ios`
|
30
|
+
|
31
|
+
#
|
32
|
+
# Process each scheme
|
33
|
+
#
|
34
|
+
schemes.each do |scheme_path|
|
35
|
+
UI.message("Processing scheme: #{scheme_path}...")
|
36
|
+
generate_xcode_unit_test(scheme_path, xcode_project_path, team_id, bundle_id, target_os)
|
37
|
+
end
|
38
|
+
|
39
|
+
UI.success("Done. You can now run `fastlane snapshot` to take screenshots.")
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.generate_xcode_unit_test(config_folder, xcode_project_path, team_id, bundle_id, target_os)
|
43
|
+
#
|
44
|
+
# Names and Folders
|
45
|
+
#
|
46
|
+
scheme_name = File.basename(config_folder)
|
47
|
+
xcode_folder = File.dirname(xcode_project_path)
|
48
|
+
project_name = File.basename(xcode_project_path, ".xcodeproj")
|
49
|
+
|
50
|
+
UI.message("Setting up '#{scheme_name}' as UI Unit Test folder and Scheme in '#{xcode_folder}' for Xcode project '#{project_name}'")
|
51
|
+
|
52
|
+
#
|
53
|
+
# Xcode Project
|
54
|
+
#
|
55
|
+
proj = Xcodeproj::Project.open(xcode_project_path) || UI.user_error!("Unable to open Xcode project '#{xcode_project_path}'")
|
56
|
+
|
57
|
+
UI.message("Xcode project is version '#{proj.root_object.compatibility_version}' compatible")
|
58
|
+
|
59
|
+
#
|
60
|
+
# Clean Xcode project
|
61
|
+
#
|
62
|
+
proj = clean_xcode_project(proj, scheme_name)
|
63
|
+
|
64
|
+
#
|
65
|
+
# Add new Unit Tests to Xcode projects
|
66
|
+
#
|
67
|
+
proj = add_unit_tests_to_xcode_project(proj, scheme_name, config_folder, project_name, target_os, team_id, bundle_id, xcode_project_path)
|
68
|
+
|
69
|
+
#
|
70
|
+
# Success
|
71
|
+
#
|
72
|
+
UI.success("Completed retrofit of '#{scheme_name}' into generated Xcode Project '#{project_name}'.")
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.clean_xcode_project(proj, scheme_name)
|
76
|
+
#
|
77
|
+
# Find existing Target
|
78
|
+
#
|
79
|
+
target = nil
|
80
|
+
proj.targets.each do |t|
|
81
|
+
next unless t.name == scheme_name
|
82
|
+
UI.important("Found existing Target '#{t.name}' and removed it.")
|
83
|
+
target = t
|
84
|
+
break
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Find existing code group
|
89
|
+
#
|
90
|
+
test_group = nil
|
91
|
+
proj.groups.each do |g|
|
92
|
+
next unless g.name == scheme_name
|
93
|
+
g.clear
|
94
|
+
test_group = g
|
95
|
+
UI.important("Found existing Code Group '#{g.name}' and removed it.")
|
96
|
+
break
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Remove existing target and group
|
101
|
+
#
|
102
|
+
target.nil? || target.remove_from_project
|
103
|
+
test_group.nil? || test_group.remove_from_project
|
104
|
+
|
105
|
+
#
|
106
|
+
# Find existing products groups and remove
|
107
|
+
#
|
108
|
+
product_ref_name = scheme_name + '.xctest'
|
109
|
+
proj.products_group.files.each do |product_ref|
|
110
|
+
if product_ref.path == product_ref_name
|
111
|
+
UI.important("Found existing Product Group '#{product_ref.path}' and removed it.")
|
112
|
+
product_ref.remove_from_project
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
proj
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.add_unit_tests_to_xcode_project(proj, scheme_name, config_folder, project_name, target_os, team_id, bundle_id, xcode_project_path)
|
120
|
+
#
|
121
|
+
# Create new test group
|
122
|
+
#
|
123
|
+
UI.message("Creating UI Test Group '#{scheme_name}' for snapshots testing")
|
124
|
+
test_group = proj.new_group(scheme_name.to_s, File.absolute_path(config_folder), '<absolute>')
|
125
|
+
|
126
|
+
#
|
127
|
+
# Find main target
|
128
|
+
#
|
129
|
+
UI.message("Finding Main Target (of the project)...")
|
130
|
+
main_target = nil
|
131
|
+
proj.root_object.targets.each do |t|
|
132
|
+
if t.name == project_name
|
133
|
+
UI.message("Found main target as '#{t.name}'")
|
134
|
+
main_target = t
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
main_target || UI.user_error!("Unable to locate Main Target for app in '#{project_name}'")
|
139
|
+
|
140
|
+
#
|
141
|
+
# Create new target
|
142
|
+
#
|
143
|
+
target = proj.new_target(:ui_test_bundle, scheme_name, :ios, target_os, proj.products_group, :swift)
|
144
|
+
|
145
|
+
#
|
146
|
+
# "Create" product and put into target
|
147
|
+
#
|
148
|
+
product_ref_name = scheme_name + '.xctest'
|
149
|
+
product_ref = proj.products_group.find_file_by_path(product_ref_name)
|
150
|
+
target.product_reference = product_ref
|
151
|
+
|
152
|
+
#
|
153
|
+
# Add main_target as dependency of target
|
154
|
+
#
|
155
|
+
UI.message("Adding Main Target Dependency to new Target: '#{main_target}'")
|
156
|
+
target.add_dependency(main_target)
|
157
|
+
|
158
|
+
# We need to save here for some reason... xcodeproj!?
|
159
|
+
proj.save
|
160
|
+
|
161
|
+
#
|
162
|
+
# Add files (fastlane configured UI Unit Tests) into target (via test group)
|
163
|
+
#
|
164
|
+
UI.message("Adding Pre-Configured UI Unit Tests (*.plist and *.swift) to Test Group '#{scheme_name}'...")
|
165
|
+
|
166
|
+
files = []
|
167
|
+
Dir["#{config_folder}*.plist", "#{config_folder}*.swift"].each do |file| # config_folder ends with / already
|
168
|
+
UI.message("Adding UI Test Source '#{file}'")
|
169
|
+
files << test_group.new_reference(File.absolute_path(file), '<absolute>')
|
170
|
+
end
|
171
|
+
# TODO: Manually add `fastlane/SnapshotHelper.swift` (or actual location)
|
172
|
+
target.add_file_references(files)
|
173
|
+
|
174
|
+
#
|
175
|
+
# Configure project and target metadata
|
176
|
+
#
|
177
|
+
UI.message("Configuring Project Metadata")
|
178
|
+
|
179
|
+
target_config = {
|
180
|
+
CreatedOnToolsVersion: "8.2",
|
181
|
+
DevelopmentTeam: team_id,
|
182
|
+
ProvisioningStyle: "Automatic",
|
183
|
+
TestTargetID: main_target.uuid
|
184
|
+
}
|
185
|
+
if proj.root_object.attributes['TargetAttributes']
|
186
|
+
proj.root_object.attributes['TargetAttributes'].store(target.uuid, target_config)
|
187
|
+
elsif
|
188
|
+
proj.root_object.attributes.store('TargetAttributes', { target.uuid => target_config })
|
189
|
+
end
|
190
|
+
|
191
|
+
target.build_configuration_list.set_setting('INFOPLIST_FILE', File.absolute_path("#{config_folder}/Info.plist"))
|
192
|
+
target.build_configuration_list.set_setting('SWIFT_VERSION', '3.0')
|
193
|
+
target.build_configuration_list.set_setting('PRODUCT_NAME', "$(TARGET_NAME)")
|
194
|
+
target.build_configuration_list.set_setting('TEST_TARGET_NAME', project_name)
|
195
|
+
target.build_configuration_list.set_setting('PRODUCT_BUNDLE_IDENTIFIER', "#{bundle_id}.#{scheme_name}")
|
196
|
+
target.build_configuration_list.set_setting('CODE_SIGN_IDENTITY[sdk=iphoneos*]', "iPhone Developer")
|
197
|
+
target.build_configuration_list.set_setting('LD_RUNPATH_SEARCH_PATHS', "$(inherited) @executable_path/Frameworks @loader_path/Frameworks")
|
198
|
+
target.build_configuration_list.set_setting('DEVELOPMENT_TEAM', team_id)
|
199
|
+
|
200
|
+
#
|
201
|
+
# Create a shared scheme for the UI tests
|
202
|
+
#
|
203
|
+
UI.message("Generating Xcode Scheme '#{scheme_name}' to run UI Snapshot Tests")
|
204
|
+
existing_scheme = Xcodeproj::XCScheme.shared_data_dir(xcode_project_path) + "/#{scheme_name}.xcscheme"
|
205
|
+
scheme = File.exist?(existing_scheme) ? Xcodeproj::XCScheme.new(existing_scheme) : Xcodeproj::XCScheme.new
|
206
|
+
|
207
|
+
#
|
208
|
+
# Add target and main target to scheme
|
209
|
+
#
|
210
|
+
scheme.add_test_target(target)
|
211
|
+
scheme.add_build_target(main_target)
|
212
|
+
scheme.set_launch_target(main_target)
|
213
|
+
|
214
|
+
#
|
215
|
+
# Save scheme and project
|
216
|
+
#
|
217
|
+
scheme.save_as(xcode_project_path, scheme_name)
|
218
|
+
proj.save
|
219
|
+
|
220
|
+
proj
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.description
|
224
|
+
'Retrofit test into iOS Xcode project'
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.authors
|
228
|
+
['Adrian Regan', 'Jan Piotrowski']
|
229
|
+
end
|
230
|
+
|
231
|
+
def self.return_value
|
232
|
+
# If your method provides a return value, you can describe here what it does
|
233
|
+
end
|
234
|
+
|
235
|
+
def self.details
|
236
|
+
# Optional:
|
237
|
+
''
|
238
|
+
end
|
239
|
+
|
240
|
+
def self.available_options
|
241
|
+
[
|
242
|
+
FastlaneCore::ConfigItem.new(key: :ios_xcode_path,
|
243
|
+
env_name: 'CORDOVA_SCREENSHOTS_IOS_XCODE_PATH',
|
244
|
+
description: 'Path to Xcode project generated by Cordova/Ionic',
|
245
|
+
default_value: Fastlane::Helper::CordovaScreenshotsHelper.find_default_ios_xcode_workspace,
|
246
|
+
optional: false),
|
247
|
+
FastlaneCore::ConfigItem.new(key: :min_target_ios,
|
248
|
+
env_name: 'CORDOVA_SCREENSHOTS_MIN_TARGET_IOS',
|
249
|
+
description: 'Minimal iOS Version to target',
|
250
|
+
default_value: CordovaScreenshots::CORDOVA_SCREENSHOTS_DEFAULT_IOS_VERSION,
|
251
|
+
optional: false),
|
252
|
+
FastlaneCore::ConfigItem.new(key: :team_id,
|
253
|
+
env_name: 'CORDOVA_SCREENSHOTS_TEAM_ID',
|
254
|
+
description: 'Team ID in iTunes Connect or Apple Developer',
|
255
|
+
default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
|
256
|
+
optional: false),
|
257
|
+
FastlaneCore::ConfigItem.new(key: :bundle_id, # TODO?
|
258
|
+
env_name: 'CORDOVA_SCREENSHOTS_BUNDLE_ID',
|
259
|
+
description: 'The Bundle ID of the iOS App, eg: ie.littlevista.whateverapp',
|
260
|
+
default_value: CredentialsManager::AppfileConfig.try_fetch_value(:package_name),
|
261
|
+
optional: false)
|
262
|
+
|
263
|
+
]
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.is_supported?(platform)
|
267
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
268
|
+
# See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
|
269
|
+
#
|
270
|
+
# [:ios, :mac, :android].include?(platform)
|
271
|
+
[:ios].include?(platform)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Fastlane
|
2
|
+
module CordovaScreenshots
|
3
|
+
CORDOVA_SCREENSHOTS_CONFIG_PATH = "fastlane/cordova_screenshots"
|
4
|
+
CORDOVA_SCREENSHOTS_IOS_CONFIG_PATH = CORDOVA_SCREENSHOTS_CONFIG_PATH + "/ios"
|
5
|
+
CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH = CORDOVA_SCREENSHOTS_CONFIG_PATH + "/android"
|
6
|
+
|
7
|
+
CORDOVA_SCREENSHOTS_IOS_BUILD_PATH = "platforms/ios"
|
8
|
+
CORDOVA_SCREENSHOTS_DEFAULT_IOS_VERSION = "9.0"
|
9
|
+
CORDOVA_SCREENSHOTS_DEFAULT_IOS_UNIT_TEST_NAME = "ui-snapshots" # TODO: scheme_name vs. test_name
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'fastlane/plugin/cordova_screenshots/constants'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Helper
|
5
|
+
class CordovaScreenshotsHelper
|
6
|
+
HELPER_PATH = File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
def self.copy_all_files(src_folder, project_folder)
|
9
|
+
if src_folder && Dir.exist?(src_folder)
|
10
|
+
dest_folder = project_folder.to_s
|
11
|
+
UI.message("Copying all files from '#{src_folder}' to '#{dest_folder}'")
|
12
|
+
Dir.exist?(dest_folder) || FileUtils.mkdir_p(dest_folder)
|
13
|
+
FileUtils.cp_r(src_folder + "/.", dest_folder)
|
14
|
+
elsif
|
15
|
+
UI.user_error!("Copying files: '#{src_folder}' does not exist.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.copy_ios_sample_tests(scheme_name)
|
20
|
+
ios_resources_path = File.expand_path("#{HELPER_PATH}/../resources/ios")
|
21
|
+
source_folder = "#{ios_resources_path}/#{CordovaScreenshots::CORDOVA_SCREENSHOTS_DEFAULT_IOS_UNIT_TEST_NAME}"
|
22
|
+
dest_folder = "#{CordovaScreenshots::CORDOVA_SCREENSHOTS_IOS_CONFIG_PATH}/#{scheme_name}"
|
23
|
+
# TODO: Don't overwrite existing files
|
24
|
+
copy_all_files(source_folder, dest_folder)
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Find any existing Xcode Workspace generated by Cordova/Ionic
|
29
|
+
#
|
30
|
+
def self.find_default_ios_xcode_workspace
|
31
|
+
Dir["#{CordovaScreenshots::CORDOVA_SCREENSHOTS_IOS_BUILD_PATH}/*.xcodeproj"].last || nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.copy_android_sample_test(package_name)
|
35
|
+
android_resources_path = File.expand_path("#{HELPER_PATH}/../resources/android")
|
36
|
+
Dir.exist?(CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH) || FileUtils.mkdir_p(CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH)
|
37
|
+
# TODO: Don't overwrite existing files!
|
38
|
+
filename = "ScreengrabTest.java"
|
39
|
+
FileUtils.cp("#{android_resources_path}/#{filename}", CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH.to_s)
|
40
|
+
replace_package_name("#{CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH}/#{filename}", package_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Read package name from test file
|
44
|
+
def self.read_package_name_from_android_test()
|
45
|
+
text = File.read("#{CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH}/ScreengrabTest.java")
|
46
|
+
# TODO: Error message if file is missing
|
47
|
+
match = text.match(/package (.*)?;/)
|
48
|
+
match[1]
|
49
|
+
# TODO: Error message if package name can not be read
|
50
|
+
end
|
51
|
+
|
52
|
+
# copy over test file to `platforms\android\app\src\androidTest\java\...\ScreengrabTest.java` (... = io\ionic\starter)
|
53
|
+
def self.copy_android_test(package_name_path)
|
54
|
+
test_path = "platforms/android/app/src/androidTest/java/#{package_name_path}"
|
55
|
+
Dir.exist?(test_path) || FileUtils.mkdir_p(test_path)
|
56
|
+
# TODO: Handle missing ScreengrabTest.java file and suggest using other action
|
57
|
+
FileUtils.cp("#{CordovaScreenshots::CORDOVA_SCREENSHOTS_ANDROID_CONFIG_PATH}/ScreengrabTest.java", test_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
# copy over build-extras.gradle to `platforms\android\app`
|
61
|
+
def self.copy_android_build_extras_gradle
|
62
|
+
android_resources_path = File.expand_path("#{HELPER_PATH}/../resources/android")
|
63
|
+
FileUtils.cp("#{android_resources_path}/build-extras.gradle", "platforms/android/app")
|
64
|
+
end
|
65
|
+
|
66
|
+
# copy over AndroidManifest.xml to `platforms\android\app\src\debug`
|
67
|
+
def self.copy_android_manifest(package_name)
|
68
|
+
android_resources_path = File.expand_path("#{HELPER_PATH}/../resources/android")
|
69
|
+
dest_path = "platforms/android/app/src/debug"
|
70
|
+
filename = "AndroidManifest.xml"
|
71
|
+
Dir.exist?(dest_path) || FileUtils.mkdir_p(dest_path)
|
72
|
+
FileUtils.cp("#{android_resources_path}/#{filename}", dest_path)
|
73
|
+
replace_package_name("#{dest_path}/#{filename}", package_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.replace_package_name(file, package_name)
|
77
|
+
data = File.read(file)
|
78
|
+
filtered_data = data.gsub("tools.fastlane.plugin.cordova_screenshots", package_name)
|
79
|
+
File.open(file, "w") do |f|
|
80
|
+
f.write(filtered_data)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
package="tools.fastlane.plugin.cordova_screenshots"
|
4
|
+
xmlns:tools="http://schemas.android.com/tools">
|
5
|
+
|
6
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
7
|
+
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
|
8
|
+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
9
|
+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
10
|
+
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
|
11
|
+
|
12
|
+
</manifest>
|
@@ -0,0 +1,92 @@
|
|
1
|
+
package tools.fastlane.plugin.cordova_screenshots;
|
2
|
+
|
3
|
+
|
4
|
+
import android.support.test.espresso.ViewInteraction;
|
5
|
+
import android.support.test.rule.ActivityTestRule;
|
6
|
+
import android.support.test.runner.AndroidJUnit4;
|
7
|
+
import android.test.suitebuilder.annotation.LargeTest;
|
8
|
+
import android.view.View;
|
9
|
+
import android.view.ViewGroup;
|
10
|
+
import android.view.ViewParent;
|
11
|
+
|
12
|
+
import org.hamcrest.Description;
|
13
|
+
import org.hamcrest.Matcher;
|
14
|
+
import org.hamcrest.TypeSafeMatcher;
|
15
|
+
import org.hamcrest.core.IsInstanceOf;
|
16
|
+
import org.junit.Rule;
|
17
|
+
import org.junit.Test;
|
18
|
+
import org.junit.runner.RunWith;
|
19
|
+
import org.junit.BeforeClass;
|
20
|
+
import org.junit.ClassRule;
|
21
|
+
|
22
|
+
import static android.support.test.espresso.Espresso.onView;
|
23
|
+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
24
|
+
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
25
|
+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
26
|
+
import static org.hamcrest.Matchers.allOf;
|
27
|
+
|
28
|
+
import tools.fastlane.screengrab.Screengrab;
|
29
|
+
import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy;
|
30
|
+
import tools.fastlane.screengrab.locale.LocaleTestRule;
|
31
|
+
|
32
|
+
@LargeTest
|
33
|
+
@RunWith(AndroidJUnit4.class)
|
34
|
+
public class ScreengrabTest {
|
35
|
+
@ClassRule
|
36
|
+
public static final LocaleTestRule localeTestRule = new LocaleTestRule();
|
37
|
+
|
38
|
+
@Rule
|
39
|
+
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
|
40
|
+
|
41
|
+
@BeforeClass
|
42
|
+
public static void beforeAll() {
|
43
|
+
// https://docs.fastlane.tools/getting-started/android/screenshots/#improved-screenshot-capture-with-ui-automator
|
44
|
+
Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
|
45
|
+
}
|
46
|
+
|
47
|
+
@Test
|
48
|
+
public void screengrabTest() {
|
49
|
+
// Added a sleep statement to match the app's execution delay.
|
50
|
+
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
51
|
+
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
52
|
+
try {
|
53
|
+
Thread.sleep(10000);
|
54
|
+
} catch (InterruptedException e) {
|
55
|
+
e.printStackTrace();
|
56
|
+
}
|
57
|
+
|
58
|
+
Screengrab.screenshot("0_app-launch");
|
59
|
+
|
60
|
+
/*
|
61
|
+
ViewInteraction webView = onView(
|
62
|
+
allOf(childAtPosition(
|
63
|
+
allOf(withId(android.R.id.content),
|
64
|
+
childAtPosition(
|
65
|
+
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
|
66
|
+
0)),
|
67
|
+
0),
|
68
|
+
isDisplayed()));
|
69
|
+
webView.check(matches(isDisplayed()));
|
70
|
+
*/
|
71
|
+
|
72
|
+
}
|
73
|
+
|
74
|
+
private static Matcher<View> childAtPosition(
|
75
|
+
final Matcher<View> parentMatcher, final int position) {
|
76
|
+
|
77
|
+
return new TypeSafeMatcher<View>() {
|
78
|
+
@Override
|
79
|
+
public void describeTo(Description description) {
|
80
|
+
description.appendText("Child at position " + position + " in parent ");
|
81
|
+
parentMatcher.describeTo(description);
|
82
|
+
}
|
83
|
+
|
84
|
+
@Override
|
85
|
+
public boolean matchesSafely(View view) {
|
86
|
+
ViewParent parent = view.getParent();
|
87
|
+
return parent instanceof ViewGroup && parentMatcher.matches(parent)
|
88
|
+
&& view.equals(((ViewGroup) parent).getChildAt(position));
|
89
|
+
}
|
90
|
+
};
|
91
|
+
}
|
92
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
android {
|
2
|
+
defaultConfig {
|
3
|
+
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
|
4
|
+
}
|
5
|
+
}
|
6
|
+
|
7
|
+
dependencies {
|
8
|
+
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
|
9
|
+
exclude group: 'com.android.support', module: 'support-annotations'
|
10
|
+
}
|
11
|
+
|
12
|
+
androidTestCompile 'tools.fastlane:screengrab:1.0.0'
|
13
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
6
|
+
<string>en</string>
|
7
|
+
<key>CFBundleExecutable</key>
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
9
|
+
<key>CFBundleIdentifier</key>
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
12
|
+
<string>6.0</string>
|
13
|
+
<key>CFBundleName</key>
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
15
|
+
<key>CFBundlePackageType</key>
|
16
|
+
<string>BNDL</string>
|
17
|
+
<key>CFBundleShortVersionString</key>
|
18
|
+
<string>1.0</string>
|
19
|
+
<key>CFBundleVersion</key>
|
20
|
+
<string>1</string>
|
21
|
+
</dict>
|
22
|
+
</plist>
|
@@ -0,0 +1,163 @@
|
|
1
|
+
//
|
2
|
+
// SnapshotHelper.swift
|
3
|
+
// Example
|
4
|
+
//
|
5
|
+
// Created by Felix Krause on 10/8/15.
|
6
|
+
// Copyright © 2015 Felix Krause. All rights reserved.
|
7
|
+
//
|
8
|
+
import Foundation
|
9
|
+
import XCTest
|
10
|
+
|
11
|
+
var deviceLanguage = ""
|
12
|
+
var locale = ""
|
13
|
+
|
14
|
+
@available(*, deprecated, message: "use setupSnapshot: instead")
|
15
|
+
func setLanguage(_ app: XCUIApplication) {
|
16
|
+
setupSnapshot(app)
|
17
|
+
}
|
18
|
+
|
19
|
+
func setupSnapshot(_ app: XCUIApplication) {
|
20
|
+
Snapshot.setupSnapshot(app)
|
21
|
+
}
|
22
|
+
|
23
|
+
func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
|
24
|
+
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
|
25
|
+
}
|
26
|
+
|
27
|
+
open class Snapshot: NSObject {
|
28
|
+
|
29
|
+
open class func setupSnapshot(_ app: XCUIApplication) {
|
30
|
+
setLanguage(app)
|
31
|
+
setLocale(app)
|
32
|
+
setLaunchArguments(app)
|
33
|
+
}
|
34
|
+
|
35
|
+
class func setLanguage(_ app: XCUIApplication) {
|
36
|
+
guard let prefix = pathPrefix() else {
|
37
|
+
return
|
38
|
+
}
|
39
|
+
|
40
|
+
let path = prefix.appendingPathComponent("language.txt")
|
41
|
+
|
42
|
+
do {
|
43
|
+
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
|
44
|
+
deviceLanguage = try String(contentsOf: path, encoding: .utf8).trimmingCharacters(in: trimCharacterSet)
|
45
|
+
app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))"]
|
46
|
+
} catch {
|
47
|
+
print("Couldn't detect/set language...")
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
class func setLocale(_ app: XCUIApplication) {
|
52
|
+
guard let prefix = pathPrefix() else {
|
53
|
+
return
|
54
|
+
}
|
55
|
+
|
56
|
+
let path = prefix.appendingPathComponent("locale.txt")
|
57
|
+
|
58
|
+
do {
|
59
|
+
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
|
60
|
+
locale = try String(contentsOf: path, encoding: .utf8).trimmingCharacters(in: trimCharacterSet)
|
61
|
+
} catch {
|
62
|
+
print("Couldn't detect/set locale...")
|
63
|
+
}
|
64
|
+
if locale.isEmpty {
|
65
|
+
locale = Locale(identifier: deviceLanguage).identifier
|
66
|
+
}
|
67
|
+
app.launchArguments += ["-AppleLocale", "\"\(locale)\""]
|
68
|
+
}
|
69
|
+
|
70
|
+
class func setLaunchArguments(_ app: XCUIApplication) {
|
71
|
+
guard let prefix = pathPrefix() else {
|
72
|
+
return
|
73
|
+
}
|
74
|
+
|
75
|
+
let path = prefix.appendingPathComponent("snapshot-launch_arguments.txt")
|
76
|
+
app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"]
|
77
|
+
|
78
|
+
do {
|
79
|
+
let launchArguments = try String(contentsOf: path, encoding: String.Encoding.utf8)
|
80
|
+
let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: [])
|
81
|
+
let matches = regex.matches(in: launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count))
|
82
|
+
let results = matches.map { result -> String in
|
83
|
+
(launchArguments as NSString).substring(with: result.range)
|
84
|
+
}
|
85
|
+
app.launchArguments += results
|
86
|
+
} catch {
|
87
|
+
print("Couldn't detect/set launch_arguments...")
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
open class func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
|
92
|
+
if waitForLoadingIndicator {
|
93
|
+
waitForLoadingIndicatorToDisappear()
|
94
|
+
}
|
95
|
+
|
96
|
+
print("snapshot: \(name)") // more information about this, check out https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work
|
97
|
+
sleep(1) // Waiting for the animation to be finished (kind of)
|
98
|
+
#if os(tvOS)
|
99
|
+
XCUIApplication().childrenMatchingType(.Browser).count
|
100
|
+
#elseif os(OSX)
|
101
|
+
XCUIApplication().typeKey(XCUIKeyboardKeySecondaryFn, modifierFlags: [])
|
102
|
+
#else
|
103
|
+
XCUIDevice.shared().orientation = .unknown
|
104
|
+
#endif
|
105
|
+
}
|
106
|
+
|
107
|
+
class func waitForLoadingIndicatorToDisappear() {
|
108
|
+
#if os(tvOS)
|
109
|
+
return
|
110
|
+
#endif
|
111
|
+
|
112
|
+
let query = XCUIApplication().statusBars.children(matching: .other).element(boundBy: 1).children(matching: .other)
|
113
|
+
|
114
|
+
while (0..<query.count).map({ query.element(boundBy: $0) }).contains(where: { $0.isLoadingIndicator }) {
|
115
|
+
sleep(1)
|
116
|
+
print("Waiting for loading indicator to disappear...")
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
class func pathPrefix() -> URL? {
|
121
|
+
let homeDir: URL
|
122
|
+
//on OSX config is stored in /Users/<username>/Library
|
123
|
+
//and on iOS/tvOS/WatchOS it's in simulator's home dir
|
124
|
+
#if os(OSX)
|
125
|
+
guard let user = ProcessInfo().environment["USER"] else {
|
126
|
+
print("Couldn't find Snapshot configuration files - can't detect current user ")
|
127
|
+
return nil
|
128
|
+
}
|
129
|
+
|
130
|
+
guard let usersDir = FileManager.default.urls(for: .userDirectory, in: .localDomainMask).first else {
|
131
|
+
print("Couldn't find Snapshot configuration files - can't detect `Users` dir")
|
132
|
+
return nil
|
133
|
+
}
|
134
|
+
|
135
|
+
homeDir = usersDir.appendingPathComponent(user)
|
136
|
+
#else
|
137
|
+
guard let simulatorHostHome = ProcessInfo().environment["SIMULATOR_HOST_HOME"] else {
|
138
|
+
print("Couldn't find simulator home location. Please, check SIMULATOR_HOST_HOME env variable.")
|
139
|
+
return nil
|
140
|
+
}
|
141
|
+
guard let homeDirUrl = URL(string: simulatorHostHome) else {
|
142
|
+
print("Can't prepare environment. Simulator home location is inaccessible. Does \(simulatorHostHome) exist?")
|
143
|
+
return nil
|
144
|
+
}
|
145
|
+
homeDir = homeDirUrl
|
146
|
+
#endif
|
147
|
+
return homeDir.appendingPathComponent("Library/Caches/tools.fastlane")
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
extension XCUIElement {
|
152
|
+
var isLoadingIndicator: Bool {
|
153
|
+
let whiteListedLoaders = ["GeofenceLocationTrackingOn", "StandardLocationTrackingOn"]
|
154
|
+
if whiteListedLoaders.contains(self.identifier) {
|
155
|
+
return false
|
156
|
+
}
|
157
|
+
return self.frame.size == CGSize(width: 10, height: 20)
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
// Please don't remove the lines below
|
162
|
+
// They are used to detect outdated configuration files
|
163
|
+
// SnapshotHelperVersion [1.3]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
//
|
2
|
+
// ui_snapshots.swift
|
3
|
+
// ui-snapshots
|
4
|
+
//
|
5
|
+
// Created by Adrian Regan on 07/04/2017.
|
6
|
+
//
|
7
|
+
//
|
8
|
+
|
9
|
+
import XCTest
|
10
|
+
|
11
|
+
class ui_snapshots: XCTestCase {
|
12
|
+
|
13
|
+
override func setUp() {
|
14
|
+
super.setUp()
|
15
|
+
|
16
|
+
let app = XCUIApplication()
|
17
|
+
|
18
|
+
setupSnapshot(app)
|
19
|
+
|
20
|
+
app.launch()
|
21
|
+
|
22
|
+
}
|
23
|
+
|
24
|
+
override func tearDown() {
|
25
|
+
super.tearDown()
|
26
|
+
}
|
27
|
+
|
28
|
+
func testSnapshots() {
|
29
|
+
|
30
|
+
//
|
31
|
+
// Place your own tests here. This is a starter example to get you going..
|
32
|
+
//
|
33
|
+
snapshot("app-launch")
|
34
|
+
|
35
|
+
// XCUIApplication().buttons["Your Button Name"].tap()
|
36
|
+
|
37
|
+
// snapshot("after-button-pressed")
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
}
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-cordova_screenshots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Piotrowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: bundler
|
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: rspec
|
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_junit_formatter
|
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: rake
|
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: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.49.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.49.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-require_tools
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
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: fastlane
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.101.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.101.1
|
139
|
+
description:
|
140
|
+
email: piotrowski@gmail.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- LICENSE
|
146
|
+
- README.md
|
147
|
+
- lib/fastlane/plugin/cordova_screenshots.rb
|
148
|
+
- lib/fastlane/plugin/cordova_screenshots/actions/init_cordova_screenshots_android_action.rb
|
149
|
+
- lib/fastlane/plugin/cordova_screenshots/actions/init_cordova_screenshots_ios_action.rb
|
150
|
+
- lib/fastlane/plugin/cordova_screenshots/actions/retrofit_cordova_screenshots_android_action.rb
|
151
|
+
- lib/fastlane/plugin/cordova_screenshots/actions/retrofit_cordova_screenshots_ios_action.rb
|
152
|
+
- lib/fastlane/plugin/cordova_screenshots/constants.rb
|
153
|
+
- lib/fastlane/plugin/cordova_screenshots/helper/cordova_screenshots_helper.rb
|
154
|
+
- lib/fastlane/plugin/cordova_screenshots/resources/android/AndroidManifest.xml
|
155
|
+
- lib/fastlane/plugin/cordova_screenshots/resources/android/ScreengrabTest.java
|
156
|
+
- lib/fastlane/plugin/cordova_screenshots/resources/android/build-extras.gradle
|
157
|
+
- lib/fastlane/plugin/cordova_screenshots/resources/ios/ui-snapshots/Info.plist
|
158
|
+
- lib/fastlane/plugin/cordova_screenshots/resources/ios/ui-snapshots/SnapshotHelper.swift
|
159
|
+
- lib/fastlane/plugin/cordova_screenshots/resources/ios/ui-snapshots/ui-snapshots.swift
|
160
|
+
- lib/fastlane/plugin/cordova_screenshots/version.rb
|
161
|
+
homepage: https://github.com/janpio/fastlane-plugin-cordova_screenshots
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.6.14.1
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Take screenshots of your Cordova/Ionic app with fastlane
|
185
|
+
test_files: []
|