tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 80ba593230e71c860024cfe194dfa2558cad63c6
parent ebe39ce25dd14075927210472e485c6e87085b5d
Author: AndiAJ <andiaj@users.noreply.github.com>
Date:   Wed,  1 Oct 2025 15:33:32 +0000

Bug 1982537 - Fix shareDownloadedFileTest UI test r=aaronmt

The UI test was flaky when trying to expand the share overlay and click the "Gmail" app.

To fix the problem I switched from using UIObject to UIObject2 to perform the swipe action.

The UI test successfully passed 50x on Firebase ✅

Differential Revision: https://phabricator.services.mozilla.com/D266819

Diffstat:
Mmobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt | 2+-
Mmobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt | 50+++++++++++++++++++++++++++-----------------------
2 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt @@ -434,7 +434,7 @@ class DownloadTest : TestSetup() { verifyDownloadedFileExistsInDownloadsList(activityTestRule, "web_icon.png") clickDownloadItemMenuIcon(activityTestRule, "web_icon.png") }.shareDownloadedItem(activityTestRule, "web_icon.png") { - verifyAndroidShareLayout() + expandAndroidShareLayout("Gmail") clickSharingApp("Gmail", GMAIL_APP) assertNativeAppOpens(GMAIL_APP) } diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt @@ -17,6 +17,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.uiautomator.By +import androidx.test.uiautomator.Direction import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.Until import org.hamcrest.Matchers.allOf @@ -96,11 +97,28 @@ class ShareOverlayRobot { mDevice.waitNotNull(Until.findObject(By.res("android:id/resolver_list"))) } - fun expandAndroidShareLayout() { - Log.i(TAG, "verifySharingWithSelectedApp: Trying to expand the Android share layout") - itemWithResId("android:id/resolver_list").swipeUp(3) - Log.i(TAG, "verifySharingWithSelectedApp: Expanded the Android share layout") - waitForAppWindowToBeUpdated() + fun expandAndroidShareLayout(appName: String) { + for (i in 1..RETRY_COUNT) { + Log.i(TAG, "expandAndroidShareLayout: Started try #$i") + try { + assertUIObjectExists(itemWithResId("android:id/chooser_header")) + Log.i(TAG, "expandAndroidShareLayout: Trying to expand the Android share layout") + mDevice.findObject(By.res("android:id/chooser_header")).swipe(Direction.UP, 1.0f, 500) + Log.i(TAG, "expandAndroidShareLayout: Expanded the Android share layout") + assertUIObjectExists(itemContainingText(appName)) + + break + } catch (e: AssertionError) { + Log.i(TAG, "expandAndroidShareLayout: AssertionError caught, executing fallback methods") + if (i == RETRY_COUNT) { + throw e + } else { + Log.i(TAG, "expandAndroidShareLayout: Waiting for $waitingTime for device to be idle") + mDevice.waitForIdle(waitingTime) + Log.i(TAG, "expandAndroidShareLayout: Waited for $waitingTime for device to be idle") + } + } + } } fun verifySharingWithSelectedApp(appName: String, content: String, subject: String) { @@ -157,26 +175,12 @@ class ShareOverlayRobot { } fun clickSharingApp(appName: String, appPackageName: String) { - for (i in 1..RETRY_COUNT) { - Log.i(TAG, "clickSharingApp: Started try #$i") val sharingApp = itemContainingText(appName) if (isPackageInstalled(appPackageName)) { - try { - assertUIObjectExists(sharingApp) - Log.i(TAG, "clickSharingApp: Trying to click sharing app: $appName and wait for a new window") - sharingApp.clickAndWaitForNewWindow() - Log.i(TAG, "clickSharingApp: Clicked sharing app: $appName and waited for a new window") - - break - } catch (e: AssertionError) { - Log.i(TAG, "clickSharingApp: AssertionError caught, executing fallback methods") - if (i == RETRY_COUNT) { - throw e - } else { - expandAndroidShareLayout() - } - } - } + assertUIObjectExists(sharingApp) + Log.i(TAG, "clickSharingApp: Trying to click sharing app: $appName and wait for a new window") + sharingApp.clickAndWaitForNewWindow() + Log.i(TAG, "clickSharingApp: Clicked sharing app: $appName and waited for a new window") } }