From 8216fc91d1435ff99626c2a2a696f129cb1cfc71 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Sun, 16 Aug 2026 17:39:34 +0200 Subject: [PATCH] fix(appium-tests): stop waiting 50s for a USB dialog Android never shows Android often grants USB permission silently, so waiting out the dialog timeout on every attempt burned ~150s per test on CI and left the confirmation screen in a state where the next tap was dropped, so the job never started at all. Keep the retry, but make the dialog wait short: the grant button disappearing is the real signal that permission landed, however it was granted. Verify the 'write image' tap took as well, by waiting for what must follow it -- the lay-flat sheet, or the progress screen when the sheet auto-proceeds on a device with a working gravity sensor. --- appium-tests/etchdroid/actions.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/appium-tests/etchdroid/actions.py b/appium-tests/etchdroid/actions.py index 9a9c02d..84eabd6 100644 --- a/appium-tests/etchdroid/actions.py +++ b/appium-tests/etchdroid/actions.py @@ -51,17 +51,17 @@ def select_first_usb_device_if_multiple(driver: Remote, timeout: int = 1): def grant_usb_permission(driver: Remote): # The tap is swallowed if it lands while the confirmation activity is still settling, - # and then nothing requests permission at all: retry until the system dialog shows or - # the grant button is gone (permission already granted, so no dialog is coming). + # and then nothing requests permission at all. Retry, but keep the dialog wait short: + # Android often grants silently, and then no dialog is ever coming. The grant button + # disappearing is the signal that permission landed, however it was granted. for _ in range(3): try: - grant_btn = wait_for_element(driver, '//*[@resource-id="grantUsbPermissionButton"]') + grant_btn = wait_for_element(driver, '//*[@resource-id="grantUsbPermissionButton"]', timeout=2) except TimeoutException: return try: grant_btn.click() - # The system dialog can take several seconds to render on a cold guest. - accept_usb_permission(driver, timeout=10) + accept_usb_permission(driver, timeout=2) return except (TimeoutException, StaleElementReferenceException): continue @@ -73,8 +73,22 @@ def accept_usb_permission(driver: Remote, timeout: float = 1): def confirm_write_image(driver: Remote): - write_image_btn = wait_for_element(driver, '//*[@resource-id="writeImageButton"]') - write_image_btn.click() + # Like the other taps on this screen, this one can be swallowed while the UI settles. + # Confirm it took by waiting for what must follow: the lay-flat sheet, or the progress + # screen when the sheet auto-proceeds (a device with a working gravity sensor). + for _ in range(3): + write_image_btn = wait_for_element(driver, '//*[@resource-id="writeImageButton"]') + try: + write_image_btn.click() + wait_for_element( + driver, + '//android.widget.TextView[@resource-id="layFlatSkipButton"] | ' + '//android.widget.TextView[@resource-id="write_progress_title"]', + timeout=5, + ) + return + except (TimeoutException, StaleElementReferenceException): + continue def skip_lay_flat_sheet(driver: Remote):