From 1c6b2ceb4bc912804195635633ab5d83738f2e03 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 10 Nov 2021 21:53:53 +0000 Subject: [PATCH] adding retrying to the reaction long pressing and extra visibilty check for dialogs --- .../androidTest/java/im/vector/app/EspressoExt.kt | 12 ++++++++++++ .../im/vector/app/espresso/tools/WaitActivity.kt | 2 ++ .../java/im/vector/app/ui/robot/RoomDetailRobot.kt | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/vector/src/androidTest/java/im/vector/app/EspressoExt.kt b/vector/src/androidTest/java/im/vector/app/EspressoExt.kt index 8ad157d17a..59982c72aa 100644 --- a/vector/src/androidTest/java/im/vector/app/EspressoExt.kt +++ b/vector/src/androidTest/java/im/vector/app/EspressoExt.kt @@ -68,6 +68,18 @@ object EspressoHelper { } } +fun withRetry(attempts: Int = 3, action: () -> Unit) { + runCatching { action() }.onFailure { + val remainingAttempts = attempts - 1 + if (remainingAttempts <= 0) { + throw it + } else { + Thread.sleep(500) + withRetry(remainingAttempts, action) + } + } +} + fun getString(@StringRes id: Int): String { return EspressoHelper.getCurrentActivity()!!.resources.getString(id) } diff --git a/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt b/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt index f296617d98..05f1ca2815 100644 --- a/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt +++ b/vector/src/androidTest/java/im/vector/app/espresso/tools/WaitActivity.kt @@ -26,6 +26,7 @@ import im.vector.app.activityIdlingResource import im.vector.app.waitForView import im.vector.app.withIdlingResource import org.hamcrest.Matcher +import org.hamcrest.Matchers.not inline fun waitUntilActivityVisible(noinline block: (() -> Unit) = {}) { withIdlingResource(activityIdlingResource(T::class.java), block) @@ -37,4 +38,5 @@ fun waitUntilViewVisible(viewMatcher: Matcher) { fun waitUntilDialogVisible(viewMatcher: Matcher) { onView(viewMatcher).inRoot(isDialog()).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + waitUntilViewVisible(viewMatcher) } diff --git a/vector/src/androidTest/java/im/vector/app/ui/robot/RoomDetailRobot.kt b/vector/src/androidTest/java/im/vector/app/ui/robot/RoomDetailRobot.kt index df1771546c..747f9d6fb0 100644 --- a/vector/src/androidTest/java/im/vector/app/ui/robot/RoomDetailRobot.kt +++ b/vector/src/androidTest/java/im/vector/app/ui/robot/RoomDetailRobot.kt @@ -38,6 +38,7 @@ import im.vector.app.features.home.room.detail.timeline.reactions.ViewReactionsB import im.vector.app.features.reactions.data.EmojiDataSource import im.vector.app.interactWithSheet import im.vector.app.waitForView +import im.vector.app.withRetry import java.lang.Thread.sleep class RoomDetailRobot { @@ -71,7 +72,7 @@ class RoomDetailRobot { addQuickReaction(quickReaction) } // Open reactions - longClickOn(quickReaction) + longClickReaction(quickReaction) // wait for bottom sheet interactWithSheet(withText(R.string.reactions), openState = BottomSheetBehavior.STATE_COLLAPSED) { pressBack() @@ -99,6 +100,12 @@ class RoomDetailRobot { waitUntilViewVisible(withId(R.id.composerEditText)) } + private fun longClickReaction(quickReaction: String) { + withRetry { + longClickOn(quickReaction) + } + } + fun openMessageMenu(message: String, block: MessageMenuRobot.() -> Unit) { onView(withId(R.id.timelineRecyclerView)) .perform(