Skip to content

Commit

Permalink
Scroll to when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe committed Sep 14, 2023
1 parent cceea17 commit 3041136
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 3041136

Please sign in to comment.