问题描述
这个简单的检查适用于 sdk 29 但不适用于 sdk 30:
onView(withText(R.string.text)).inRoot(withDecorView(not(mActivityRule.activity.window.decorView))) .check(matches(isdisplayed()))
我收到 androidx.test.espresso.NoMatchingRootException。
有人可以帮忙解决这个问题吗?
解决方法
Espresso 无法可靠地断言 toast 消息。将 uiAutomator
与 espresso 一起使用来声明祝酒词。
fun checkToast(msg: String) {
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.waitForIdle()
org.junit.Assert.assertTrue(uiDevice.hasObject(By.text(msg)))
}