Skip to content

Commit

Permalink
Fixed screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
tladesignz committed Feb 28, 2024
1 parent 616aa3c commit 2d31582
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
19 changes: 10 additions & 9 deletions Screenshots/Screenshots.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Screenshots: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testScreenshots() throws {
@MainActor
func testScreenshots() throws {

// UI tests must launch the application that they test.
let app = XCUIApplication()
Expand Down Expand Up @@ -55,14 +56,14 @@ class Screenshots: XCTestCase {

app.buttons["close_auth_cookies"].tap()

app.buttons["bridge_configuration"].tap()

snapshot("4-Bridge-Configuration")

app.tables.cells["transport_custom"].tap()
app.tables.cells["next_button"].tap()

snapshot("5-Custom-Bridges")
// app.buttons["bridge_configuration"].tap()
//
// snapshot("4-Bridge-Configuration")
//
// app.tables.cells["transport_custom"].tap()
// app.tables.cells["next_button"].tap()
//
// snapshot("5-Custom-Bridges")

// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
Expand Down
10 changes: 5 additions & 5 deletions fastlane/Snapfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# A list of devices you want to take the screenshots from
devices([
"iPhone 14 Pro Max @ iOS 16",
"iPhone 11 Pro Max @ iOS 16",
"iPhone 8+ @ iOS 16",
"iPad Pro (12.9-inch) (3rd generation) @ iOS 16",
"iPad Pro 12.9\" 2gen @ iOS 16",
"iPhone 15 Pro Max @ iOS 17.2",
"iPhone 11 Pro Max @ iOS 17.2",
"iPhone 8+ @ iOS 15.5",
"iPad Pro 12.9\" 6gen @ iOS 17.2",
"iPad Pro 12.9\" 2gen @ iOS 17.2",
])

languages([
Expand Down
22 changes: 13 additions & 9 deletions fastlane/SnapshotHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import Foundation
import XCTest

var deviceLanguage = ""
var locale = ""

@MainActor
func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) {
Snapshot.setupSnapshot(app, waitForAnimations: waitForAnimations)
}

@MainActor
func snapshot(_ name: String, waitForLoadingIndicator: Bool) {
if waitForLoadingIndicator {
Snapshot.snapshot(name)
Expand All @@ -33,6 +32,7 @@ func snapshot(_ name: String, waitForLoadingIndicator: Bool) {
/// - Parameters:
/// - name: The name of the snapshot
/// - timeout: Amount of seconds to wait until the network loading indicator disappears. Pass `0` if you don't want to wait.
@MainActor
func snapshot(_ name: String, timeWaitingForIdle timeout: TimeInterval = 20) {
Snapshot.snapshot(name, timeWaitingForIdle: timeout)
}
Expand All @@ -52,13 +52,16 @@ enum SnapshotError: Error, CustomDebugStringConvertible {
}

@objcMembers
@MainActor
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)
}
static var deviceLanguage = ""
static var currentLocale = ""

open class func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) {

Expand Down Expand Up @@ -103,17 +106,17 @@ open class Snapshot: NSObject {

do {
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
locale = try String(contentsOf: path, encoding: .utf8).trimmingCharacters(in: trimCharacterSet)
currentLocale = try String(contentsOf: path, encoding: .utf8).trimmingCharacters(in: trimCharacterSet)
} catch {
NSLog("Couldn't detect/set locale...")
}

if locale.isEmpty && !deviceLanguage.isEmpty {
locale = Locale(identifier: deviceLanguage).identifier
if currentLocale.isEmpty && !deviceLanguage.isEmpty {
currentLocale = Locale(identifier: deviceLanguage).identifier
}

if !locale.isEmpty {
app.launchArguments += ["-AppleLocale", "\"\(locale)\""]
if !currentLocale.isEmpty {
app.launchArguments += ["-AppleLocale", "\"\(currentLocale)\""]
}
}

Expand Down Expand Up @@ -281,6 +284,7 @@ private extension XCUIElementQuery {
return self.containing(isNetworkLoadingIndicator)
}

@MainActor
var deviceStatusBars: XCUIElementQuery {
guard let app = Snapshot.app else {
fatalError("XCUIApplication is not set. Please call setupSnapshot(app) before snapshot().")
Expand All @@ -306,4 +310,4 @@ private extension CGFloat {

// Please don't remove the lines below
// They are used to detect outdated configuration files
// SnapshotHelperVersion [1.29]
// SnapshotHelperVersion [1.30]

0 comments on commit 2d31582

Please sign in to comment.