fastlane-plugin-ionic_integration 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c414a201f1622f34e4079486d368830415d5bb5
4
+ data.tar.gz: cf73d0b573a4179d599dd01e0781f2ba9e9f1667
5
+ SHA512:
6
+ metadata.gz: a29bf584846dec83895e0357c0bdc86bb7b1120a98611581cdf08c30e28fa2d90aece302dc6ffaf18978b3d7413dc0b101a522bf28c30a73a9bc60441333df61
7
+ data.tar.gz: 41d86718e4ac1d28f462649b6007e6c099de8f9ae9925784536eb0c9747c817bc9f5c988fa1dfc8af0f24860354eef62517c8fced702edbb28877d232c258ae4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Adrian Regan <adrian@littlevista.net>
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.
data/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # ionic_integration plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-ionic_integration)
4
+
5
+ ## Getting Started
6
+
7
+ **NOTE** This is hot off the press and I am still testing it locally, so hang tight
8
+
9
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-ionic_integration`, add it to your project by running:
10
+
11
+ ```bash
12
+ fastlane add_plugin ionic_integration
13
+ ```
14
+
15
+ ## About ionic_integration
16
+
17
+ Integrating Fastlane with Ionic Generated Projects
18
+
19
+ Fastlane is an awesome application. However the assumption is that you are in control of the iOS or Android projects while using it. When developing in Ionic
20
+ (or Cordova), the relevant platform projects are created for you by Ionic. For example **ionic platform add ios**
21
+
22
+ This poses a problem when attempting to automate the build process. We do not want to put the generated projects under source control, however we would like to
23
+ be able to link it into fastlane??
24
+
25
+ This plugin will let you generate a sample UI Test group for generating snapshots the [fastlane way](https://tisunov.github.io/2015/11/06/automating-app-store-screenshots-generation-with-fastlane-snapshot-and-sketch.html). But it stores the UI Unit tests in your fastlane folder so that you can
26
+ commit only these to version control. The plugin, will then retrofit these tests into the Ionic/Cordova generated projects.
27
+
28
+ There are two actions (so far)
29
+ **ionic_ios_config_snapshot** get's you started with a sample UI Test configuration (and saves it to fastlane/ionic/config/ios/ui-tests). The UI Unit Tests
30
+ are linked into any existing XCode project generated by Ionic.
31
+
32
+ **ionic_ios_snapshot** Scans the fastlane/ionic/config/ios/ui-tests folder for sub folders that represent UI Test Schemes (each folder is a scheme). It retrofits
33
+ each UI Test scheme into the XCode projects generated by Ionic.
34
+
35
+ NOTE: At the moment this works for Xcode 8+. If anyone out there is interested in contributing, it would be great to support XCode 7 and (ideally) be able to do a
36
+ similar thing for Android generated projects.
37
+
38
+ ## Example
39
+
40
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
41
+
42
+ To create a sample test you can add a lane like so:
43
+
44
+ ```ruby
45
+ lane :setup_tests do
46
+ ionic_ios_config_snapshot(
47
+ ionic_scheme_name: "blah-blah"
48
+ )
49
+ end
50
+ ```
51
+
52
+ This will create a folder **fastlane/ionic/config/ios/ui-tests/blah-blah**
53
+
54
+ In this folder will be the standard test files that you would expect for a UI Unit Test, Info.plist, Fastlane SWIFT file and a sample Unit Test ui-snapshots.swift
55
+
56
+ **ionic_ios_config_snapshot** also executes the *ionic_config_snapshot* action to retrofit this unit test configuration into any existing XCode Project
57
+
58
+ When this is done. The sample will be linked into your generated project. In the above example, a UI Test scheme will be created in **fastlane/ionic/config/ios/ui-tests/blah-blah**. The files in this folder are linked absolutely into Xcode, that is Xcode refers directly to these files (they are not copied over to Xcode)
59
+
60
+ If you open up Xcode and open the file 'blah-blah/ui-snapshots.swift' you will see something like this:
61
+
62
+ ```
63
+ func testSnapshots() {
64
+
65
+ //
66
+ // Place your own tests here. This is a starter example to get you going..
67
+ //
68
+ snapshot("app-launch")
69
+
70
+ // XCUIApplication().buttons["Your Button Name"].tap()
71
+
72
+ // snapshot("after-button-pressed")
73
+
74
+ }
75
+ ```
76
+ In the XCode UI, select the scheme 'blah-blah' and click into the method 'testSnapshots()' (after the first snapshot). Then Run the scheme.
77
+ This will open the simulator and you can click around in your application. XCode will record, each interaction within the
78
+ testSnapshots() method.
79
+
80
+ When you are done, you can save everthing and it will save those interactions into the fastlane/ionic/config/ios/ui-tests/ui-snapshots.swift.
81
+
82
+ You can now add fastlane ```snapshot("decription")``` where you like.
83
+
84
+ This whole operation only needs to be done once (or if you want to add more screenshots later). The UI Test files can be added to your source control and they will be retrofitted into any future generated Ionic projects. Nice.
85
+
86
+ Your fully automated Fastlane file can now look like this:
87
+
88
+ ```ruby
89
+ platform :ios do
90
+
91
+ before_all do
92
+ #
93
+ # This will retrofit any existing schemes in fastlane/ionic/config/ios/ui-tests/
94
+ #
95
+ ionic_ios_snapshot(
96
+ team_id: "[YOUR TEAM ID]"
97
+ bundle_id: "[YOUR APP BUNDLE ID]"
98
+ )
99
+ end
100
+
101
+ lane :release do
102
+ # This will run the retrofitted UI Tests for you and create snapshots... :-)
103
+ snapshot(
104
+ output_simulator_logs: true,
105
+ reinstall_app: false,
106
+ erase_simulator: true,
107
+ scheme: "[Name of folder in fastlane/ionic/config/ios/ui-tests/, i.e. blah-blah]"
108
+ )
109
+ end
110
+ end
111
+ ```
112
+
113
+ You can now use this to fully automate the build process between ionic and fastlane, including snapshots.
114
+
115
+ ## Run tests for this plugin
116
+
117
+ To run both the tests, and code style validation, run
118
+
119
+ ```
120
+ rake
121
+ ```
122
+
123
+ To automatically fix many of the styling issues, use
124
+ ```
125
+ rubocop -a
126
+ ```
127
+
128
+ ## Issues and Feedback
129
+
130
+ For any other issues and feedback about this plugin, please submit it to this repository.
131
+
132
+ ## Troubleshooting
133
+
134
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
135
+
136
+ ## Using _fastlane_ Plugins
137
+
138
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
139
+
140
+ ## About _fastlane_
141
+
142
+ _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).
143
+
@@ -0,0 +1,17 @@
1
+ require 'fastlane/plugin/ionic_integration/version'
2
+ require 'fastlane/plugin/ionic_integration/constants'
3
+
4
+ module Fastlane
5
+ module IonicIntegration
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::IonicIntegration.all_classes.each do |current|
16
+ require current
17
+ end
@@ -0,0 +1,85 @@
1
+ require 'xcodeproj'
2
+ require 'fastlane/plugin/ionic_integration/constants'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ #
7
+ # Used to bootstrap the UI Unit Testing Process for iOS generated Xcode Projects.
8
+ #
9
+ # It copies over a sample UI test to our fastlane config folder and runs the IonicSnapShotAction
10
+ #
11
+ class IonicIosConfigSnapshotAction < Action
12
+ #
13
+ # Default location for Ionic/Cordova Project generation, ionic plaform add ios
14
+ #
15
+ default_scheme_name = IonicIntegration::IONIC_DEFAULT_UNIT_TEST_NAME
16
+
17
+ def self.run(params)
18
+ workspace_path = params[:ionic_ios_xcode_path]
19
+ target_os = params[:ionic_min_target_ios]
20
+ scheme_name = params[:ionic_scheme_name]
21
+
22
+ UI.message("Creating New UI Unit Tests for Snapshots, with Scheme #{scheme_name} in #{IonicIntegration::IONIC_IOS_CONFIG_UITESTS_PATH}")
23
+ Fastlane::Helper::IonicIntegrationHelper.copy_ios_sample_tests(scheme_name)
24
+
25
+ #
26
+ # Just call our main ios snapshot action, if there is a workspace
27
+ #
28
+ if Dir.exist?(workspace_path)
29
+ Actions::IonicIosSnapshotAction.run(
30
+ ionic_ios_xcode_path: workspace_path,
31
+ ionic_min_target_ios: target_os
32
+ )
33
+ UI.success("Created UI Test Configuration")
34
+ elsif
35
+ UI.success("Created UI Test Configuration. No Workspace exists or was specified yet. When ionic generates the workspace you'll need to call ionic_ios_snapshot action.")
36
+ end
37
+ end
38
+
39
+ def self.description
40
+ 'Create a Sample iOS UI Unit Test to get started with in a generated Ionic/Cordova project'
41
+ end
42
+
43
+ def self.authors
44
+ ['Adrian Regan']
45
+ end
46
+
47
+ def self.return_value
48
+ # If your method provides a return value, you can describe here what it does
49
+ end
50
+
51
+ def self.details
52
+ # Optional:
53
+ "Creates a set of UI Unit Tests in #{IonicIntegration::IONIC_IOS_CONFIG_UITESTS_PATH} and configures an existing Ionic/Cordova Generated Xcode projec to use them"
54
+ end
55
+
56
+ def self.available_options
57
+ [
58
+ FastlaneCore::ConfigItem.new(key: :ionic_ios_xcode_path,
59
+ env_name: 'IONIC_IOS_XCODE_PATH',
60
+ description: 'Path to XCode Project Generated by Ionic',
61
+ default_value: Fastlane::Helper::IonicIntegrationHelper.find_default_ios_xcode_workspace,
62
+ optional: false),
63
+ FastlaneCore::ConfigItem.new(key: :ionic_min_target_ios,
64
+ env_name: 'IONIC_MIN_TARGET_IOS',
65
+ description: 'Minimal iOS Version to Target',
66
+ default_value: IonicIntegration::DEFAULT_IOS_VERSION,
67
+ optional: false),
68
+ FastlaneCore::ConfigItem.new(key: :ionic_scheme_name,
69
+ env_name: 'IONIC_IOS_TEST_SCHEME',
70
+ description: 'Scheme Name of the UI Unit Tests',
71
+ default_value: IonicIntegration::IONIC_DEFAULT_UNIT_TEST_NAME,
72
+ optional: false)
73
+ ]
74
+ end
75
+
76
+ def self.is_supported?(platform)
77
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
78
+ # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
79
+ #
80
+ # [:ios, :mac, :android].include?(platform)
81
+ [:ios].include?(platform)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,212 @@
1
+ require 'xcodeproj'
2
+
3
+ module Fastlane
4
+ module Actions
5
+ class IonicIosSnapshotAction < Action
6
+ def self.run(params)
7
+ UI.message "Configuring Xcode with UI Tests Located in #{IonicIntegration::IONIC_IOS_CONFIG_UITESTS_PATH}/**"
8
+
9
+ (!params.nil? && !params[:ionic_ios_xcode_path].nil?) || UI.user_error!("Mandatory parameter :ionic_ios_xcode_path not specified")
10
+
11
+ #
12
+ # Deduce the name of the xcode project we are looking for...
13
+ #
14
+ xcode_project = params[:ionic_ios_xcode_path]
15
+ target_os = params[:ionic_min_target_ios]
16
+ team_id = params[:team_id]
17
+ bundle_id = params[:bundle_id]
18
+
19
+ File.exist?(xcode_project) || UI.user_error!("Xcode Project #{xcode_project} does not exist!")
20
+ #
21
+ # Find all preconfigured UI Unit Tests
22
+ #
23
+ schemes = Dir.glob("#{IonicIntegration::IONIC_IOS_CONFIG_UITESTS_PATH}/*/").reject do |d|
24
+ d =~ /^\.{1,2}$/
25
+ end
26
+
27
+ UI.message "Found #{schemes}..."
28
+ schemes.each do |scheme_path|
29
+ # UI.message("Processing Test Scheme #{scheme_path}")
30
+ generate_xcode_unit_test(scheme_path, xcode_project, team_id, bundle_id, target_os)
31
+ end
32
+ end
33
+
34
+ def self.generate_xcode_unit_test(config_folder, xcode_project_path, team_id, bundle_id, target_os)
35
+ scheme_name = File.basename(config_folder)
36
+ xcode_folder = File.dirname(xcode_project_path)
37
+ project_name = File.basename(xcode_project_path, ".xcodeproj")
38
+
39
+ UI.message("Setting up #{scheme_name} as UI Unit Test folder and Scheme in #{xcode_folder} for Xcode Project #{project_name}")
40
+
41
+ proj = Xcodeproj::Project.open(xcode_project_path) || UI.user_error!("Unable to Open Xcode Project #{xcode_project_path}")
42
+
43
+ UI.message("Xcode Project is Version #{proj.root_object.compatibility_version} Compatible")
44
+ #
45
+ # Find existing Target and remove it
46
+ #
47
+ target = nil
48
+ proj.targets.each do |t|
49
+ next unless t.name == scheme_name
50
+ UI.important "Found existing Target #{t.name}. Will be replaced."
51
+ target = t
52
+ break
53
+ end
54
+
55
+ #
56
+ # Find existing code group or unit tests and remove if needed.
57
+ #
58
+ snapGrp = nil
59
+ proj.groups.each do |g|
60
+ next unless g.name == scheme_name
61
+ g.clear
62
+ snapGrp = g
63
+ UI.important "Found existing Code Group #{g.name}. Will be replaced."
64
+ break
65
+ end
66
+
67
+ #
68
+ # Remove existing targets and groups if required.
69
+ #
70
+ target.nil? || target.remove_from_project
71
+ snapGrp.nil? || snapGrp.remove_from_project
72
+
73
+ target = nil
74
+ snapGrp = nil
75
+
76
+ #
77
+ # Ok, let's rock and roll
78
+ #
79
+ UI.message "Creating UI Test Group #{scheme_name} for snapshots testing"
80
+ snapGrp = proj.new_group(scheme_name.to_s)
81
+
82
+ UI.message "Finding Main Target (of the Project)..."
83
+ main_target = nil
84
+ proj.root_object.targets.each do |t|
85
+ if t.name == project_name
86
+ UI.message "Found main target as #{t.name}"
87
+ main_target = t
88
+ end
89
+ end
90
+
91
+ main_target || UI.user_error!("Unable to locate Main Target for Ionic App in #{project_name}")
92
+
93
+ # Create a product for our ui unit test
94
+ product_ref = proj.products_group.new_reference(scheme_name + '.xctest', :built_products)
95
+
96
+ target = Xcodeproj::Project::ProjectHelper.new_target(proj, :ui_test_bundle,
97
+ scheme_name, :ios, target_os, proj.products_group, :swift)
98
+
99
+ target.product_reference = product_ref
100
+
101
+ UI.message "Adding Main Target Dependency: " + main_target.to_s
102
+ target.add_dependency(main_target)
103
+
104
+ # We need to save here for some reason... xcodeproj?
105
+ proj.save
106
+
107
+ UI.message "Adding Pre-Configured UI Unit Tests (*.plist and *.swift) to Test Group #{scheme_name}"
108
+ files = []
109
+
110
+ # Link our fastlane configured UI Unit Tests into the project
111
+ Dir["#{config_folder}/*.plist", "#{config_folder}/*.swift"].each do |file|
112
+ UI.message "Adding UI Test Source #{file}"
113
+ files << snapGrp.new_reference(File.absolute_path(file))
114
+ end
115
+
116
+ target.add_file_references(files)
117
+
118
+ UI.message "Configuring Project Metadata..."
119
+
120
+ # We may need to switch here on compatibility versions, this is for Xcode 8.0
121
+ # Fasten your seatbelts, it gets bumpy from here on in..
122
+ target_config = {
123
+ CreatedOnToolsVersion: "8.2",
124
+ DevelopmentTeam: team_id,
125
+ ProvisioningStyle: "Automatic",
126
+ TestTargetID: main_target.uuid
127
+ }
128
+
129
+ if proj.root_object.attributes['TargetAttributes']
130
+ proj.root_object.attributes['TargetAttributes'].store(target.uuid, target_config)
131
+ elsif
132
+ proj.root_object.attributes.store('TargetAttributes', { target.uuid => target_config })
133
+ end
134
+
135
+ target.build_configuration_list.set_setting('INFOPLIST_FILE', "#{scheme_name}/Info.plist")
136
+ target.build_configuration_list.set_setting('SWIFT_VERSION', '3.0')
137
+ target.build_configuration_list.set_setting('PRODUCT_NAME', "$(TARGET_NAME)")
138
+ target.build_configuration_list.set_setting('TEST_TARGET_NAME', project_name)
139
+ target.build_configuration_list.set_setting('PRODUCT_BUNDLE_IDENTIFIER', "#{bundle_id}.#{scheme_name}")
140
+ target.build_configuration_list.set_setting('CODE_SIGN_IDENTITY[sdk=iphoneos*]', "iPhone Developer")
141
+ target.build_configuration_list.set_setting('LD_RUNPATH_SEARCH_PATHS', "$(inherited) @executable_path/Frameworks @loader_path/Frameworks")
142
+ target.build_configuration_list.set_setting('DEVELOPMENT_TEAM', team_id)
143
+
144
+ # Create a shared scheme for the UI tests
145
+ existingScheme = Xcodeproj::XCScheme.shared_data_dir(xcode_project_path) + "/#{scheme_name}.xcscheme"
146
+
147
+ UI.message "Generating XCode Scheme #{scheme_name} to run UI Snapshot Tests"
148
+ scheme = File.exist?(existingScheme) ? Xcodeproj::XCScheme.new(existingScheme) : Xcodeproj::XCScheme.new
149
+
150
+ scheme.add_test_target(target)
151
+
152
+ scheme.add_build_target(main_target)
153
+ scheme.set_launch_target(main_target)
154
+
155
+ scheme.save_as(xcode_project_path, scheme_name)
156
+
157
+ UI.success "Completed Retrofit of #{scheme_name} in Ionic Generated XCode Project #{project_name} OK... SAVING"
158
+
159
+ proj.save
160
+ end
161
+
162
+ def self.description
163
+ 'Bridge between Ionic/Cordova Projects and Fastlane for Automated Snapshot Generation for iOS Projects'
164
+ end
165
+
166
+ def self.authors
167
+ ['Adrian Regan']
168
+ end
169
+
170
+ def self.return_value
171
+ # If your method provides a return value, you can describe here what it does
172
+ end
173
+
174
+ def self.details
175
+ # Optional:
176
+ 'This plugin allows the developer to specify UI Unit Tests and store them in the fastlane configuration. The plugin will copy over these unit tests to the generated Xcode (and hopefully Android) projects, create the required targets/schemes to run the snapshots and integrate into fastlane. It allows for greater automation of the build for ionic/cordova projects that wish to use fastlane'
177
+ end
178
+
179
+ def self.available_options
180
+ [
181
+ FastlaneCore::ConfigItem.new(key: :ionic_ios_xcode_path,
182
+ env_name: 'IONIC_IOS_XCODE_PATH',
183
+ description: 'Path to XCode Project Generated by Ionic',
184
+ default_value: Fastlane::Helper::IonicIntegrationHelper.find_default_ios_xcode_workspace,
185
+ optional: false),
186
+ FastlaneCore::ConfigItem.new(key: :ionic_min_target_ios,
187
+ env_name: 'IONIC_MIN_TARGET_IOS',
188
+ description: 'Minimal iOS Version to Target',
189
+ default_value: IonicIntegration::DEFAULT_IOS_VERSION,
190
+ optional: false),
191
+ FastlaneCore::ConfigItem.new(key: :team_id,
192
+ env_name: 'IONIC_TEAM_ID_IOS',
193
+ description: 'Team Id in iTunesConnect or Apple Developer',
194
+ optional: false),
195
+ FastlaneCore::ConfigItem.new(key: :bundle_id,
196
+ env_name: 'IONIC_BUNDLE_ID_IOS',
197
+ description: 'The Bundle Id of the iOS App, eg: ie.littlevista.whateverapp',
198
+ optional: false)
199
+
200
+ ]
201
+ end
202
+
203
+ def self.is_supported?(platform)
204
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
205
+ # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
206
+ #
207
+ # [:ios, :mac, :android].include?(platform)
208
+ [:ios].include?(platform)
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module IonicIntegration
3
+ IONIC_IOS_BUILD_PATH = "platforms/ios"
4
+ DEFAULT_IOS_VERSION = "9.0"
5
+
6
+ IONIC_CONFIG_PATH = "fastlane/ionic/config"
7
+ IONIC_IOS_CONFIG_PATH = IONIC_CONFIG_PATH + "/ios"
8
+ IONIC_IOS_CONFIG_UITESTS_PATH = IONIC_IOS_CONFIG_PATH + "/ui-tests"
9
+
10
+ IONIC_DEFAULT_UNIT_TEST_NAME = "ui-snapshots"
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ require 'fastlane/plugin/ionic_integration/constants'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ class IonicIntegrationHelper
6
+ HELPER_PATH = File.expand_path(File.dirname(__FILE__))
7
+
8
+ IOS_RESOURCES_PATH = File.expand_path("#{HELPER_PATH}/../resources/ios")
9
+
10
+ #
11
+ # Copy over to the xcode project our pre-configured UI Test Code
12
+ #
13
+ def self.copy_ios_ui_test_code(src_folder, project_folder)
14
+ if src_folder && Dir.exist?(src_folder)
15
+ dest_folder = project_folder.to_s
16
+ UI.message "Copying iOS UI Tests from #{src_folder} to #{dest_folder}"
17
+ Dir.exist?(dest_folder) || FileUtils.mkdir_p(dest_folder)
18
+ FileUtils.cp_r(src_folder + "/.", dest_folder)
19
+ elsif
20
+ UI.user_error! "Copying iOS UI Test Files: #{src_folder} does not exist."
21
+ end
22
+ end
23
+
24
+ def self.copy_ios_sample_tests(scheme_name)
25
+ source_folder = "#{IOS_RESOURCES_PATH}/#{IonicIntegration::IONIC_DEFAULT_UNIT_TEST_NAME}"
26
+ dest_folder = "#{IonicIntegration::IONIC_IOS_CONFIG_UITESTS_PATH}/#{scheme_name}"
27
+ copy_ios_ui_test_code(source_folder, dest_folder)
28
+ end
29
+
30
+ #
31
+ # Find any existing Xcode Workspace generated by Ionic/Cordova
32
+ #
33
+ def self.find_default_ios_xcode_workspace
34
+ Dir["#{IonicIntegration::IONIC_IOS_BUILD_PATH}/*.xcodeproj"].last || nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module IonicIntegration
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-ionic_integration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Regan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-14 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: rake
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: rubocop
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: fastlane
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.26.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.26.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: fakefs
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
+ description:
112
+ email: adrian.regan@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - LICENSE
118
+ - README.md
119
+ - lib/fastlane/plugin/ionic_integration.rb
120
+ - lib/fastlane/plugin/ionic_integration/actions/ionic_ios_config_snapshot_action.rb
121
+ - lib/fastlane/plugin/ionic_integration/actions/ionic_ios_snapshot_action.rb
122
+ - lib/fastlane/plugin/ionic_integration/constants.rb
123
+ - lib/fastlane/plugin/ionic_integration/helper/ionic_integration_helper.rb
124
+ - lib/fastlane/plugin/ionic_integration/resources/ios/ui-snapshots/Info.plist
125
+ - lib/fastlane/plugin/ionic_integration/resources/ios/ui-snapshots/SnapshotHelper.swift
126
+ - lib/fastlane/plugin/ionic_integration/resources/ios/ui-snapshots/ui-snapshots.swift
127
+ - lib/fastlane/plugin/ionic_integration/version.rb
128
+ homepage: https://github.com/knocknarea/fastlane-plugin-ionic_integration
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.8
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Integrating Fastlane with Ionic Generated Projects
152
+ test_files: []