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

Fix UI tests #249

Merged
merged 14 commits into from
May 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -18,37 +18,36 @@ 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")!!
context.startActivity(intent)
}

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
}
}

Expand All @@ -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) {
Expand Down
19 changes: 11 additions & 8 deletions scripts/run_ui_tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down