diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/DownloadRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/DownloadRobot.kt index 5687dcb7cc14..61e82ddab308 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/DownloadRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/DownloadRobot.kt @@ -133,16 +133,29 @@ fun downloadRobot(interact: DownloadRobot.() -> Unit): DownloadRobot.Transition } private fun assertDownloadPrompt(fileName: String) { - assertTrue( - "Download prompt button not visible", - mDevice.findObject(UiSelector().resourceId("$packageName:id/download_button")) - .waitForExists(waitingTime) - ) - assertTrue( - "$fileName title doesn't match", - mDevice.findObject(UiSelector().text(fileName)) - .waitForExists(waitingTime) - ) + var currentTries = 0 + while (currentTries++ < 3) { + try { + assertTrue( + "Download prompt button not visible", + mDevice.findObject(UiSelector().resourceId("$packageName:id/download_button")) + .waitForExists(waitingTime) + ) + assertTrue( + "$fileName title doesn't match", + mDevice.findObject(UiSelector().text(fileName)) + .waitForExists(waitingTime) + ) + + break + } catch (e: AssertionError) { + println("Failed to find locator: ${e.localizedMessage}") + + browserScreen { + }.clickDownloadLink(fileName) { + } + } + } } private fun assertDownloadNotificationPopup() {