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 e26029a7..a9ce1db4 100644 --- a/app/src/androidTest/java/com/michaeltroger/gruenerpass/robots/AndroidFileAppRobot.kt +++ b/app/src/androidTest/java/com/michaeltroger/gruenerpass/robots/AndroidFileAppRobot.kt @@ -8,8 +8,8 @@ import androidx.test.uiautomator.UiScrollable import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.Until -private const val RETRIALS = 3 private const val TIMEOUT = 5000L +private const val testFolder = "testdata" class AndroidFileAppRobot { @@ -18,10 +18,11 @@ class AndroidFileAppRobot { private val hamburgerSelector = By.desc("Show roots") private val rootDirSelector = By.textStartsWith("Android SDK") - private val testDataDirSelector = By.text("testdata") + private val testDataDirSelector = By.text(testFolder) private val pdfSelector = By.textEndsWith(".pdf") private val greenPassAppSelector = By.text("Green Pass") private val shareButtonSelector = By.desc("Share") + private val listViewSelector = By.desc("List view") fun openFileManagerApp() = apply { val intent: Intent = context.packageManager.getLaunchIntentForPackage("com.android.documentsui")!! @@ -29,26 +30,24 @@ class AndroidFileAppRobot { } fun goToPdfFolder() = apply { - (1..RETRIALS).forEach { _ -> - try { - uiDevice.wait(Until.hasObject(hamburgerSelector), TIMEOUT) - uiDevice.findObject(hamburgerSelector).click() - - uiDevice.wait(Until.hasObject(rootDirSelector), TIMEOUT) - uiDevice.findObject(rootDirSelector).click() - - uiDevice.wait(Until.hasObject(testDataDirSelector), TIMEOUT) - uiDevice.findObject(testDataDirSelector).click() - - uiDevice.wait(Until.hasObject(pdfSelector), TIMEOUT) - if (!uiDevice.hasObject(pdfSelector)) { - return@forEach - } - - return@apply - } catch (e: NullPointerException) { - //ignoring - } + val uiScrollable = UiScrollable(UiSelector().scrollable(true)) + try { + uiDevice.wait(Until.hasObject(hamburgerSelector), TIMEOUT) + uiDevice.findObject(hamburgerSelector).click() + + uiDevice.wait(Until.hasObject(rootDirSelector), TIMEOUT) + uiDevice.findObject(rootDirSelector).click() + + uiScrollable.scrollTextIntoView(testFolder) + uiDevice.wait(Until.hasObject(testDataDirSelector), TIMEOUT) + uiDevice.findObject(testDataDirSelector).click() + + uiDevice.wait(Until.hasObject(pdfSelector), TIMEOUT) + uiDevice.wait(Until.hasObject(testDataDirSelector), TIMEOUT) + + uiDevice.findObject(listViewSelector).click() + } catch (e: NullPointerException) { + //ignoring } } @@ -67,10 +66,12 @@ class AndroidFileAppRobot { } private fun selectFile(fileName: String, longClick: Boolean = false) { - val uiScrollable = UiScrollable(UiSelector().scrollable(true)) - uiScrollable.scrollTextIntoView(fileName) + uiDevice.wait(Until.hasObject(pdfSelector), TIMEOUT) + val uiScrollable = UiScrollable(UiSelector().scrollable(true)) val selector = By.text(fileName) + + uiScrollable.scrollTextIntoView(fileName) uiDevice.wait(Until.hasObject(selector), TIMEOUT) if (longClick) { diff --git a/scripts/run_ui_tests b/scripts/run_ui_tests index 171508ae..be729c68 100755 --- a/scripts/run_ui_tests +++ b/scripts/run_ui_tests @@ -25,22 +25,25 @@ done set +e # don't fail on errors -adb shell "screenrecord --size 1024x768 /sdcard/screen1.mp4; screenrecord --size 1024x768 /sdcard/screen2.mp4; screenrecord --size 1024x768 /sdcard/screen3.mp4; screenrecord --size 1024x768 /sdcard/screen4.mp4" & +screenRecord() { + for ((i=0;i<5;i++)) + do + adb shell screenrecord --size 1024x768 /sdcard/screen"$i".mp4 + done +} +screenRecord & ./gradlew :app:connectedDebugAndroidTest exit_code=$? -for ((n=0;n<5;n++)) +mkdir app/build/screenrecording + +for ((i=0;i<5;i++)) do adb shell kill -2 $(adb shell pidof screenrecord) + adb pull /sdcard/screen"$i".mp4 app/build/screenrecording/screen"$i".mp4 done -mkdir app/build/screenrecording -adb pull /sdcard/screen1.mp4 app/build/screenrecording/screen1.mp4 -adb pull /sdcard/screen2.mp4 app/build/screenrecording/screen2.mp4 -adb pull /sdcard/screen3.mp4 app/build/screenrecording/screen3.mp4 -adb pull /sdcard/screen4.mp4 app/build/screenrecording/screen4.mp4 - adb pull /sdcard/Pictures/error_screenshots app/build set -e # fail on errors adb pull /sdcard/Pictures/screenshots