@@ -18,8 +18,8 @@ import XCTest
18
18
var deviceLanguage = " "
19
19
var locale = " "
20
20
21
- func setupSnapshot( _ app: XCUIApplication ) {
22
- Snapshot . setupSnapshot ( app)
21
+ func setupSnapshot( _ app: XCUIApplication , waitForAnimations : Bool = true ) {
22
+ Snapshot . setupSnapshot ( app, waitForAnimations : waitForAnimations )
23
23
}
24
24
25
25
func snapshot( _ name: String , waitForLoadingIndicator: Bool ) {
@@ -63,14 +63,16 @@ enum SnapshotError: Error, CustomDebugStringConvertible {
63
63
@objcMembers
64
64
open class Snapshot : NSObject {
65
65
static var app : XCUIApplication ?
66
+ static var waitForAnimations = true
66
67
static var cacheDirectory : URL ?
67
68
static var screenshotsDirectory : URL ? {
68
69
return cacheDirectory? . appendingPathComponent ( " screenshots " , isDirectory: true )
69
70
}
70
71
71
- open class func setupSnapshot( _ app: XCUIApplication ) {
72
+ open class func setupSnapshot( _ app: XCUIApplication , waitForAnimations : Bool = true ) {
72
73
73
74
Snapshot . app = app
75
+ Snapshot . waitForAnimations = waitForAnimations
74
76
75
77
do {
76
78
let cacheDir = try pathPrefix ( )
@@ -115,7 +117,7 @@ open class Snapshot: NSObject {
115
117
print ( " Couldn't detect/set locale... " )
116
118
}
117
119
118
- if locale. isEmpty {
120
+ if locale. isEmpty && !deviceLanguage . isEmpty {
119
121
locale = Locale ( identifier: deviceLanguage) . identifier
120
122
}
121
123
@@ -153,10 +155,17 @@ open class Snapshot: NSObject {
153
155
154
156
print ( " snapshot: \( name) " ) // more information about this, check out https://docs.fastlane.tools/actions/snapshot/#how-does-it-work
155
157
156
- sleep ( 1 ) // Waiting for the animation to be finished (kind of)
158
+ if Snapshot . waitForAnimations {
159
+ sleep ( 1 ) // Waiting for the animation to be finished (kind of)
160
+ }
157
161
158
162
#if os(OSX)
159
- XCUIApplication ( ) . typeKey ( XCUIKeyboardKeySecondaryFn, modifierFlags: [ ] )
163
+ guard let app = self . app else {
164
+ print ( " XCUIApplication is not set. Please call setupSnapshot(app) before snapshot(). " )
165
+ return
166
+ }
167
+
168
+ app. typeKey ( XCUIKeyboardKeySecondaryFn, modifierFlags: [ ] )
160
169
#else
161
170
162
171
guard let app = self . app else {
@@ -182,7 +191,12 @@ open class Snapshot: NSObject {
182
191
return
183
192
#endif
184
193
185
- let networkLoadingIndicator = XCUIApplication ( ) . otherElements. deviceStatusBars. networkLoadingIndicators. element
194
+ guard let app = self . app else {
195
+ print ( " XCUIApplication is not set. Please call setupSnapshot(app) before snapshot(). " )
196
+ return
197
+ }
198
+
199
+ let networkLoadingIndicator = app. otherElements. deviceStatusBars. networkLoadingIndicators. element
186
200
let networkLoadingIndicatorDisappeared = XCTNSPredicateExpectation ( predicate: NSPredicate ( format: " exists == false " ) , object: networkLoadingIndicator)
187
201
_ = XCTWaiter . wait ( for: [ networkLoadingIndicatorDisappeared] , timeout: timeout)
188
202
}
@@ -257,7 +271,11 @@ private extension XCUIElementQuery {
257
271
}
258
272
259
273
var deviceStatusBars : XCUIElementQuery {
260
- let deviceWidth = XCUIApplication ( ) . windows. firstMatch. frame. width
274
+ guard let app = Snapshot . app else {
275
+ fatalError ( " XCUIApplication is not set. Please call setupSnapshot(app) before snapshot(). " )
276
+ }
277
+
278
+ let deviceWidth = app. windows. firstMatch. frame. width
261
279
262
280
let isStatusBar = NSPredicate { ( evaluatedObject, _) in
263
281
guard let element = evaluatedObject as? XCUIElementAttributes else { return false }
@@ -277,4 +295,4 @@ private extension CGFloat {
277
295
278
296
// Please don't remove the lines below
279
297
// They are used to detect outdated configuration files
280
- // SnapshotHelperVersion [1.13 ]
298
+ // SnapshotHelperVersion [1.15 ]
0 commit comments