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

[auick_action_ios] Retries multiple times to not fail ci when there is a flake #3823

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Changes from 2 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
@@ -5,6 +5,9 @@
import XCTest

private let elementWaitingTime: TimeInterval = 30
private let quickActionPressDuration: TimeInterval = 1.5
// Max number of tries to open the quick action menu if failed.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add a short explanation why we need to retry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

private let quickActionMaxRetries: Int = 3;

class RunnerUITests: XCTestCase {

@@ -31,16 +34,23 @@ class RunnerUITests: XCTestCase {
)
}

quickActionsAppIcon.press(forDuration: 2)

let actionTwo = springboard.buttons["Action two"]
if !actionTwo.waitForExistence(timeout: elementWaitingTime) {
var actionTwo: XCUIElement?
for _ in 1...quickActionMaxRetries {
quickActionsAppIcon.press(forDuration: quickActionPressDuration)
actionTwo = springboard.buttons["Action two"]
if actionTwo!.waitForExistence(timeout: elementWaitingTime) {
break
}
// Reset to previous state.
XCUIDevice.shared.press(XCUIDevice.Button.home)
}
if (!actionTwo!.exists) {
XCTFail(
"Failed due to not able to find the actionTwo button from springboard with \(elementWaitingTime) seconds. Springboard debug description: \(springboard.debugDescription)"
)
}

actionTwo.tap()
actionTwo!.tap()

let actionTwoConfirmation = exampleApp.otherElements["action_two"]
if !actionTwoConfirmation.waitForExistence(timeout: elementWaitingTime) {
@@ -73,16 +83,23 @@ class RunnerUITests: XCTestCase {
)
}

quickActionsAppIcon.press(forDuration: 2)

let actionOne = springboard.buttons["Action one"]
if !actionOne.waitForExistence(timeout: elementWaitingTime) {
var actionOne: XCUIElement?
for _ in 1...quickActionMaxRetries {
Copy link
Contributor

Choose a reason for hiding this comment

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

may wanna write a helper function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

quickActionsAppIcon.press(forDuration: quickActionPressDuration)
actionOne = springboard.buttons["Action one"]
if actionOne!.waitForExistence(timeout: elementWaitingTime) {
break
}
// Reset to previous state.
XCUIDevice.shared.press(XCUIDevice.Button.home)
}
if (!actionOne!.exists) {
XCTFail(
"Failed due to not able to find the actionOne button from springboard with \(elementWaitingTime) seconds. Springboard debug description: \(springboard.debugDescription)"
)
}

actionOne.tap()
actionOne!.tap()

let actionOneConfirmation = exampleApp.otherElements["action_one"]
if !actionOneConfirmation.waitForExistence(timeout: elementWaitingTime) {