snapshot 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +29 -2
- data/lib/assets/SnapfileTemplate +3 -0
- data/lib/assets/SnapshotHelper.swift +24 -0
- data/lib/snapshot.rb +4 -0
- data/lib/snapshot/collector.rb +4 -2
- data/lib/snapshot/fixes/simulator_zoom_fix.rb +1 -1
- data/lib/snapshot/options.rb +7 -0
- data/lib/snapshot/runner.rb +56 -11
- data/lib/snapshot/setup.rb +2 -2
- data/lib/snapshot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5114ebf47b492efce73f8730742424c4210c9b2
|
4
|
+
data.tar.gz: 8cb4bc0486032d9bd4a465ff0a7bc70b40d71a0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 142a574585e51be9ba67a72bb31257333c881430bfb26cf439aed0c1206e18c9c5b9b9c6344dbfdb622a5fa112318cd39a0e55a3aac8c7520c39e5742ff8b0e9
|
7
|
+
data.tar.gz: 6c026cea706c997b6809009a85d1231af7433c68361b764ed098ee9904cca80e0ec949ac061f21632b112b83dbf827d51028f9ee6996afa932197f613316aa4a
|
data/README.md
CHANGED
@@ -152,14 +152,14 @@ Here a few links to get started:
|
|
152
152
|
**Swift**
|
153
153
|
```swift
|
154
154
|
let app = XCUIApplication()
|
155
|
-
|
155
|
+
setupSnapshot(app)
|
156
156
|
app.launch()
|
157
157
|
```
|
158
158
|
|
159
159
|
**Objective C**
|
160
160
|
```objective-c
|
161
161
|
XCUIApplication *app = [[XCUIApplication alloc] init];
|
162
|
-
[Snapshot
|
162
|
+
[Snapshot setupSnapshot:app];
|
163
163
|
[app launch];
|
164
164
|
```
|
165
165
|
|
@@ -225,6 +225,8 @@ languages([
|
|
225
225
|
"es-ES"
|
226
226
|
])
|
227
227
|
|
228
|
+
launch_arguments("-username Felix")
|
229
|
+
|
228
230
|
# The directory in which the screenshots should be stored
|
229
231
|
output_directory './screenshots'
|
230
232
|
|
@@ -255,6 +257,31 @@ snapshot update
|
|
255
257
|
|
256
258
|
to update your `SnapshotHelper.swift` files. In case you modified your `SnapshotHelper.swift` and want to manually update the file, check out [SnapshotHelper.swift](https://github.com/fastlane/snapshot/blob/master/lib/assets/SnapshotHelper.swift).
|
257
259
|
|
260
|
+
## Launch Arguments
|
261
|
+
|
262
|
+
You can provide additional arguments to your app on launch. These strings will be available in your code through `NSProcessInfo.processInfo().arguments`. Alternatively use user-default syntax (`-key value`) and they will be available as key-value pairs in `NSUserDefaults.standardUserDefaults()`.
|
263
|
+
|
264
|
+
`snapshot` includes `-FASTLANE_SNAPSHOT YES`, which will set a temporary user default for the key `FASTLANE_SNAPSHOT`, you may use this to detect when the app is run by `snapshot`.
|
265
|
+
|
266
|
+
```swift
|
267
|
+
if NSUserDefaults.standardUserDefaults().boolForKey("FASTLANE_SNAPSHOT") {
|
268
|
+
// runtime check that we are in snapshot mode
|
269
|
+
}
|
270
|
+
|
271
|
+
username.text = NSUserDefaults.standardUserDefaults().stringForKey("username")
|
272
|
+
// username.text = "Felix"
|
273
|
+
```
|
274
|
+
|
275
|
+
Specify multiple argument strings and `snapshot` will generate screenshots for each combination of arguments, devices, and languages. This is useful for comparing the same screenshots with different feature flags, dynamic text sizes, and different data sets.
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
# Snapfile for A/B Test Comparison
|
279
|
+
launch_arguments([
|
280
|
+
"-secretFeatureEnabled YES",
|
281
|
+
"-secretFeatureEnabled NO"
|
282
|
+
])
|
283
|
+
```
|
284
|
+
|
258
285
|
# How does it work?
|
259
286
|
|
260
287
|
The easiest solution would be to just render the UIWindow into a file. That's not possible because UI Tests don't run on a main thread. So `snapshot` uses a different approach:
|
data/lib/assets/SnapfileTemplate
CHANGED
@@ -16,6 +16,9 @@ languages([
|
|
16
16
|
"it-IT"
|
17
17
|
])
|
18
18
|
|
19
|
+
# Arguments to pass to the app on launch. See https://github.com/fastlane/snapshot#launch_arguments
|
20
|
+
# launch_arguments("-favColor red")
|
21
|
+
|
19
22
|
# The name of the scheme which contains the UI Tests
|
20
23
|
# scheme "SchemeName"
|
21
24
|
|
@@ -11,8 +11,14 @@ import XCTest
|
|
11
11
|
|
12
12
|
var deviceLanguage = ""
|
13
13
|
|
14
|
+
@available(*, deprecated, message="use setupSnapshot: instead")
|
14
15
|
func setLanguage(app: XCUIApplication) {
|
16
|
+
setupSnapshot(app)
|
17
|
+
}
|
18
|
+
|
19
|
+
func setupSnapshot(app: XCUIApplication) {
|
15
20
|
Snapshot.setLanguage(app)
|
21
|
+
Snapshot.setLaunchArguments(app)
|
16
22
|
}
|
17
23
|
|
18
24
|
func snapshot(name: String, waitForLoadingIndicator: Bool = false) {
|
@@ -33,6 +39,24 @@ class Snapshot: NSObject {
|
|
33
39
|
}
|
34
40
|
}
|
35
41
|
|
42
|
+
class func setLaunchArguments(app: XCUIApplication) {
|
43
|
+
let path = "/tmp/snapshot-launch_arguments.txt"
|
44
|
+
|
45
|
+
app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES"]
|
46
|
+
|
47
|
+
do {
|
48
|
+
let launchArguments = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String
|
49
|
+
let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: [])
|
50
|
+
let matches = regex.matchesInString(launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count))
|
51
|
+
let results = matches.map { result -> String in
|
52
|
+
(launchArguments as NSString).substringWithRange(result.range)
|
53
|
+
}
|
54
|
+
app.launchArguments += results
|
55
|
+
} catch {
|
56
|
+
print("Couldn't detect/set launch_arguments...")
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
36
60
|
class func snapshot(name: String, waitForLoadingIndicator: Bool = false) {
|
37
61
|
if waitForLoadingIndicator {
|
38
62
|
waitForLoadingIndicatorToDisappear()
|
data/lib/snapshot.rb
CHANGED
@@ -32,6 +32,10 @@ module Snapshot
|
|
32
32
|
def snapfile_name
|
33
33
|
"Snapfile"
|
34
34
|
end
|
35
|
+
|
36
|
+
def kill_simulator
|
37
|
+
`killall iOS Simulator &> /dev/null`
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
Helper = FastlaneCore::Helper # you gotta love Ruby: Helper.* should use the Helper class contained in FastlaneCore
|
data/lib/snapshot/collector.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Snapshot
|
2
2
|
# Responsible for collecting the generated screenshots and copying them over to the output directory
|
3
3
|
class Collector
|
4
|
-
def self.fetch_screenshots(output, language, device_type)
|
4
|
+
def self.fetch_screenshots(output, language, device_type, launch_arguments_index)
|
5
5
|
# Documentation about how this works in the project README
|
6
6
|
containing = File.join(TestCommandGenerator.derived_data_path, "Logs", "Test")
|
7
7
|
attachments_path = File.join(containing, "Attachments")
|
@@ -21,7 +21,9 @@ module Snapshot
|
|
21
21
|
FileUtils.mkdir_p(language_folder)
|
22
22
|
|
23
23
|
device_name = device_type.delete(" ")
|
24
|
-
|
24
|
+
components = [device_name, launch_arguments_index, name].delete_if { |a| a.to_s.length == 0 }
|
25
|
+
|
26
|
+
output_path = File.join(language_folder, components.join("-") + ".png")
|
25
27
|
from_path = File.join(attachments_path, filename)
|
26
28
|
if $verbose
|
27
29
|
Helper.log.info "Copying file '#{from_path}' to '#{output_path}'...".green
|
data/lib/snapshot/options.rb
CHANGED
@@ -47,6 +47,13 @@ module Snapshot
|
|
47
47
|
default_value: [
|
48
48
|
'en-US'
|
49
49
|
]),
|
50
|
+
FastlaneCore::ConfigItem.new(key: :launch_arguments,
|
51
|
+
env_name: 'SNAPSHOT_LAUNCH_ARGUMENTS',
|
52
|
+
description: "A list of launch arguments which should be used",
|
53
|
+
is_string: false,
|
54
|
+
default_value: [
|
55
|
+
''
|
56
|
+
]),
|
50
57
|
FastlaneCore::ConfigItem.new(key: :output_directory,
|
51
58
|
short_option: "-o",
|
52
59
|
env_name: "SNAPSHOT_OUTPUT_DIRECTORY",
|
data/lib/snapshot/runner.rb
CHANGED
@@ -24,19 +24,28 @@ module Snapshot
|
|
24
24
|
|
25
25
|
self.number_of_retries = 0
|
26
26
|
errors = []
|
27
|
+
results = {} # collect all the results for a nice table
|
28
|
+
launch_arguments_set = config_launch_arguments
|
27
29
|
Snapshot.config[:devices].each do |device|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
launch_arguments_set.each do |launch_arguments|
|
31
|
+
Snapshot.config[:languages].each do |language|
|
32
|
+
results[device] ||= {}
|
33
|
+
|
34
|
+
begin
|
35
|
+
launch(language, device, launch_arguments)
|
36
|
+
results[device][language] = true
|
37
|
+
rescue => ex
|
38
|
+
Helper.log.error ex # we should to show right here as well
|
39
|
+
errors << ex
|
40
|
+
results[device][language] = false
|
41
|
+
raise ex if Snapshot.config[:stop_after_first_error]
|
42
|
+
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
39
46
|
|
47
|
+
print_results(results)
|
48
|
+
|
40
49
|
raise errors.join('; ') if errors.count > 0
|
41
50
|
|
42
51
|
# Generate HTML report
|
@@ -46,16 +55,52 @@ module Snapshot
|
|
46
55
|
FileUtils.rm_rf(TestCommandGenerator.derived_data_path)
|
47
56
|
end
|
48
57
|
|
49
|
-
def
|
58
|
+
def config_launch_arguments
|
59
|
+
launch_arguments = Array(Snapshot.config[:launch_arguments])
|
60
|
+
# if more than 1 set of arguments, use a tuple with an index
|
61
|
+
if launch_arguments.count == 1
|
62
|
+
[launch_arguments]
|
63
|
+
else
|
64
|
+
launch_arguments.map.with_index { |e, i| [i, e] }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def print_results(results)
|
69
|
+
return if results.count == 0
|
70
|
+
|
71
|
+
rows = []
|
72
|
+
results.each do |device, languages|
|
73
|
+
current = [device]
|
74
|
+
languages.each do |language, value|
|
75
|
+
current << (value == true ? " 💚" : " ❌")
|
76
|
+
end
|
77
|
+
rows << current
|
78
|
+
end
|
79
|
+
|
80
|
+
params = {
|
81
|
+
rows: rows,
|
82
|
+
headings: ["Device"] + results.values.first.keys,
|
83
|
+
title: "snapshot results"
|
84
|
+
}
|
85
|
+
puts ""
|
86
|
+
puts Terminal::Table.new(params)
|
87
|
+
puts ""
|
88
|
+
end
|
89
|
+
|
90
|
+
def launch(language, device_type, launch_arguments)
|
50
91
|
screenshots_path = TestCommandGenerator.derived_data_path
|
51
92
|
FileUtils.rm_rf(File.join(screenshots_path, "Logs"))
|
52
93
|
FileUtils.rm_rf(screenshots_path) if Snapshot.config[:clean]
|
53
94
|
FileUtils.mkdir_p(screenshots_path)
|
54
95
|
|
55
96
|
File.write("/tmp/language.txt", language)
|
97
|
+
File.write("/tmp/snapshot-launch_arguments.txt", launch_arguments.last)
|
56
98
|
|
57
99
|
Fixes::SimulatorZoomFix.patch
|
58
100
|
|
101
|
+
Snapshot.kill_simulator # because of https://github.com/fastlane/snapshot/issues/337
|
102
|
+
`xcrun simctl shutdown booted`
|
103
|
+
|
59
104
|
command = TestCommandGenerator.generate(device_type: device_type)
|
60
105
|
|
61
106
|
Helper.log_alert("#{device_type} - #{language}")
|
@@ -82,7 +127,7 @@ module Snapshot
|
|
82
127
|
|
83
128
|
self.number_of_retries += 1
|
84
129
|
if self.number_of_retries < 20
|
85
|
-
launch(language, device_type)
|
130
|
+
launch(language, device_type, launch_arguments)
|
86
131
|
else
|
87
132
|
# It's important to raise an error, as we don't want to collect the screenshots
|
88
133
|
raise "Too many errors... no more retries...".red
|
@@ -90,7 +135,7 @@ module Snapshot
|
|
90
135
|
end)
|
91
136
|
|
92
137
|
raw_output = File.read(TestCommandGenerator.xcodebuild_log_path)
|
93
|
-
Collector.fetch_screenshots(raw_output, language, device_type)
|
138
|
+
Collector.fetch_screenshots(raw_output, language, device_type, launch_arguments.first)
|
94
139
|
end
|
95
140
|
|
96
141
|
def clear_previous_screenshots
|
data/lib/snapshot/setup.rb
CHANGED
@@ -19,10 +19,10 @@ module Snapshot
|
|
19
19
|
puts "Open your Xcode project and make sure to do the following:".yellow
|
20
20
|
puts "1) Add the ./SnapshotHelper.swift to your UI Test target".yellow
|
21
21
|
puts " You can move the file anywhere you want".yellow
|
22
|
-
puts "2) Call `
|
22
|
+
puts "2) Call `setupSnapshot(app)` when launching your app".yellow
|
23
23
|
puts ""
|
24
24
|
puts " let app = XCUIApplication()"
|
25
|
-
puts "
|
25
|
+
puts " setupSnapshot(app)"
|
26
26
|
puts " app.launch()"
|
27
27
|
puts ""
|
28
28
|
puts "3) Add `snapshot(\"0Launch\")` to wherever you want to create the screenshots".yellow
|
data/lib/snapshot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Krause
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|