AndroidAPS/app/src/androidTest/java/info/nightscout/androidaps/EspressoHelper.kt

28 lines
795 B
Kotlin
Raw Normal View History

2019-12-11 23:15:36 +01:00
package info.nightscout.androidaps
2019-12-12 21:37:09 +01:00
import androidx.test.espresso.ViewAction
2019-12-11 23:15:36 +01:00
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
fun ViewInteraction.isDisplayed(): Boolean {
try {
check(matches(ViewMatchers.isDisplayed()))
return true
2019-12-12 21:37:09 +01:00
} catch (e: Throwable) {
2019-12-11 23:15:36 +01:00
return false
}
}
2019-12-12 21:37:09 +01:00
fun ViewInteraction.waitAndPerform(viewActions: ViewAction): ViewInteraction? {
val startTime = System.currentTimeMillis()
while (!isDisplayed()) {
Thread.sleep(100)
if (System.currentTimeMillis() - startTime >= 5000) {
throw AssertionError("View not visible after 5000 milliseconds")
}
}
return perform(viewActions)
}