Skip to content

test: fix View UI tests that require more time for sign-in to occur #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
}

@MainActor
func testSignInDisplaysSignedInView() async throws {
func testSignInDisplaysSignedInView() throws {
let app = XCUIApplication()
let email = createEmail()
app.launchArguments.append("--auth-emulator")
Expand All @@ -81,10 +81,23 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
signInButton.tap()

let signedInText = app.staticTexts["signed-in-text"]
XCTAssertTrue(
signedInText.waitForExistence(timeout: 10),
"SignedInView should be visible after login"
)

let expectation = XCTestExpectation(description: "Wait for SignedInView to appear")

let checkInterval: TimeInterval = 1
let maxWaitTime: TimeInterval = 30

Timer.scheduledTimer(withTimeInterval: checkInterval, repeats: true) { timer in
DispatchQueue.main.async {
if signedInText.exists {
expectation.fulfill()
timer.invalidate()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use waitForExpectations instead.


wait(for: [expectation], timeout: maxWaitTime)
XCTAssertTrue(signedInText.exists, "SignedInView should be visible after login")

dismissAlert(app: app)
// Check the Views are updated
Expand Down Expand Up @@ -177,9 +190,22 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
signInButton.tap()

let signedInText = app.staticTexts["signed-in-text"]
XCTAssertTrue(
signedInText.waitForExistence(timeout: 20),
"SignedInView should be visible after login"
)

let expectation = XCTestExpectation(description: "Wait for SignedInView to appear")

let checkInterval: TimeInterval = 1
let maxWaitTime: TimeInterval = 30

Timer.scheduledTimer(withTimeInterval: checkInterval, repeats: true) { timer in
DispatchQueue.main.async {
if signedInText.exists {
expectation.fulfill()
timer.invalidate()
}
}
}

wait(for: [expectation], timeout: maxWaitTime)
XCTAssertTrue(signedInText.exists, "SignedInView should be visible after login")
}
}
Loading