robolectric/robolectric

Can't assert that toast text is showing up espresso way.

Open

#5,091 opened on Jun 6, 2019

View on GitHub
 (5 comments) (2 reactions) (0 assignees)Java (5,755 stars) (1,356 forks)batch import
help wanted

Description

Description

I had a passing test with espresso that tries to log in with invalid email, and it shows toast message, When I move it into 'test' path and it fails to pass

androidx.test.espresso.NoMatchingRootException: Matcher 'with decor view not <DecorView@1b26160[LoginActivity]>' did not match any of the following roots: [Root{application-window-token=android.view.ViewRootImpl$W@604ee46e, window-token=android.view.ViewRootImpl$W@604ee46e, has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#20 ty=1 fl=#81810100 pfl=0x20000 wanim=0x10302f6 needsMenuKey=2 colorMode=0}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=320, height=470, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,0)(fillxfill) sim=#20 ty=1 fl=#81810100 pfl=0x20000 wanim=0x10302f6 needsMenuKey=2 colorMode=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}}]

seems like toast might not even be showing up.

Steps to Reproduce

make toast show up, assert using

onView(withText(R.string.TOAST_STRING)).inRoot(withDecorView(not(currentActivity.window.decorView))).check(matches(isDisplayed()))

Robolectric & Android Version

Robolectric 4.3 on target sdk26

Link to a public git repo demonstrating the problem:

Contributor guide