Skip to content

Commit

Permalink
Fix flaky E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Oct 17, 2023
1 parent dd6efd1 commit 05da584
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion SwiftUIDemoAppUITests/Robots/UserRobot+Asserts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ extension UserRobot {

@discardableResult
func assertParticipantsAreVisible(count: Int) -> Self {
XCTAssertEqual(count, CallPage.participantView.waitCount(count, timeout: UserRobot.defaultTimeout).count)
XCTAssertEqual(count, CallPage.participantView.waitCount(count, timeout: UserRobot.defaultTimeout, exact: true).count)
return self
}

Expand Down
35 changes: 17 additions & 18 deletions TestTools/UITests/Safari.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ struct Safari {
func open(_ url: URL) -> Self {
safari.launch()
_ = safari.wait(for: .runningForeground, timeout: 5)
if #available(iOS 16.4, *) {
safari.open(url)
return self
} else {
// Type the deeplink and execute it
let firstLaunchContinueButton = safari.buttons["Continue"]
if firstLaunchContinueButton.exists {
firstLaunchContinueButton.tap()
}

return go(to: url)

// Type the deeplink and execute it
let firstLaunchContinueButton = safari.buttons["Continue"]
if firstLaunchContinueButton.exists {
firstLaunchContinueButton.tap()
}

return go(to: url)
}

@discardableResult
Expand All @@ -46,20 +42,23 @@ struct Safari {
if safari.alerts.count > 0 {
while safari.alerts.count > 0 {
safari.alerts.buttons["Allow"].safeTap()
sleep(UInt32(0.5))
}
}
return self
}

@discardableResult
func tapOnOpenButton(_ timeout: TimeInterval = 5) -> Self {
safari
.buttons
.matching(NSPredicate(format: "label LIKE 'OPEN' OR label LIKE 'Open'"))
.firstMatch
.wait(timeout: timeout)
.tap()

let openButton = safari.buttons.matching(NSPredicate(format: "label LIKE 'OPEN' OR label LIKE 'Open'")).firstMatch

var counter = 0
while !openButton.wait(timeout: timeout).exists || counter < 5 {
safari.buttons["ReloadButton"].tap()
counter += 1
}

openButton.tap()
return self
}
}

0 comments on commit 05da584

Please sign in to comment.