diff --git a/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/ui/EspressoText.kt b/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/ui/EspressoText.kt index 43e303f628d..947f5590e65 100644 --- a/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/ui/EspressoText.kt +++ b/paymentsheet-example/src/androidTest/java/com/stripe/android/test/core/ui/EspressoText.kt @@ -2,12 +2,23 @@ package com.stripe.android.test.core.ui import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed import androidx.test.espresso.matcher.ViewMatchers.withText -open class EspressoText(private val text: String) { +open class EspressoText(text: String) { + private val interaction = onView(withText(text)) fun click() { - onView(withText(text)) - .perform(ViewActions.click()) + val isNotVisible = runCatching { + interaction.check(matches(isCompletelyDisplayed())) + }.isFailure + + if (isNotVisible) { + interaction.perform(scrollTo()) + } + + interaction.perform(ViewActions.click()) } }