Dan*_*ana 5 android matcher assertion android-toast android-espresso
这个简单的检查适用于 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来祝酒。
fun checkToast(msg: String) {
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.waitForIdle()
org.junit.Assert.assertTrue(uiDevice.hasObject(By.text(msg)))
}
Run Code Online (Sandbox Code Playgroud)