From 294e168b3a03ccead5e4c62a75caf136363aab8c Mon Sep 17 00:00:00 2001 From: Michael Troger <11340859+michaeltroger@users.noreply.github.com> Date: Wed, 1 May 2024 12:25:58 +0200 Subject: [PATCH] Try to fix test --- .../gruenerpass/robots/AndroidFileAppRobot.kt | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/app/src/androidTest/java/com/michaeltroger/gruenerpass/robots/AndroidFileAppRobot.kt b/app/src/androidTest/java/com/michaeltroger/gruenerpass/robots/AndroidFileAppRobot.kt index 7f851dd2..4a62a1cc 100644 --- a/app/src/androidTest/java/com/michaeltroger/gruenerpass/robots/AndroidFileAppRobot.kt +++ b/app/src/androidTest/java/com/michaeltroger/gruenerpass/robots/AndroidFileAppRobot.kt @@ -55,6 +55,7 @@ class AndroidFileAppRobot { fun openPdf(fileName: String): MainActivityRobot { selectFile(fileName = fileName, longClick = false) + uiDevice.wait(Until.hasObject(greenPassSelector), TIMEOUT) return MainActivityRobot() } @@ -73,26 +74,16 @@ class AndroidFileAppRobot { val uiScrollable = UiScrollable(UiSelector().scrollable(true)) val selector = By.text(fileName) - (1..RETRIALS).forEach { _ -> - try { - if (uiDevice.hasObject(greenPassSelector)) { - return - } - - uiScrollable.scrollTextIntoView(fileName) - - uiDevice.wait(Until.hasObject(selector), TIMEOUT) - - if (longClick) { - uiDevice.findObject(selector).longClick() - } else { - uiDevice.findObject(selector).click() - } + uiDevice.wait(Until.hasObject(selector), TIMEOUT) + if (!uiDevice.hasObject(selector)) { + uiScrollable.scrollForward(1) + uiDevice.wait(Until.hasObject(selector), TIMEOUT) + } - uiDevice.wait(Until.hasObject(greenPassSelector), TIMEOUT) - } catch (e: NullPointerException) { - //ignoring - } + if (longClick) { + uiDevice.findObject(selector).longClick() + } else { + uiDevice.findObject(selector).click() } }