Testing Snackbar show with Espresso

前端 未结 3 1570
陌清茗
陌清茗 2021-02-05 00:28

Is there a way to test using Espresso that the snackbar shows up with the right text?

I have a simple call to create a snackbar

Snackbar.make(mView, \"My         


        
3条回答
  •  执念已碎
    2021-02-05 01:22

    This worked for me, please try.

    onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("My text")))
                .check(matches(isDisplayed()));
    

    If you use AndroidX, please use the following:

    onView(withId(com.google.android.material.R.id.snackbar_text))
            .check(matches(withText(R.string.whatever_is_your_text)))
    

提交回复
热议问题