1 package host.exp.exponent.utils 2 3 import androidx.test.uiautomator.UiDevice 4 import com.azimolabs.conditionwatcher.ConditionWatcher 5 import androidx.test.uiautomator.UiSelector 6 import androidx.test.espresso.Espresso 7 import androidx.test.espresso.matcher.ViewMatchers 8 import androidx.test.espresso.assertion.ViewAssertions 9 import androidx.test.uiautomator.Configurator 10 import com.azimolabs.conditionwatcher.Instruction 11 import java.lang.Exception 12 13 object ExpoConditionWatcher { 14 @Throws(Exception::class) waitForTextnull15 fun waitForText(device: UiDevice, text: String) { 16 ConditionWatcher.waitForCondition(object : Instruction() { 17 override fun getDescription(): String { 18 return "$text text should exist" 19 } 20 21 override fun checkCondition(): Boolean { 22 Configurator.getInstance().waitForSelectorTimeout = 1000 23 val selector = UiSelector().text(text) 24 return device.findObject(selector).exists() 25 } 26 }) 27 Espresso.onView(ViewMatchers.withText(text)) 28 .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) 29 } 30 } 31