diff --git a/IRCCloud/Classes/BuffersTableView.m b/IRCCloud/Classes/BuffersTableView.m index aae3c9c39..ff7ae5784 100644 --- a/IRCCloud/Classes/BuffersTableView.m +++ b/IRCCloud/Classes/BuffersTableView.m @@ -567,7 +567,7 @@ - (void)refresh { -(void)_updateUnreadIndicators { #ifndef EXTENSION [self.tableView visibleCells]; - CGRect bounds = UIEdgeInsetsInsetRect(self.tableView.bounds, self.safeAreaInsets); + CGRect bounds = UIEdgeInsetsInsetRect(self.tableView.bounds, UIEdgeInsetsMake(0, 0, self.safeAreaInsets.bottom, 0)); NSArray *rows = [self.tableView indexPathsForRowsInRect:bounds]; if(rows.count) { NSInteger first = [[rows objectAtIndex:0] row]; diff --git a/UITests/SnapshotHelper.swift b/UITests/SnapshotHelper.swift index 08b7e842e..0046aaa68 100644 --- a/UITests/SnapshotHelper.swift +++ b/UITests/SnapshotHelper.swift @@ -18,8 +18,8 @@ import XCTest var deviceLanguage = "" var locale = "" -func setupSnapshot(_ app: XCUIApplication) { - Snapshot.setupSnapshot(app) +func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) { + Snapshot.setupSnapshot(app, waitForAnimations: waitForAnimations) } func snapshot(_ name: String, waitForLoadingIndicator: Bool) { @@ -38,22 +38,13 @@ func snapshot(_ name: String, timeWaitingForIdle timeout: TimeInterval = 20) { } enum SnapshotError: Error, CustomDebugStringConvertible { - case cannotDetectUser - case cannotFindHomeDirectory case cannotFindSimulatorHomeDirectory - case cannotAccessSimulatorHomeDirectory(String) case cannotRunOnPhysicalDevice var debugDescription: String { switch self { - case .cannotDetectUser: - return "Couldn't find Snapshot configuration files - can't detect current user " - case .cannotFindHomeDirectory: - return "Couldn't find Snapshot configuration files - can't detect `Users` dir" case .cannotFindSimulatorHomeDirectory: return "Couldn't find simulator home location. Please, check SIMULATOR_HOST_HOME env variable." - case .cannotAccessSimulatorHomeDirectory(let simulatorHostHome): - return "Can't prepare environment. Simulator home location is inaccessible. Does \(simulatorHostHome) exist?" case .cannotRunOnPhysicalDevice: return "Can't use Snapshot on a physical device." } @@ -63,32 +54,34 @@ enum SnapshotError: Error, CustomDebugStringConvertible { @objcMembers open class Snapshot: NSObject { static var app: XCUIApplication? + static var waitForAnimations = true static var cacheDirectory: URL? static var screenshotsDirectory: URL? { return cacheDirectory?.appendingPathComponent("screenshots", isDirectory: true) } - open class func setupSnapshot(_ app: XCUIApplication) { - + open class func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) { + Snapshot.app = app + Snapshot.waitForAnimations = waitForAnimations do { - let cacheDir = try pathPrefix() + let cacheDir = try getCacheDirectory() Snapshot.cacheDirectory = cacheDir setLanguage(app) setLocale(app) setLaunchArguments(app) } catch let error { - print(error) + NSLog(error.localizedDescription) } } class func setLanguage(_ app: XCUIApplication) { guard let cacheDirectory = self.cacheDirectory else { - print("CacheDirectory is not set - probably running on a physical device?") + NSLog("CacheDirectory is not set - probably running on a physical device?") return } - + let path = cacheDirectory.appendingPathComponent("language.txt") do { @@ -96,29 +89,29 @@ open class Snapshot: NSObject { deviceLanguage = try String(contentsOf: path, encoding: .utf8).trimmingCharacters(in: trimCharacterSet) app.launchArguments += ["-AppleLanguages", "(\(deviceLanguage))"] } catch { - print("Couldn't detect/set language...") + NSLog("Couldn't detect/set language...") } } class func setLocale(_ app: XCUIApplication) { guard let cacheDirectory = self.cacheDirectory else { - print("CacheDirectory is not set - probably running on a physical device?") + NSLog("CacheDirectory is not set - probably running on a physical device?") return } - + let path = cacheDirectory.appendingPathComponent("locale.txt") do { let trimCharacterSet = CharacterSet.whitespacesAndNewlines locale = try String(contentsOf: path, encoding: .utf8).trimmingCharacters(in: trimCharacterSet) } catch { - print("Couldn't detect/set locale...") + NSLog("Couldn't detect/set locale...") } - + if locale.isEmpty && !deviceLanguage.isEmpty { locale = Locale(identifier: deviceLanguage).identifier } - + if !locale.isEmpty { app.launchArguments += ["-AppleLocale", "\"\(locale)\""] } @@ -126,10 +119,10 @@ open class Snapshot: NSObject { class func setLaunchArguments(_ app: XCUIApplication) { guard let cacheDirectory = self.cacheDirectory else { - print("CacheDirectory is not set - probably running on a physical device?") + NSLog("CacheDirectory is not set - probably running on a physical device?") return } - + let path = cacheDirectory.appendingPathComponent("snapshot-launch_arguments.txt") app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"] @@ -142,7 +135,7 @@ open class Snapshot: NSObject { } app.launchArguments += results } catch { - print("Couldn't detect/set launch_arguments...") + NSLog("Couldn't detect/set launch_arguments...") } } @@ -151,33 +144,67 @@ open class Snapshot: NSObject { waitForLoadingIndicatorToDisappear(within: timeout) } - print("snapshot: \(name)") // more information about this, check out https://docs.fastlane.tools/actions/snapshot/#how-does-it-work + NSLog("snapshot: \(name)") // more information about this, check out https://docs.fastlane.tools/actions/snapshot/#how-does-it-work - sleep(1) // Waiting for the animation to be finished (kind of) + if Snapshot.waitForAnimations { + sleep(1) // Waiting for the animation to be finished (kind of) + } #if os(OSX) guard let app = self.app else { - print("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") + NSLog("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") return } app.typeKey(XCUIKeyboardKeySecondaryFn, modifierFlags: []) #else - - guard let app = self.app else { - print("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") + + guard self.app != nil else { + NSLog("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") return } - - let window = app.windows.firstMatch - let screenshot = window.screenshot() - guard let simulator = ProcessInfo().environment["SIMULATOR_DEVICE_NAME"], let screenshotsDir = screenshotsDirectory else { return } - let path = screenshotsDir.appendingPathComponent("\(simulator)-\(name).png") + + let screenshot = XCUIScreen.main.screenshot() + #if os(iOS) && !targetEnvironment(macCatalyst) + let image = XCUIDevice.shared.orientation.isLandscape ? fixLandscapeOrientation(image: screenshot.image) : screenshot.image + #else + let image = screenshot.image + #endif + + guard var simulator = ProcessInfo().environment["SIMULATOR_DEVICE_NAME"], let screenshotsDir = screenshotsDirectory else { return } + do { - try screenshot.pngRepresentation.write(to: path) + // The simulator name contains "Clone X of " inside the screenshot file when running parallelized UI Tests on concurrent devices + let regex = try NSRegularExpression(pattern: "Clone [0-9]+ of ") + let range = NSRange(location: 0, length: simulator.count) + simulator = regex.stringByReplacingMatches(in: simulator, range: range, withTemplate: "") + + let path = screenshotsDir.appendingPathComponent("\(simulator)-\(name).png") + #if swift(<5.0) + UIImagePNGRepresentation(image)?.write(to: path, options: .atomic) + #else + try image.pngData()?.write(to: path, options: .atomic) + #endif } catch let error { - print("Problem writing screenshot: \(name) to \(path)") - print(error) + NSLog("Problem writing screenshot: \(name) to \(screenshotsDir)/\(simulator)-\(name).png") + NSLog(error.localizedDescription) + } + #endif + } + + class func fixLandscapeOrientation(image: UIImage) -> UIImage { + #if os(watchOS) + return image + #else + if #available(iOS 10.0, *) { + let format = UIGraphicsImageRendererFormat() + format.scale = image.scale + let renderer = UIGraphicsImageRenderer(size: image.size, format: format) + return renderer.image { context in + image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)) + } + } else { + return image } #endif } @@ -188,7 +215,7 @@ open class Snapshot: NSObject { #endif guard let app = self.app else { - print("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") + NSLog("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") return } @@ -197,40 +224,28 @@ open class Snapshot: NSObject { _ = XCTWaiter.wait(for: [networkLoadingIndicatorDisappeared], timeout: timeout) } - class func pathPrefix() throws -> URL? { - let homeDir: URL + class func getCacheDirectory() throws -> URL { + let cachePath = "Library/Caches/tools.fastlane" // on OSX config is stored in /Users//Library // and on iOS/tvOS/WatchOS it's in simulator's home dir #if os(OSX) - guard let user = ProcessInfo().environment["USER"] else { - throw SnapshotError.cannotDetectUser + let homeDir = URL(fileURLWithPath: NSHomeDirectory()) + return homeDir.appendingPathComponent(cachePath) + #elseif arch(i386) || arch(x86_64) || arch(arm64) + guard let simulatorHostHome = ProcessInfo().environment["SIMULATOR_HOST_HOME"] else { + throw SnapshotError.cannotFindSimulatorHomeDirectory } - - guard let usersDir = FileManager.default.urls(for: .userDirectory, in: .localDomainMask).first else { - throw SnapshotError.cannotFindHomeDirectory - } - - homeDir = usersDir.appendingPathComponent(user) + let homeDir = URL(fileURLWithPath: simulatorHostHome) + return homeDir.appendingPathComponent(cachePath) #else - #if arch(i386) || arch(x86_64) - guard let simulatorHostHome = ProcessInfo().environment["SIMULATOR_HOST_HOME"] else { - throw SnapshotError.cannotFindSimulatorHomeDirectory - } - guard let homeDirUrl = URL(string: simulatorHostHome) else { - throw SnapshotError.cannotAccessSimulatorHomeDirectory(simulatorHostHome) - } - homeDir = URL(fileURLWithPath: homeDirUrl.path) - #else - throw SnapshotError.cannotRunOnPhysicalDevice - #endif + throw SnapshotError.cannotRunOnPhysicalDevice #endif - return homeDir.appendingPathComponent("Library/Caches/tools.fastlane") } } private extension XCUIElementAttributes { var isNetworkLoadingIndicator: Bool { - if hasWhiteListedIdentifier { return false } + if hasAllowListedIdentifier { return false } let hasOldLoadingIndicatorSize = frame.size == CGSize(width: 10, height: 20) let hasNewLoadingIndicatorSize = frame.size.width.isBetween(46, and: 47) && frame.size.height.isBetween(2, and: 3) @@ -238,10 +253,10 @@ private extension XCUIElementAttributes { return hasOldLoadingIndicatorSize || hasNewLoadingIndicatorSize } - var hasWhiteListedIdentifier: Bool { - let whiteListedIdentifiers = ["GeofenceLocationTrackingOn", "StandardLocationTrackingOn"] + var hasAllowListedIdentifier: Bool { + let allowListedIdentifiers = ["GeofenceLocationTrackingOn", "StandardLocationTrackingOn"] - return whiteListedIdentifiers.contains(identifier) + return allowListedIdentifiers.contains(identifier) } func isStatusBar(_ deviceWidth: CGFloat) -> Bool { @@ -291,4 +306,4 @@ private extension CGFloat { // Please don't remove the lines below // They are used to detect outdated configuration files -// SnapshotHelperVersion [1.14] +// SnapshotHelperVersion [1.28] diff --git a/build-scripts/BUILD b/build-scripts/BUILD index 565f1b06a..f71beab75 100644 --- a/build-scripts/BUILD +++ b/build-scripts/BUILD @@ -1 +1 @@ -231 \ No newline at end of file +237 \ No newline at end of file diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 37d4db6b0..8a8772ff6 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -120,7 +120,7 @@ platform :ios do skip_open_summary: true, clean: true, derived_data_path: "./build", - devices: ["iPhone X", "iPhone 6 Plus", "iPhone Xs Max"], + devices: ["iPhone X", "iPhone 6s Plus", "iPhone 13 Pro Max"], ios_version: "12.2", launch_arguments: ["-bigphone YES"] )