4

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?

Dana
  • 109
  • 1
  • 6

2 Answers2

0

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)))
    }
Shivam Pokhriyal
  • 1,044
  • 11
  • 26
  • still not working (on api 29 and 30). This is working on 29 and not on 30: onView(withText(R.string.text)).inRoot( withDecorView(not(mActivityRule.activity.window.decorView))) .check(matches(isDisplayed())) – Dana Jun 03 '21 at 06:14
  • For me this is not even working on Android 28 (did not test with older versions). Not even UI Automator Viewer can detect the toast (even though I can see the message in the screenshot). – Aorlinn Aug 04 '21 at 13:25
0

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

Melad
  • 1,184
  • 14
  • 18