Skip to content

Instantly share code, notes, and snippets.

@testableapple
Created February 22, 2020 18:40
Show Gist options
  • Select an option

  • Save testableapple/792a556e8cff52faddc8d8298949401f to your computer and use it in GitHub Desktop.

Select an option

Save testableapple/792a556e8cff52faddc8d8298949401f to your computer and use it in GitHub Desktop.
fun ViewInteraction.isDisplayed(): Boolean {
try {
this.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
} catch (ignored: NoMatchingViewException) {
return false
}
return true
}
fun ViewInteraction.doesNotExist(): Boolean {
try {
this.check(ViewAssertions.doesNotExist())
} catch (ignored: AssertionError) {
return false
}
return true
}
fun ViewInteraction.waitForAppear(millis: Long = 5000): ViewInteraction {
val timeout = System.currentTimeMillis() + millis
while (System.currentTimeMillis() < timeout) {
if (this.isDisplayed()) { break }
}
return this
}
fun ViewInteraction.waitForDisappear(millis: Long = 5000): ViewInteraction {
val timeout = System.currentTimeMillis() + millis
while (System.currentTimeMillis() < timeout) {
if (this.doesNotExist()) { break }
}
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment