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):