android Espresso- toast message assertions not working with sdk 30

Viewed 790

this simple check is working on sdk 29 but not on sdk 30:

onView(withText(R.string.text)).inRoot( withDecorView(not(mActivityRule.activity.window.decorView))) .check(matches(isDisplayed()))

I get androidx.test.espresso.NoMatchingRootException.

can anyone help with this issue?

2 Answers

Espresso can't reliably assert toast messages. Use uiAutomator alongwith espresso for asserting toasts.

    fun checkToast(msg: String) {
        val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
        uiDevice.waitForIdle()
        org.junit.Assert.assertTrue(uiDevice.hasObject(By.text(msg)))
    }

Accourding to the comments for this issue in github. You can see that toast matching in sdk 30 is not working with anybody

Related