snapshot 1.15.0 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/SnapshotHelper.swift +26 -26
- data/lib/assets/SnapshotHelper2-3.swift +140 -0
- data/lib/snapshot/setup.rb +4 -2
- data/lib/snapshot/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e2e45d4b91626395ae6af735f77e832402683da
|
4
|
+
data.tar.gz: 1cb9fc6127e5aad69764d6d69e4a3d8861adf590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff03296bdeed4b15f2d56bdccf8881a4712f7c47da376c6f6d7057d3728a3134bc4a81b6bff784eed5c9f864b7af3d65c51844b81e531fd681198dba0863eea
|
7
|
+
data.tar.gz: 2f38154732cf07831bc7d31c47a5c7cd62c4ec12f0f0e2f115e60b84fbca2963f9257934a6901e63c35a64b4ee4224725d29c12d5b7bbd6bd6be439f903fde89
|
@@ -12,76 +12,76 @@ import XCTest
|
|
12
12
|
var deviceLanguage = ""
|
13
13
|
var locale = ""
|
14
14
|
|
15
|
-
@available(*, deprecated, message
|
16
|
-
func setLanguage(app: XCUIApplication) {
|
15
|
+
@available(*, deprecated, message: "use setupSnapshot: instead")
|
16
|
+
func setLanguage(_ app: XCUIApplication) {
|
17
17
|
setupSnapshot(app)
|
18
18
|
}
|
19
19
|
|
20
|
-
func setupSnapshot(app: XCUIApplication) {
|
20
|
+
func setupSnapshot(_ app: XCUIApplication) {
|
21
21
|
Snapshot.setupSnapshot(app)
|
22
22
|
}
|
23
23
|
|
24
|
-
func snapshot(name: String, waitForLoadingIndicator: Bool = true) {
|
24
|
+
func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
|
25
25
|
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
|
26
26
|
}
|
27
27
|
|
28
|
-
|
28
|
+
open class Snapshot: NSObject {
|
29
29
|
|
30
|
-
|
30
|
+
open class func setupSnapshot(_ app: XCUIApplication) {
|
31
31
|
setLanguage(app)
|
32
32
|
setLocale(app)
|
33
33
|
setLaunchArguments(app)
|
34
34
|
}
|
35
35
|
|
36
|
-
class func setLanguage(app: XCUIApplication) {
|
36
|
+
class func setLanguage(_ app: XCUIApplication) {
|
37
37
|
guard let prefix = pathPrefix() else {
|
38
38
|
return
|
39
39
|
}
|
40
40
|
|
41
|
-
let path = prefix.
|
41
|
+
let path = prefix.appendingPathComponent("language.txt")
|
42
42
|
|
43
43
|
do {
|
44
|
-
let trimCharacterSet =
|
45
|
-
deviceLanguage = try NSString(contentsOfFile: path, encoding:
|
44
|
+
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
|
45
|
+
deviceLanguage = try NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue).trimmingCharacters(in: trimCharacterSet) as String
|
46
46
|
app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))"]
|
47
47
|
} catch {
|
48
48
|
print("Couldn't detect/set language...")
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
-
class func setLocale(app: XCUIApplication) {
|
52
|
+
class func setLocale(_ app: XCUIApplication) {
|
53
53
|
guard let prefix = pathPrefix() else {
|
54
54
|
return
|
55
55
|
}
|
56
56
|
|
57
|
-
let path = prefix.
|
57
|
+
let path = prefix.appendingPathComponent("locale.txt")
|
58
58
|
|
59
59
|
do {
|
60
|
-
let trimCharacterSet =
|
61
|
-
locale = try NSString(contentsOfFile: path, encoding:
|
60
|
+
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
|
61
|
+
locale = try NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue).trimmingCharacters(in: trimCharacterSet) as String
|
62
62
|
} catch {
|
63
63
|
print("Couldn't detect/set locale...")
|
64
64
|
}
|
65
65
|
if locale.isEmpty {
|
66
|
-
locale =
|
66
|
+
locale = Locale(identifier: deviceLanguage).identifier
|
67
67
|
}
|
68
68
|
app.launchArguments += ["-AppleLocale", "\"\(locale)\""]
|
69
69
|
}
|
70
70
|
|
71
|
-
class func setLaunchArguments(app: XCUIApplication) {
|
71
|
+
class func setLaunchArguments(_ app: XCUIApplication) {
|
72
72
|
guard let prefix = pathPrefix() else {
|
73
73
|
return
|
74
74
|
}
|
75
75
|
|
76
|
-
let path = prefix.
|
76
|
+
let path = prefix.appendingPathComponent("snapshot-launch_arguments.txt")
|
77
77
|
app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"]
|
78
78
|
|
79
79
|
do {
|
80
|
-
let launchArguments = try NSString(contentsOfFile: path, encoding:
|
80
|
+
let launchArguments = try NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue) as String
|
81
81
|
let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: [])
|
82
|
-
let matches = regex.
|
82
|
+
let matches = regex.matches(in: launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count))
|
83
83
|
let results = matches.map { result -> String in
|
84
|
-
(launchArguments as NSString).
|
84
|
+
(launchArguments as NSString).substring(with: result.range)
|
85
85
|
}
|
86
86
|
app.launchArguments += results
|
87
87
|
} catch {
|
@@ -89,7 +89,7 @@ public class Snapshot: NSObject {
|
|
89
89
|
}
|
90
90
|
}
|
91
91
|
|
92
|
-
|
92
|
+
open class func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
|
93
93
|
if waitForLoadingIndicator {
|
94
94
|
waitForLoadingIndicatorToDisappear()
|
95
95
|
}
|
@@ -101,7 +101,7 @@ public class Snapshot: NSObject {
|
|
101
101
|
#if os(tvOS)
|
102
102
|
XCUIApplication().childrenMatchingType(.Browser).count
|
103
103
|
#else
|
104
|
-
XCUIDevice.
|
104
|
+
XCUIDevice.shared().orientation = .unknown
|
105
105
|
#endif
|
106
106
|
}
|
107
107
|
|
@@ -110,17 +110,17 @@ public class Snapshot: NSObject {
|
|
110
110
|
return;
|
111
111
|
#endif
|
112
112
|
|
113
|
-
let query = XCUIApplication().statusBars.
|
113
|
+
let query = XCUIApplication().statusBars.children(matching: .other).element(boundBy: 1).children(matching: .other)
|
114
114
|
|
115
|
-
while (0..<query.count).map({ query.
|
115
|
+
while (0..<query.count).map({ query.element(boundBy: $0) }).contains(where: { $0.isLoadingIndicator }) {
|
116
116
|
sleep(1)
|
117
117
|
print("Waiting for loading indicator to disappear...")
|
118
118
|
}
|
119
119
|
}
|
120
120
|
|
121
121
|
class func pathPrefix() -> NSString? {
|
122
|
-
if let path =
|
123
|
-
return path.
|
122
|
+
if let path = ProcessInfo().environment["SIMULATOR_HOST_HOME"] as NSString? {
|
123
|
+
return path.appendingPathComponent("Library/Caches/tools.fastlane") as NSString?
|
124
124
|
}
|
125
125
|
print("Couldn't find Snapshot configuration files at ~/Library/Caches/tools.fastlane")
|
126
126
|
return nil
|
@@ -0,0 +1,140 @@
|
|
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
|
+
|
9
|
+
// This file should be used if your UI Tests are written in Swift 2.3
|
10
|
+
|
11
|
+
import Foundation
|
12
|
+
import XCTest
|
13
|
+
|
14
|
+
var deviceLanguage = ""
|
15
|
+
var locale = ""
|
16
|
+
|
17
|
+
@available(*, deprecated, message="use setupSnapshot: instead")
|
18
|
+
func setLanguage(app: XCUIApplication) {
|
19
|
+
setupSnapshot(app)
|
20
|
+
}
|
21
|
+
|
22
|
+
func setupSnapshot(app: XCUIApplication) {
|
23
|
+
Snapshot.setupSnapshot(app)
|
24
|
+
}
|
25
|
+
|
26
|
+
func snapshot(name: String, waitForLoadingIndicator: Bool = true) {
|
27
|
+
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
|
28
|
+
}
|
29
|
+
|
30
|
+
public class Snapshot: NSObject {
|
31
|
+
|
32
|
+
public class func setupSnapshot(app: XCUIApplication) {
|
33
|
+
setLanguage(app)
|
34
|
+
setLocale(app)
|
35
|
+
setLaunchArguments(app)
|
36
|
+
}
|
37
|
+
|
38
|
+
class func setLanguage(app: XCUIApplication) {
|
39
|
+
guard let prefix = pathPrefix() else {
|
40
|
+
return
|
41
|
+
}
|
42
|
+
|
43
|
+
let path = prefix.stringByAppendingPathComponent("language.txt")
|
44
|
+
|
45
|
+
do {
|
46
|
+
let trimCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
|
47
|
+
deviceLanguage = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding).stringByTrimmingCharactersInSet(trimCharacterSet) as String
|
48
|
+
app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))"]
|
49
|
+
} catch {
|
50
|
+
print("Couldn't detect/set language...")
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
class func setLocale(app: XCUIApplication) {
|
55
|
+
guard let prefix = pathPrefix() else {
|
56
|
+
return
|
57
|
+
}
|
58
|
+
|
59
|
+
let path = prefix.stringByAppendingPathComponent("locale.txt")
|
60
|
+
|
61
|
+
do {
|
62
|
+
let trimCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()
|
63
|
+
locale = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding).stringByTrimmingCharactersInSet(trimCharacterSet) as String
|
64
|
+
} catch {
|
65
|
+
print("Couldn't detect/set locale...")
|
66
|
+
}
|
67
|
+
if locale.isEmpty {
|
68
|
+
locale = NSLocale(localeIdentifier: deviceLanguage).localeIdentifier
|
69
|
+
}
|
70
|
+
app.launchArguments += ["-AppleLocale", "\"\(locale)\""]
|
71
|
+
}
|
72
|
+
|
73
|
+
class func setLaunchArguments(app: XCUIApplication) {
|
74
|
+
guard let prefix = pathPrefix() else {
|
75
|
+
return
|
76
|
+
}
|
77
|
+
|
78
|
+
let path = prefix.stringByAppendingPathComponent("snapshot-launch_arguments.txt")
|
79
|
+
app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"]
|
80
|
+
|
81
|
+
do {
|
82
|
+
let launchArguments = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding) as String
|
83
|
+
let regex = try NSRegularExpression(pattern: "(\\\".+?\\\"|\\S+)", options: [])
|
84
|
+
let matches = regex.matchesInString(launchArguments, options: [], range: NSRange(location:0, length:launchArguments.characters.count))
|
85
|
+
let results = matches.map { result -> String in
|
86
|
+
(launchArguments as NSString).substringWithRange(result.range)
|
87
|
+
}
|
88
|
+
app.launchArguments += results
|
89
|
+
} catch {
|
90
|
+
print("Couldn't detect/set launch_arguments...")
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
public class func snapshot(name: String, waitForLoadingIndicator: Bool = true) {
|
95
|
+
if waitForLoadingIndicator {
|
96
|
+
waitForLoadingIndicatorToDisappear()
|
97
|
+
}
|
98
|
+
|
99
|
+
print("snapshot: \(name)") // more information about this, check out https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work
|
100
|
+
|
101
|
+
sleep(1) // Waiting for the animation to be finished (kind of)
|
102
|
+
|
103
|
+
#if os(tvOS)
|
104
|
+
XCUIApplication().childrenMatchingType(.Browser).count
|
105
|
+
#else
|
106
|
+
XCUIDevice.sharedDevice().orientation = .Unknown
|
107
|
+
#endif
|
108
|
+
}
|
109
|
+
|
110
|
+
class func waitForLoadingIndicatorToDisappear() {
|
111
|
+
#if os(tvOS)
|
112
|
+
return;
|
113
|
+
#endif
|
114
|
+
|
115
|
+
let query = XCUIApplication().statusBars.childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other)
|
116
|
+
|
117
|
+
while (0..<query.count).map({ query.elementBoundByIndex($0) }).contains({ $0.isLoadingIndicator }) {
|
118
|
+
sleep(1)
|
119
|
+
print("Waiting for loading indicator to disappear...")
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
class func pathPrefix() -> NSString? {
|
124
|
+
if let path = NSProcessInfo().environment["SIMULATOR_HOST_HOME"] as NSString? {
|
125
|
+
return path.stringByAppendingPathComponent("Library/Caches/tools.fastlane")
|
126
|
+
}
|
127
|
+
print("Couldn't find Snapshot configuration files at ~/Library/Caches/tools.fastlane")
|
128
|
+
return nil
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
extension XCUIElement {
|
133
|
+
var isLoadingIndicator: Bool {
|
134
|
+
return self.frame.size == CGSize(width: 10, height: 20)
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
// Please don't remove the lines below
|
139
|
+
// They are used to detect outdated configuration files
|
140
|
+
// SnapshotHelperVersion [1.2]
|
data/lib/snapshot/setup.rb
CHANGED
@@ -10,9 +10,11 @@ module Snapshot
|
|
10
10
|
|
11
11
|
File.write(snapfile_path, File.read("#{Snapshot::ROOT}/lib/assets/SnapfileTemplate"))
|
12
12
|
File.write(File.join(path, 'SnapshotHelper.swift'), File.read("#{Snapshot::ROOT}/lib/assets/SnapshotHelper.swift"))
|
13
|
+
File.write(File.join(path, 'SnapshotHelper2-3.swift'), File.read("#{Snapshot::ROOT}/lib/assets/SnapshotHelper2-3.swift"))
|
13
14
|
|
14
|
-
puts "Successfully created SnapshotHelper.swift '#{File.join(path, 'SnapshotHelper.swift')}'".green
|
15
|
-
puts "Successfully created
|
15
|
+
puts "✅ Successfully created SnapshotHelper.swift '#{File.join(path, 'SnapshotHelper.swift')}'".green
|
16
|
+
puts "✅ Successfully created SnapshotHelper2-3.swift '#{File.join(path, 'SnapshotHelper2-3.swift')} (if your UI tests are written in Swift 2.3)'".green
|
17
|
+
puts "✅ Successfully created new Snapfile at '#{snapfile_path}'".green
|
16
18
|
|
17
19
|
puts "-------------------------------------------------------".yellow
|
18
20
|
puts "Open your Xcode project and make sure to do the following:".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.16.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: 2016-09-
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastimage
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- bin/snapshot
|
226
226
|
- lib/assets/SnapfileTemplate
|
227
227
|
- lib/assets/SnapshotHelper.swift
|
228
|
+
- lib/assets/SnapshotHelper2-3.swift
|
228
229
|
- lib/snapshot.rb
|
229
230
|
- lib/snapshot/collector.rb
|
230
231
|
- lib/snapshot/commands_generator.rb
|
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
267
|
version: '0'
|
267
268
|
requirements: []
|
268
269
|
rubyforge_project:
|
269
|
-
rubygems_version: 2.
|
270
|
+
rubygems_version: 2.6.6
|
270
271
|
signing_key:
|
271
272
|
specification_version: 4
|
272
273
|
summary: Automate taking localized screenshots of your iOS app on every device
|