66// Copyright © 2015 Felix Krause. All rights reserved.
77//
88
9- // -----------------------------------------------------
10- // IMPORTANT: When modifying this file, make sure to
11- // increment the version number at the very
12- // bottom of the file to notify users about
13- // the new SnapshotHelper.swift
14- // -----------------------------------------------------
15-
169import Foundation
1710import XCTest
1811
@@ -49,7 +42,7 @@ open class Snapshot: NSObject {
4942
5043 do {
5144 let trimCharacterSet = CharacterSet . whitespacesAndNewlines
52- deviceLanguage = try String ( contentsOf : path, encoding: . utf8) . trimmingCharacters ( in: trimCharacterSet)
45+ deviceLanguage = try NSString ( contentsOfFile : path, encoding: String . Encoding . utf8. rawValue ) . trimmingCharacters ( in: trimCharacterSet) as String
5346 app. launchArguments += [ " -AppleLanguages " , " ( \( deviceLanguage) ) " ]
5447 } catch {
5548 print ( " Couldn't detect/set language... " )
@@ -65,7 +58,7 @@ open class Snapshot: NSObject {
6558
6659 do {
6760 let trimCharacterSet = CharacterSet . whitespacesAndNewlines
68- locale = try String ( contentsOf : path, encoding: . utf8) . trimmingCharacters ( in: trimCharacterSet)
61+ locale = try NSString ( contentsOfFile : path, encoding: String . Encoding . utf8. rawValue ) . trimmingCharacters ( in: trimCharacterSet) as String
6962 } catch {
7063 print ( " Couldn't detect/set locale... " )
7164 }
@@ -84,7 +77,7 @@ open class Snapshot: NSObject {
8477 app. launchArguments += [ " -FASTLANE_SNAPSHOT " , " YES " , " -ui_testing " ]
8578
8679 do {
87- let launchArguments = try String ( contentsOf : path, encoding: String . Encoding. utf8)
80+ let launchArguments = try NSString ( contentsOfFile : path, encoding: String . Encoding. utf8. rawValue ) as String
8881 let regex = try NSRegularExpression ( pattern: " ( \\ \" .+? \\ \" | \\ S+) " , options: [ ] )
8982 let matches = regex. matches ( in: launchArguments, options: [ ] , range: NSRange ( location: 0 , length: launchArguments. characters. count) )
9083 let results = matches. map { result -> String in
@@ -107,8 +100,6 @@ open class Snapshot: NSObject {
107100
108101 #if os(tvOS)
109102 XCUIApplication ( ) . childrenMatchingType ( . Browser) . count
110- #elseif os(OSX)
111- XCUIApplication ( ) . typeKey ( XCUIKeyboardKeySecondaryFn, modifierFlags: [ ] )
112103 #else
113104 XCUIDevice . shared ( ) . orientation = . unknown
114105 #endif
@@ -127,47 +118,21 @@ open class Snapshot: NSObject {
127118 }
128119 }
129120
130- class func pathPrefix( ) -> URL ? {
131- let homeDir : URL
132- //on OSX config is stored in /Users/<username>/Library
133- //and on iOS/tvOS/WatchOS it's in simulator's home dir
134- #if os(OSX)
135- guard let user = ProcessInfo ( ) . environment [ " USER " ] else {
136- print ( " Couldn't find Snapshot configuration files - can't detect current user " )
137- return nil
138- }
139-
140- guard let usersDir = FileManager . default. urls ( for: . userDirectory, in: . localDomainMask) . first else {
141- print ( " Couldn't find Snapshot configuration files - can't detect `Users` dir " )
142- return nil
143- }
144-
145- homeDir = usersDir. appendingPathComponent ( user)
146- #else
147- guard let simulatorHostHome = ProcessInfo ( ) . environment [ " SIMULATOR_HOST_HOME " ] else {
148- print ( " Couldn't find simulator home location. Please, check SIMULATOR_HOST_HOME env variable. " )
149- return nil
150- }
151- guard let homeDirUrl = URL ( string: simulatorHostHome) else {
152- print ( " Can't prepare environment. Simulator home location is inaccessible. Does \( simulatorHostHome) exist? " )
153- return nil
154- }
155- homeDir = URL ( fileURLWithPath: homeDirUrl. path)
156- #endif
157- return homeDir. appendingPathComponent ( " Library/Caches/tools.fastlane " )
121+ class func pathPrefix( ) -> NSString ? {
122+ if let path = ProcessInfo ( ) . environment [ " SIMULATOR_HOST_HOME " ] as NSString ? {
123+ return path. appendingPathComponent ( " Library/Caches/tools.fastlane " ) as NSString ?
124+ }
125+ print ( " Couldn't find Snapshot configuration files at ~/Library/Caches/tools.fastlane " )
126+ return nil
158127 }
159128}
160129
161130extension XCUIElement {
162131 var isLoadingIndicator : Bool {
163- let whiteListedLoaders = [ " GeofenceLocationTrackingOn " , " StandardLocationTrackingOn " ]
164- if whiteListedLoaders. contains ( self . identifier) {
165- return false
166- }
167132 return self . frame. size == CGSize ( width: 10 , height: 20 )
168133 }
169134}
170135
171136// Please don't remove the lines below
172137// They are used to detect outdated configuration files
173- // SnapshotHelperVersion [1.4 ]
138+ // SnapshotHelperVersion [1.2 ]
0 commit comments