15
15
import Foundation
16
16
import XCTest
17
17
18
- var deviceLanguage = " "
19
- var locale = " "
20
-
18
+ @MainActor
21
19
func setupSnapshot( _ app: XCUIApplication , waitForAnimations: Bool = true ) {
22
20
Snapshot . setupSnapshot ( app, waitForAnimations: waitForAnimations)
23
21
}
24
22
23
+ @MainActor
25
24
func snapshot( _ name: String , waitForLoadingIndicator: Bool ) {
26
25
if waitForLoadingIndicator {
27
26
Snapshot . snapshot ( name)
@@ -33,6 +32,7 @@ func snapshot(_ name: String, waitForLoadingIndicator: Bool) {
33
32
/// - Parameters:
34
33
/// - name: The name of the snapshot
35
34
/// - timeout: Amount of seconds to wait until the network loading indicator disappears. Pass `0` if you don't want to wait.
35
+ @MainActor
36
36
func snapshot( _ name: String , timeWaitingForIdle timeout: TimeInterval = 20 ) {
37
37
Snapshot . snapshot ( name, timeWaitingForIdle: timeout)
38
38
}
@@ -52,6 +52,7 @@ enum SnapshotError: Error, CustomDebugStringConvertible {
52
52
}
53
53
54
54
@objcMembers
55
+ @MainActor
55
56
open class Snapshot : NSObject {
56
57
static var app : XCUIApplication ?
57
58
static var waitForAnimations = true
@@ -60,6 +61,9 @@ open class Snapshot: NSObject {
60
61
return cacheDirectory? . appendingPathComponent ( " screenshots " , isDirectory: true )
61
62
}
62
63
64
+ static var deviceLanguage = " "
65
+ static var currentLocale = " "
66
+
63
67
open class func setupSnapshot( _ app: XCUIApplication , waitForAnimations: Bool = true ) {
64
68
Snapshot . app = app
65
69
Snapshot . waitForAnimations = waitForAnimations
@@ -102,17 +106,17 @@ open class Snapshot: NSObject {
102
106
103
107
do {
104
108
let trimCharacterSet = CharacterSet . whitespacesAndNewlines
105
- locale = try String ( contentsOf: path, encoding: . utf8) . trimmingCharacters ( in: trimCharacterSet)
109
+ currentLocale = try String ( contentsOf: path, encoding: . utf8) . trimmingCharacters ( in: trimCharacterSet)
106
110
} catch {
107
111
NSLog ( " Couldn't detect/set locale... " )
108
112
}
109
113
110
- if locale . isEmpty, !deviceLanguage. isEmpty {
111
- locale = Locale ( identifier: deviceLanguage) . identifier
114
+ if currentLocale . isEmpty && !deviceLanguage. isEmpty {
115
+ currentLocale = Locale ( identifier: deviceLanguage) . identifier
112
116
}
113
117
114
- if !locale . isEmpty {
115
- app. launchArguments += [ " -AppleLocale " , " \" \( locale ) \" " ]
118
+ if !currentLocale . isEmpty {
119
+ app. launchArguments += [ " -AppleLocale " , " \" \( currentLocale ) \" " ]
116
120
}
117
121
}
118
122
@@ -180,7 +184,7 @@ open class Snapshot: NSObject {
180
184
181
185
let path = screenshotsDir. appendingPathComponent ( " \( simulator) - \( name) .png " )
182
186
#if swift(<5.0)
183
- UIImagePNGRepresentation ( image) ? . write ( to: path, options: . atomic)
187
+ try UIImagePNGRepresentation ( image) ? . write ( to: path, options: . atomic)
184
188
#else
185
189
try image. pngData ( ) ? . write ( to: path, options: . atomic)
186
190
#endif
@@ -280,6 +284,7 @@ private extension XCUIElementQuery {
280
284
return containing ( isNetworkLoadingIndicator)
281
285
}
282
286
287
+ @MainActor
283
288
var deviceStatusBars : XCUIElementQuery {
284
289
guard let app = Snapshot . app else {
285
290
fatalError ( " XCUIApplication is not set. Please call setupSnapshot(app) before snapshot(). " )
@@ -305,4 +310,4 @@ private extension CGFloat {
305
310
306
311
// Please don't remove the lines below
307
312
// They are used to detect outdated configuration files
308
- // SnapshotHelperVersion [1.28 ]
313
+ // SnapshotHelperVersion [1.30 ]
0 commit comments