Skip to content

Commit

Permalink
Fix Device Tests (#59)
Browse files Browse the repository at this point in the history
* Use Xcode 16.1 on CI

Xcode 16.0 was removed from the macos-14 image: actions/runner-images#11203

16.2 is still rolling out so let's use 16.1 for now.

* Use simple existence checks in webviews
  • Loading branch information
dcaunt authored Jan 7, 2025
1 parent dd7c67c commit a41a3e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
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

0 comments on commit a41a3e0

Please sign in to comment.