commit 9247ccd1b0b0a4e071110d0b6d9070503425be0c
parent 974d7ee3f051ed5125f7845b0c9483376df9ed57
Author: Aaron Train <aaron.train@gmail.com>
Date: Tue, 21 Oct 2025 13:54:10 +0000
Bug 1995010 - Use pressImeActionButton for more reliable IME interactions r=ajoltan
Swaps out `pressEnter` calls from UIDevice to a more reliable `pressImeActionButton` on submit query calls.
Try: https://treeherder.mozilla.org/jobs?revision=64e051257acfd121f6ab46cca6e72248b6c807b9&repo=try&selectedTaskRun=fkjIjGCMRsWdctF1BEnHuw.0 (intermittent on second run)
Differential Revision: https://phabricator.services.mozilla.com/D269263
Diffstat:
2 files changed, 62 insertions(+), 18 deletions(-)
diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt
@@ -21,9 +21,11 @@ import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.recyclerview.widget.RecyclerView
+import androidx.test.espresso.AppNotIdleException
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.longClick
+import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.PositionAssertions.isCompletelyAbove
import androidx.test.espresso.assertion.PositionAssertions.isPartiallyBelow
@@ -60,6 +62,7 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
+import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.waitForObjects
@@ -316,7 +319,7 @@ class NavigationToolbarRobot {
awesomeBar().setText(url.toString())
Log.i(TAG, "enterURLAndEnterToBrowser: Toolbar text was set to: $url")
Log.i(TAG, "enterURLAndEnterToBrowser: Trying to press device enter button")
- mDevice.pressEnter()
+ pressImeActionOnAwesomeBar()
Log.i(TAG, "enterURLAndEnterToBrowser: Pressed device enter button")
registerAndCleanupIdlingResources(sessionLoadedIdlingResource) {
@@ -341,12 +344,11 @@ class NavigationToolbarRobot {
Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Trying to click navigation toolbar")
composeTestRule.onAllNodesWithTag(ADDRESSBAR_URL_BOX).onLast().performClick()
Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Clicked navigation toolbar")
- Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Trying to set toolbar text to: $url")
- onView(withId(composeToolbarR.id.mozac_addressbar_search_query_input)).perform(replaceText(url.toString()))
- Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Toolbar text was set to: $url")
- Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Trying to press device enter button")
- mDevice.pressEnter()
- Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Pressed device enter button")
+ Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Trying to set toolbar text to: $url and perform IME action")
+ onView(withId(composeToolbarR.id.mozac_addressbar_search_query_input)).perform(
+ replaceText(url.toString()), pressImeActionButton(),
+ )
+ Log.i(TAG, "enterURLAndEnterToBrowserWithComposableToolbar: Toolbar text was set to: $url and IME action performed")
BrowserRobot().interact()
return BrowserRobot.Transition()
@@ -363,7 +365,7 @@ class NavigationToolbarRobot {
awesomeBar().setText(url.toString())
Log.i(TAG, "enterURLAndEnterToBrowser: Toolbar text was set to: $url")
Log.i(TAG, "enterURLAndEnterToBrowser: Trying to press device enter button")
- mDevice.pressEnter()
+ pressImeActionOnAwesomeBar()
Log.i(TAG, "enterURLAndEnterToBrowser: Pressed device enter button")
BrowserRobot().interact()
@@ -380,7 +382,7 @@ class NavigationToolbarRobot {
awesomeBar().setText(crashUrl)
Log.i(TAG, "openTabCrashReporter: Toolbar text was set to: $crashUrl")
Log.i(TAG, "openTabCrashReporter: Trying to press device enter button")
- mDevice.pressEnter()
+ pressImeActionOnAwesomeBar()
Log.i(TAG, "openTabCrashReporter: Pressed device enter button")
registerAndCleanupIdlingResources(sessionLoadedIdlingResource) {
@@ -667,6 +669,34 @@ private fun urlBar() = mDevice.findObject(UiSelector().resourceId("$packageName:
private fun homeUrlBar() = mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar_text"))
private fun awesomeBar() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view"))
+private fun pressImeActionOnAwesomeBar() {
+ val context = appContext
+ val resId = context.resources.getIdentifier(
+ "mozac_browser_toolbar_edit_url_view",
+ "id",
+ packageName,
+ )
+
+ try {
+ Log.i(TAG, "pressImeActionOnAwesomeBar: Trying pressImeActionButton via Espresso")
+ onView(withId(resId)).perform(pressImeActionButton())
+ Log.i(TAG, "pressImeActionOnAwesomeBar: Espresso IME action completed successfully")
+ } catch (e: AppNotIdleException) {
+ Log.w(TAG, "pressImeActionOnAwesomeBar: IME action failed (AppNotIdleException); falling back to UiAutomator pressEnter()", e)
+ try {
+ val field = awesomeBar()
+ if (field.exists()) {
+ field.click()
+ mDevice.pressEnter()
+ Log.i(TAG, "pressImeActionOnAwesomeBar: Fallback UiAutomator pressEnter() executed successfully")
+ } else {
+ Log.w(TAG, "pressImeActionOnAwesomeBar: Fallback failed: awesomeBar() not found")
+ }
+ } catch (fallbackEx: Exception) {
+ Log.e(TAG, "pressImeActionOnAwesomeBar: Fallback UiAutomator pressEnter() failed", fallbackEx)
+ }
+ }
+}
private fun threeDotButton() = onView(withId(toolbarR.id.mozac_browser_toolbar_menu))
private fun tabTrayButton() = onView(withId(R.id.tab_button))
private fun tabsCounter() = onView(
diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt
@@ -24,6 +24,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.PositionAssertions
import androidx.test.espresso.intent.Intents
@@ -56,6 +57,7 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
+import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
@@ -597,7 +599,7 @@ class SearchRobot {
browserToolbarEditView().setText("mozilla\n")
Log.i(TAG, "openBrowser: Edit mode toolbar text was set to: mozilla")
Log.i(TAG, "openBrowser: Trying to click device enter button")
- mDevice.pressEnter()
+ pressImeActionOnToolbarEditView()
Log.i(TAG, "openBrowser: Clicked device enter button")
BrowserRobot().interact()
@@ -611,7 +613,7 @@ class SearchRobot {
browserToolbarEditView().setText(query)
Log.i(TAG, "submitQuery: Edit mode toolbar text was set to: $query")
Log.i(TAG, "submitQuery: Trying to click device enter button")
- mDevice.pressEnter()
+ pressImeActionOnToolbarEditView()
Log.i(TAG, "submitQuery: Clicked device enter button")
registerAndCleanupIdlingResources(sessionLoadedIdlingResource) {
@@ -623,13 +625,11 @@ class SearchRobot {
}
fun submitQueryWithComposableToolbar(query: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
- Log.i(TAG, "submitQueryWithComposableToolbar: Trying to set toolbar text to: $query")
- onView(withId(composeToolbarR.id.mozac_addressbar_search_query_input)).perform(replaceText(query))
- Log.i(TAG, "submitQueryWithComposableToolbar: Toolbar text was set to: $query")
- Log.i(TAG, "submitQueryWithComposableToolbar: Trying to click device enter button")
- mDevice.pressEnter()
- Log.i(TAG, "submitQueryWithComposableToolbar: Clicked device enter button")
-
+ Log.i(TAG, "submitQueryWithComposableToolbar: Trying to set toolbar text to: $query and pressing IME action")
+ onView(withId(composeToolbarR.id.mozac_addressbar_search_query_input)).perform(
+ replaceText(query), pressImeActionButton(),
+ )
+ Log.i(TAG, "submitQueryWithComposableToolbar: Toolbar text was set to: $query and IME action performed")
BrowserRobot().interact()
return BrowserRobot.Transition()
}
@@ -667,6 +667,20 @@ fun searchScreen(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
private fun browserToolbarEditView() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view"))
+private fun pressImeActionOnToolbarEditView() {
+ val context = appContext
+ val resId = context.resources.getIdentifier(
+ "mozac_browser_toolbar_edit_url_view",
+ "id",
+ packageName,
+ )
+
+ Log.i(TAG, "pressImeActionOnToolbarEditView: Trying to perform pressImeActionButton via Espresso")
+ onView(withId(resId))
+ .perform(pressImeActionButton())
+ Log.i(TAG, "pressImeActionOnToolbarEditView: Performed pressImeActionButton via Espresso")
+}
+
private fun dismissPermissionButton() =
mDevice.findObject(UiSelector().text("Dismiss"))