Check if a dialog is displayed with Espresso

后端 未结 6 600
孤街浪徒
孤街浪徒 2020-12-04 14:07

I\'m trying to write some tests with the new android-test-kit (Espresso). But I can\'t find any information on how to check if a dialog is displayed and per

6条回答
  •  盖世英雄少女心
    2020-12-04 14:53

    1. To verify if dialog appears you can simply check if View with a text that present inside the dialog is shown:

      onView(withText("dialogText")).check(matches(isDisplayed()));
      

      or, based on text with id

      onView(withId(R.id.myDialogTextId)).check(matches(allOf(withText(myDialogText), isDisplayed()));
      
    2. To click on dialogs button do this (button1 - OK, button2 - Cancel):

      onView(withId(android.R.id.button1)).perform(click());
      

      UPDATE

    3. I think is possible since Espresso has multi window support.
    4. Not sure about clicking outside the custom dialog view but for checking if it is displaying or not you have to create your custom matcher and check inside it.

提交回复
热议问题