@@ -18,8 +18,8 @@ import XCTest
1818var deviceLanguage = " "
1919var locale = " "
2020
21- func setupSnapshot( _ app: XCUIApplication ) {
22- Snapshot . setupSnapshot ( app)
21+ func setupSnapshot( _ app: XCUIApplication , waitForAnimations : Bool = true ) {
22+ Snapshot . setupSnapshot ( app, waitForAnimations : waitForAnimations )
2323}
2424
2525func snapshot( _ name: String , waitForLoadingIndicator: Bool ) {
@@ -63,14 +63,16 @@ enum SnapshotError: Error, CustomDebugStringConvertible {
6363@objcMembers
6464open class Snapshot : NSObject {
6565 static var app : XCUIApplication ?
66+ static var waitForAnimations = true
6667 static var cacheDirectory : URL ?
6768 static var screenshotsDirectory : URL ? {
6869 return cacheDirectory? . appendingPathComponent ( " screenshots " , isDirectory: true )
6970 }
7071
71- open class func setupSnapshot( _ app: XCUIApplication ) {
72+ open class func setupSnapshot( _ app: XCUIApplication , waitForAnimations : Bool = true ) {
7273
7374 Snapshot . app = app
75+ Snapshot . waitForAnimations = waitForAnimations
7476
7577 do {
7678 let cacheDir = try pathPrefix ( )
@@ -114,10 +116,14 @@ open class Snapshot: NSObject {
114116 } catch {
115117 print ( " Couldn't detect/set locale... " )
116118 }
117- if locale. isEmpty {
119+
120+ if locale. isEmpty && !deviceLanguage. isEmpty {
118121 locale = Locale ( identifier: deviceLanguage) . identifier
119122 }
120- app. launchArguments += [ " -AppleLocale " , " \" \( locale) \" " ]
123+
124+ if !locale. isEmpty {
125+ app. launchArguments += [ " -AppleLocale " , " \" \( locale) \" " ]
126+ }
121127 }
122128
123129 class func setLaunchArguments( _ app: XCUIApplication ) {
@@ -149,22 +155,25 @@ open class Snapshot: NSObject {
149155
150156 print ( " snapshot: \( name) " ) // more information about this, check out https://docs.fastlane.tools/actions/snapshot/#how-does-it-work
151157
152- 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+ }
153161
154162 #if os(OSX)
155- XCUIApplication ( ) . typeKey ( XCUIKeyboardKeySecondaryFn, modifierFlags: [ ] )
156- #else
157-
158163 guard let app = self . app else {
159164 print ( " XCUIApplication is not set. Please call setupSnapshot(app) before snapshot(). " )
160165 return
161166 }
167+
168+ app. typeKey ( XCUIKeyboardKeySecondaryFn, modifierFlags: [ ] )
169+ #else
162170
163- guard let window = app. windows . allElementsBoundByIndex . first ( where : { $0 . frame . isEmpty == false } ) else {
164- print ( " Couldn't find an element window in XCUIApplication with a non-empty frame ." )
171+ guard let app = self . app else {
172+ print ( " XCUIApplication is not set. Please call setupSnapshot(app) before snapshot() ." )
165173 return
166174 }
167-
175+
176+ let window = app. windows. firstMatch
168177 let screenshot = window. screenshot ( )
169178 guard let simulator = ProcessInfo ( ) . environment [ " SIMULATOR_DEVICE_NAME " ] , let screenshotsDir = screenshotsDirectory else { return }
170179 let path = screenshotsDir. appendingPathComponent ( " \( simulator) - \( name) .png " )
@@ -182,7 +191,12 @@ open class Snapshot: NSObject {
182191 return
183192 #endif
184193
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
186200 let networkLoadingIndicatorDisappeared = XCTNSPredicateExpectation ( predicate: NSPredicate ( format: " exists == false " ) , object: networkLoadingIndicator)
187201 _ = XCTWaiter . wait ( for: [ networkLoadingIndicatorDisappeared] , timeout: timeout)
188202 }
@@ -257,7 +271,11 @@ private extension XCUIElementQuery {
257271 }
258272
259273 var deviceStatusBars : XCUIElementQuery {
260- let deviceWidth = XCUIApplication ( ) . 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
261279
262280 let isStatusBar = NSPredicate { ( evaluatedObject, _) in
263281 guard let element = evaluatedObject as? XCUIElementAttributes else { return false }
@@ -277,4 +295,4 @@ private extension CGFloat {
277295
278296// Please don't remove the lines below
279297// They are used to detect outdated configuration files
280- // SnapshotHelperVersion [1.10 ]
298+ // SnapshotHelperVersion [1.15 ]
0 commit comments