From b2673bc65404cce4836bfc893ada8f4ac914494d Mon Sep 17 00:00:00 2001 From: Oana Horvath Date: Fri, 22 May 2020 21:06:24 +0300 Subject: [PATCH] for #10753: improves the clickAddBookmarkButton method in flaky tests (#10842) --- .../fenix/ui/robots/ThreeDotMenuMainRobot.kt | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt index 7d6aafc38..3fa6518da 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuMainRobot.kt @@ -6,15 +6,20 @@ package org.mozilla.fenix.ui.robots +import android.view.View import androidx.recyclerview.widget.RecyclerView import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.UiController +import androidx.test.espresso.ViewAction import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility @@ -25,6 +30,7 @@ import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until +import org.hamcrest.Matcher import org.hamcrest.Matchers.allOf import org.mozilla.fenix.R import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime @@ -70,10 +76,25 @@ class ThreeDotMenuMainRobot { Until.findObject(By.desc("Bookmark")), waitingTime ) - addBookmarkButton().click() - // wait for main menu to disappear - mDevice.waitNotNull( - Until.gone(By.res("mozac_browser_menu_recyclerView")) + addBookmarkButton().perform( + click( + /* no-op rollback action for when clicks randomly perform a long click, Espresso should attempt to click again + https://issuetracker.google.com/issues/37078920#comment9 + */ + object : ViewAction { + override fun getDescription(): String { + return "Handle tap->longclick." + } + + override fun getConstraints(): Matcher { + return isAssignableFrom(View::class.java) + } + + override fun perform(uiController: UiController?, view: View?) { + // do nothing + } + } + ) ) }