android Espresso- toast message assertions not working with sdk 30
Asked Answered
D

2

6

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?

Doersten answered 31/5, 2021 at 9:40 Comment(0)
W
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)))
    }
Wellintentioned answered 1/6, 2021 at 9:18 Comment(2)
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()))Doersten
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).Cultivar
S
0

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

Surbeck answered 3/7, 2022 at 12:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.