Skip to content
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

Fix Device Tests #59

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/device-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
path: ${{ inputs.working-directory }}
token: ${{ secrets.CHECKOUT_TOKEN || github.token }}

- name: Select Xcode 16.0
run: sudo xcode-select -s /Applications/Xcode_16.app
- name: Select Xcode 16.1
run: sudo xcode-select -s /Applications/Xcode_16.1.app

- name: Authenticate using GitHub App
id: auth
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ jobs:
- name: Install dependencies
run: brew install swiftlint

- name: Select Xcode 16.0
run: sudo xcode-select -s /Applications/Xcode_16.0.app
- name: Select Xcode 16.1
run: sudo xcode-select -s /Applications/Xcode_16.1.app

- name: Run unit tests on iOS
run: xcodebuild test -scheme OpenPass -destination "OS=18.0,name=iPhone 15"
run: xcodebuild test -scheme OpenPass -destination "OS=18.1,name=iPhone 15"

- name: Run ObjC unit tests on iOS
run: xcodebuild test -scheme OpenPassObjC -destination "OS=18.0,name=iPhone 15"
run: xcodebuild test -scheme OpenPassObjC -destination "OS=18.1,name=iPhone 15"

- name: Run unit tests on tvOS
run: xcodebuild test -scheme OpenPass -destination "OS=18.0,name=Apple TV"
run: xcodebuild test -scheme OpenPass -destination "OS=18.1,name=Apple TV"

- name: Run ObjC unit tests on tvOS
run: xcodebuild test -scheme OpenPassObjC -destination "OS=18.0,name=Apple TV"
run: xcodebuild test -scheme OpenPassObjC -destination "OS=18.1,name=Apple TV"

- name: Lint code
run: swiftlint lint --config .swiftlint.yml --strict --reporter github-actions-logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ struct WaitError: Error, LocalizedError {
}
}

extension XCUIElement {
/// A convenience for waiting for an element to exist and then performing an action with the element.
func waitForExistence(
timeout: TimeInterval = webViewTimeout,
action: (_ element: XCUIElement) -> Void = { _ in }
) throws {
guard waitForExistence(timeout: timeout) else {
throw WaitError(message: "Element did not come to exist \(self.debugDescription)")
}
action(self)
}
}

extension XCUIElement {
/// A convenience for waiting for the element's `exists` property to be true.
@discardableResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ final class OpenPassDevelopmentAppUITests: XCTestCase {

guard app.wait(for: .runningForeground, timeout: webViewTimeout) else {
throw UITestError("App did not return to foreground")
return
}
}

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

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

// Click Continue
try signInView.emailInputContinue.waitForExistsInteractive {
try signInView.emailInputContinue.waitForExistence {
$0.tap()
}

Expand All @@ -174,7 +173,7 @@ final class OpenPassDevelopmentAppUITests: XCTestCase {
}

// ...and enter it into the OTP text boxes, ensuring the webView is loaded
try signInView.codeInput.waitForExistsInteractive(timeout: webViewTimeout) { _ in
try signInView.codeInput.waitForExistence { _ in
signInView.enterCode(code)
}
}
Expand Down