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
|
2020-02-09 22:16:48 +01:00
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
|
|
|
import androidx.test.uiautomator.UiSelector
|
2019-12-11 23:15:36 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-02-09 22:16:48 +01:00
|
|
|
fun clickOkInDialog() {
|
|
|
|
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
|
|
|
val button = uiDevice.findObject(UiSelector().clickable(true).checkable(false).index(1))
|
|
|
|
if (button.exists() && button.isEnabled) button.click()
|
|
|
|
}
|