snapshot/lib/assets/SnapshotHelper.swift in fastlane-2.158.0 vs snapshot/lib/assets/SnapshotHelper.swift in fastlane-2.159.0

- old
+ new

@@ -163,27 +163,42 @@ NSLog("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().") return } let screenshot = XCUIScreen.main.screenshot() + let image = XCUIDevice.shared.orientation.isLandscape ? fixLandscapeOrientation(image: screenshot.image) : screenshot.image + guard var simulator = ProcessInfo().environment["SIMULATOR_DEVICE_NAME"], let screenshotsDir = screenshotsDirectory else { return } do { // 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") - try screenshot.pngRepresentation.write(to: path) + try image.pngData()?.write(to: path, options: .atomic) } catch let error { NSLog("Problem writing screenshot: \(name) to \(screenshotsDir)/\(simulator)-\(name).png") NSLog(error.localizedDescription) } #endif } + class func fixLandscapeOrientation(image: UIImage) -> UIImage { + 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 + } + } + class func waitForLoadingIndicatorToDisappear(within timeout: TimeInterval) { #if os(tvOS) return #endif @@ -277,6 +292,6 @@ } } // Please don't remove the lines below // They are used to detect outdated configuration files -// SnapshotHelperVersion [1.23] +// SnapshotHelperVersion [1.24]