Skip to content

Commit 4ec06eb

Browse files
committed
Use simple existence checks in webviews
1 parent 7c84799 commit 4ec06eb

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Development/OpenPassDevelopmentAppUITests/Helpers/TestHelpers.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ struct WaitError: Error, LocalizedError {
7777
}
7878
}
7979

80+
extension XCUIElement {
81+
/// A convenience for waiting for an element to exist and then performing an action with the element.
82+
func waitForExistence(
83+
timeout: TimeInterval = webViewTimeout,
84+
action: (_ element: XCUIElement) -> Void = { _ in }
85+
) throws {
86+
if waitForExistence(timeout: timeout) {
87+
action(self)
88+
}
89+
throw WaitError(message: "Element did not come to exist \(self.debugDescription)")
90+
}
91+
}
92+
8093
extension XCUIElement {
8194
/// A convenience for waiting for the element's `exists` property to be true.
8295
@discardableResult

Development/OpenPassDevelopmentAppUITests/OpenPassDevelopmentAppUITests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ final class OpenPassDevelopmentAppUITests: XCTestCase {
9191

9292
guard app.wait(for: .runningForeground, timeout: webViewTimeout) else {
9393
throw UITestError("App did not return to foreground")
94-
return
9594
}
9695
}
9796

@@ -148,23 +147,23 @@ final class OpenPassDevelopmentAppUITests: XCTestCase {
148147
func signIn(view signInView: SignInView, client: MailSlurpClient, inbox: InboxDto) async throws {
149148
// Ensure the webView is loaded
150149
do {
151-
try signInView.emailInput.waitForExists(timeout: webViewTimeout)
150+
try signInView.emailInput.waitForExistence()
152151
} catch {
153152
// If the email address input does not exist, then it's likely that Chrome already has a previous
154153
// login session active. We need to click the "Use another email" to clear out the old session
155154
signInView.signInWithAnotherEmail.tap()
156155
}
157156

158157
// Ensure the webView is loaded
159-
try signInView.emailInput.waitForExistsInteractive(timeout: webViewTimeout) {
158+
try signInView.emailInput.waitForExistence {
160159
// Now enter the email address of the MailSlurp inbox into the text input
161160
// On a physical device, tapping the input is required before text may be entered
162161
$0.tap()
163162
$0.typeText(inbox.emailAddress)
164163
}
165164

166165
// Click Continue
167-
try signInView.emailInputContinue.waitForExistsInteractive {
166+
try signInView.emailInputContinue.waitForExistence {
168167
$0.tap()
169168
}
170169

@@ -174,7 +173,7 @@ final class OpenPassDevelopmentAppUITests: XCTestCase {
174173
}
175174

176175
// ...and enter it into the OTP text boxes, ensuring the webView is loaded
177-
try signInView.codeInput.waitForExistsInteractive(timeout: webViewTimeout) { _ in
176+
try signInView.codeInput.waitForExistence { _ in
178177
signInView.enterCode(code)
179178
}
180179
}

0 commit comments

Comments
 (0)