snapshot 1.1.1 → 1.2.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 +16 -3
- data/bin/snapshot +10 -0
- data/lib/assets/SnapfileTemplate +1 -0
- data/lib/assets/SnapshotHelper.swift +8 -7
- data/lib/snapshot.rb +2 -0
- data/lib/snapshot/collector.rb +3 -3
- data/lib/snapshot/fixes/README.md +5 -0
- data/lib/snapshot/fixes/simulator_zoom_fix.rb +30 -0
- data/lib/snapshot/reports_generator.rb +1 -0
- data/lib/snapshot/runner.rb +20 -1
- data/lib/snapshot/setup.rb +1 -1
- data/lib/snapshot/update.rb +32 -0
- data/lib/snapshot/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 054323cf6415d800521313446b8bea54920c4f2d
|
4
|
+
data.tar.gz: f763b832b5ae52d1f0f26def4447aafb28789b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af528678ff568a255bd2d53a898fbf8ce3a14758d602dcc096567605990b0e836e1356669699c731de45148e50446e95509c4cdc93c3717295c674a49ab9e18a
|
7
|
+
data.tar.gz: 7bac6cf670f207698a4f4f9a2772d4b6c22087007a46e0530d14853eb243d494db8f078939f4c91f75549d5a88ad93ffc1c3b8aff1ceca6d277bff8f3d7e20ed
|
data/README.md
CHANGED
@@ -131,6 +131,7 @@ Here a few links to get started:
|
|
131
131
|
- [A first look into UI Tests](http://www.mokacoding.com/blog/xcode-7-ui-testing/)
|
132
132
|
- [UI Testing in Xcode 7](http://masilotti.com/ui-testing-xcode-7/)
|
133
133
|
- [HSTestingBackchannel : ‘Cheat’ by communicating directly with your app](https://github.com/ConfusedVorlon/HSTestingBackchannel)
|
134
|
+
- [Automating App Store screenshots using fastlane snapshot and frameit](https://tisunov.github.io/2015/11/06/automating-app-store-screenshots-generation-with-fastlane-snapshot-and-sketch.html)
|
134
135
|
|
135
136
|
**Note**: Since there is no official way to trigger a screenshot from UI Tests, `snapshot` uses a workaround (described in [How Does It Work?](#how-does-it-work)) to trigger a screenshot. If you feel like this should be done right, please duplicate radar [23062925](https://openradar.appspot.com/radar?id=5056366381105152).
|
136
137
|
|
@@ -242,15 +243,27 @@ snapshot reset_simulators
|
|
242
243
|
|
243
244
|
You can use the environment variable `SNAPSHOT_FORCE_DELETE` to stop asking for confirmation before deleting.
|
244
245
|
|
246
|
+
## Update snapshot helpers
|
247
|
+
|
248
|
+
Some updates require the helper files to be updated. `snapshot` will automatically warn you and tell you how to update.
|
249
|
+
|
250
|
+
Basically you can run
|
251
|
+
|
252
|
+
```
|
253
|
+
snapshot update
|
254
|
+
```
|
255
|
+
|
256
|
+
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
|
+
|
245
258
|
# How does it work?
|
246
259
|
|
247
260
|
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:
|
248
261
|
|
249
|
-
When you run unit tests in Xcode, the reporter generates a plist file, documenting all events that occured during the tests ([More Information](http://michele.io/test-logs-in-xcode)). Additionally, Xcode generates screenshots before, during and after each of these events. There
|
262
|
+
When you run unit tests in Xcode, the reporter generates a plist file, documenting all events that occured during the tests ([More Information](http://michele.io/test-logs-in-xcode)). Additionally, Xcode generates screenshots before, during and after each of these events. There is no way to manually trigger a screenshot event. The screenshots and the plist files are stored in the DerivedData directory, which `snapshot` stores in a temporary folder.
|
250
263
|
|
251
|
-
When the user calls `snapshot(...)` in the UI Tests (Swift or Objective C) the script actually
|
264
|
+
When the user calls `snapshot(...)` in the UI Tests (Swift or Objective C) the script actually does a rotation to `.Invalid` which doesn't have any effect on the actual app, but is enough to trigger a screenshot. It has no effect to the application and is not something you would do in your tests. The goal was to find *some* event that a user would never trigger, so that we know it's from `snapshot`.
|
252
265
|
|
253
|
-
`snapshot` then iterates through all test events and check where we did this weird
|
266
|
+
`snapshot` then iterates through all test events and check where we did this weird rotation. Once `snapshot` has all events triggered by `snapshot` it collects a ordered list of all the file names of the actual screenshots of the application.
|
254
267
|
|
255
268
|
In the test output, the Swift `snapshot` function will print out something like this
|
256
269
|
|
data/bin/snapshot
CHANGED
@@ -49,6 +49,16 @@ class SnapshotApplication
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
command :update do |c|
|
53
|
+
c.syntax = 'snapshot update'
|
54
|
+
c.description = "Updates your SnapshotHelper.swift to the latest version"
|
55
|
+
|
56
|
+
c.action do |args, options|
|
57
|
+
require 'snapshot/update'
|
58
|
+
Snapshot::Update.new.update
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
52
62
|
command :reset_simulators do |c|
|
53
63
|
c.syntax = 'snapshot reset_simulators'
|
54
64
|
c.description = "This will remove all your existing simulators and re-create new ones"
|
data/lib/assets/SnapfileTemplate
CHANGED
@@ -16,7 +16,7 @@ func setLanguage(app: XCUIApplication)
|
|
16
16
|
Snapshot.setLanguage(app)
|
17
17
|
}
|
18
18
|
|
19
|
-
func snapshot(name: String, waitForLoadingIndicator: Bool =
|
19
|
+
func snapshot(name: String, waitForLoadingIndicator: Bool = false)
|
20
20
|
{
|
21
21
|
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
|
22
22
|
}
|
@@ -28,7 +28,7 @@ func snapshot(name: String, waitForLoadingIndicator: Bool = true)
|
|
28
28
|
class func setLanguage(app: XCUIApplication)
|
29
29
|
{
|
30
30
|
let path = "/tmp/language.txt"
|
31
|
-
|
31
|
+
|
32
32
|
do {
|
33
33
|
let locale = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String
|
34
34
|
deviceLanguage = locale.substringToIndex(locale.startIndex.advancedBy(2, limit:locale.endIndex))
|
@@ -46,11 +46,8 @@ func snapshot(name: String, waitForLoadingIndicator: Bool = true)
|
|
46
46
|
}
|
47
47
|
print("snapshot: \(name)") // more information about this, check out https://github.com/krausefx/snapshot
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
let finish = view.coordinateWithNormalizedOffset(CGVectorMake(31, 30000))
|
52
|
-
start.pressForDuration(0, thenDragToCoordinate: finish)
|
53
|
-
sleep(1)
|
49
|
+
sleep(1) // Waiting for the animation to be finished (kind of)
|
50
|
+
XCUIDevice.sharedDevice().orientation = .Unknown
|
54
51
|
}
|
55
52
|
|
56
53
|
class func waitForLoadingIndicatorToDisappear()
|
@@ -63,3 +60,7 @@ func snapshot(name: String, waitForLoadingIndicator: Bool = true)
|
|
63
60
|
}
|
64
61
|
}
|
65
62
|
}
|
63
|
+
|
64
|
+
// Please don't remove the lines below
|
65
|
+
// They are used to detect outdated configuration files
|
66
|
+
// SnapshotHelperVersion [[1.0]]
|
data/lib/snapshot.rb
CHANGED
data/lib/snapshot/collector.rb
CHANGED
@@ -46,8 +46,8 @@ module Snapshot
|
|
46
46
|
(subtest["Subtests"] || []).each do |subtest2|
|
47
47
|
(subtest2["Subtests"] || []).each do |subtest3|
|
48
48
|
(subtest3["ActivitySummaries"] || []).each do |activity|
|
49
|
-
# We now check if it's the
|
50
|
-
was_snapshot = activity["Title"]
|
49
|
+
# We now check if it's the rotation gesture, because that's the only thing we care about
|
50
|
+
was_snapshot = activity["Title"] == "Set device orientation to Unknown"
|
51
51
|
activities << activity if was_snapshot
|
52
52
|
end
|
53
53
|
end
|
@@ -61,7 +61,7 @@ module Snapshot
|
|
61
61
|
to_store = [] # contains the names of all the attachments we want to use
|
62
62
|
activities.each do |activity|
|
63
63
|
# We do care about this, all "Long press Target" events mean screenshots
|
64
|
-
attachment_entry = activity
|
64
|
+
attachment_entry = activity
|
65
65
|
to_store << attachment_entry["Attachments"].last["FileName"]
|
66
66
|
end
|
67
67
|
|
@@ -0,0 +1,5 @@
|
|
1
|
+
### Fixes
|
2
|
+
|
3
|
+
This directory contains all the files we don't actually want to have, but are necessary due to open radars, e.g.
|
4
|
+
- [#5056366381105152](https://openradar.appspot.com/radar?id=5056366381105152): Trigger screenshots from UI Tests
|
5
|
+
- [#6127019184095232](https://openradar.appspot.com/radar?id=6127019184095232): Screenshots are broken when simulator is not scaled at 100%
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Snapshot
|
2
|
+
module Fixes
|
3
|
+
# This fix is needed due to a bug in UI Tests that creates invalid screenshots when the
|
4
|
+
# simulator is not scaled to a 100%
|
5
|
+
# Issue: https://github.com/fastlane/snapshot/issues/249
|
6
|
+
# Radar: https://openradar.appspot.com/radar?id=6127019184095232
|
7
|
+
|
8
|
+
class SimulatorZoomFix
|
9
|
+
def self.patch
|
10
|
+
# First we need to kill the simulator
|
11
|
+
`killall iOS Simulator &> /dev/null`
|
12
|
+
|
13
|
+
Helper.log.debug "Patching '#{config_path}' to scale simulator to 100%"
|
14
|
+
|
15
|
+
FastlaneCore::Simulator.all.each do |simulator|
|
16
|
+
simulator_name = simulator.name.tr(" ", "-")
|
17
|
+
key = "SimulatorWindowLastScale-com.apple.CoreSimulator.SimDeviceType.#{simulator_name}"
|
18
|
+
|
19
|
+
command = "defaults write '#{config_path}' '#{key}' '1.0'"
|
20
|
+
puts command.yellow if $debug
|
21
|
+
`#{command}`
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.config_path
|
26
|
+
File.join(File.expand_path("~"), "Library", "Preferences", "com.apple.iphonesimulator.plist")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/snapshot/runner.rb
CHANGED
@@ -14,6 +14,8 @@ module Snapshot
|
|
14
14
|
sleep 3 # to be sure the user sees this, as compiling clears the screen
|
15
15
|
end
|
16
16
|
|
17
|
+
verify_helper_is_current
|
18
|
+
|
17
19
|
FastlaneCore::PrintTable.print_values(config: Snapshot.config, hide_keys: [], title: "Summary for snapshot #{Snapshot::VERSION}")
|
18
20
|
|
19
21
|
clear_previous_screenshots if Snapshot.config[:clear_previous_screenshots]
|
@@ -48,6 +50,8 @@ module Snapshot
|
|
48
50
|
|
49
51
|
File.write("/tmp/language.txt", language)
|
50
52
|
|
53
|
+
Fixes::SimulatorZoomFix.patch
|
54
|
+
|
51
55
|
command = TestCommandGenerator.generate(device_type: device_type)
|
52
56
|
|
53
57
|
Helper.log_alert("#{device_type} - #{language}")
|
@@ -70,7 +74,7 @@ module Snapshot
|
|
70
74
|
ErrorHandler.handle_test_error(output, return_code)
|
71
75
|
|
72
76
|
# no exception raised... that means we need to retry
|
73
|
-
Helper.log.info "
|
77
|
+
Helper.log.info "Caught error... #{return_code}".red
|
74
78
|
|
75
79
|
self.number_of_retries += 1
|
76
80
|
if self.number_of_retries < 20
|
@@ -92,5 +96,20 @@ module Snapshot
|
|
92
96
|
File.delete(current)
|
93
97
|
end
|
94
98
|
end
|
99
|
+
|
100
|
+
# rubocop:disable Style/Next
|
101
|
+
def verify_helper_is_current
|
102
|
+
helper_files = Update.find_helper
|
103
|
+
helper_files.each do |path|
|
104
|
+
content = File.read(path)
|
105
|
+
|
106
|
+
if content.include?("start.pressForDuration(0, thenDragToCoordinate: finish)")
|
107
|
+
Helper.log.error "Your '#{path}' is outdated, please run `snapshot update`".red
|
108
|
+
Helper.log.error "to update your Helper file".red
|
109
|
+
raise "Please update your Snapshot Helper file".red
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
# rubocop:enable Style/Next
|
95
114
|
end
|
96
115
|
end
|
data/lib/snapshot/setup.rb
CHANGED
@@ -12,7 +12,7 @@ module Snapshot
|
|
12
12
|
File.write(snapfile_path, File.read("#{gem_path}/lib/assets/SnapfileTemplate"))
|
13
13
|
File.write(File.join(path, 'SnapshotHelper.swift'), File.read("#{gem_path}/lib/assets/SnapshotHelper.swift"))
|
14
14
|
|
15
|
-
puts "Successfully created SnapshotHelper.
|
15
|
+
puts "Successfully created SnapshotHelper.swift '#{File.join(path, 'SnapshotHelper.swift')}'".green
|
16
16
|
puts "Successfully created new Snapfile at '#{snapfile_path}'".green
|
17
17
|
|
18
18
|
puts "-------------------------------------------------------".yellow
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Snapshot
|
2
|
+
# Migrate helper files
|
3
|
+
class Update
|
4
|
+
# @return [Array] A list of helper files (usually just one)
|
5
|
+
def self.find_helper
|
6
|
+
Dir["./**/SnapshotHelper.swift"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
gem_path = Helper.gem_path("snapshot")
|
11
|
+
paths = self.class.find_helper
|
12
|
+
|
13
|
+
Helper.log.info "Found the following SnapshotHelper:"
|
14
|
+
puts ''
|
15
|
+
paths.each { |p| Helper.log.info "\t#{p}" }
|
16
|
+
puts ''
|
17
|
+
Helper.log.info "Are you sure you want to automatically update the helpers listed above?"
|
18
|
+
Helper.log.info "This will overwrite all its content with the latest code."
|
19
|
+
Helper.log.info "The underlying API will not change. You can always migrate manually by looking at"
|
20
|
+
Helper.log.info "https://github.com/fastlane/snapshot/blob/master/lib/assets/SnapshotHelper.swift"
|
21
|
+
|
22
|
+
return 1 unless agree("Overwrite configuration files? (y/n)".red, true)
|
23
|
+
|
24
|
+
paths.each do |path|
|
25
|
+
Helper.log.info "Updating '#{path}'..."
|
26
|
+
File.write(path, File.read("#{gem_path}/lib/assets/SnapshotHelper.swift"))
|
27
|
+
end
|
28
|
+
|
29
|
+
Helper.log.info "Successfully updated helper files".green
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
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.2.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-11-
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|
@@ -216,6 +216,8 @@ files:
|
|
216
216
|
- lib/snapshot/dependency_checker.rb
|
217
217
|
- lib/snapshot/detect_values.rb
|
218
218
|
- lib/snapshot/error_handler.rb
|
219
|
+
- lib/snapshot/fixes/README.md
|
220
|
+
- lib/snapshot/fixes/simulator_zoom_fix.rb
|
219
221
|
- lib/snapshot/latest_ios_version.rb
|
220
222
|
- lib/snapshot/options.rb
|
221
223
|
- lib/snapshot/page.html.erb
|
@@ -226,6 +228,7 @@ files:
|
|
226
228
|
- lib/snapshot/screenshot_rotate.rb
|
227
229
|
- lib/snapshot/setup.rb
|
228
230
|
- lib/snapshot/test_command_generator.rb
|
231
|
+
- lib/snapshot/update.rb
|
229
232
|
- lib/snapshot/version.rb
|
230
233
|
homepage: https://fastlane.tools
|
231
234
|
licenses:
|
@@ -247,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
250
|
version: '0'
|
248
251
|
requirements: []
|
249
252
|
rubyforge_project:
|
250
|
-
rubygems_version: 2.
|
253
|
+
rubygems_version: 2.4.0
|
251
254
|
signing_key:
|
252
255
|
specification_version: 4
|
253
256
|
summary: Automate taking localized screenshots of your iOS app on every device
|