检查 AlertDialog 的标题和消息

Check an AlertDialog's title and message

使用 Espresso 是否可以简化这两个语句?

    onView(withText(expectedErrorTitle))
            .check(matches(isDisplayed()));
    onView(withText(expectedErrorMessage))
            .check(matches(isDisplayed()));

我试过这个但是没用:

    onView(allOf(
            withText(expectedErrorTitle),
            withText(expectedErrorMessage)
    )).check(matches(isDisplayed()));

为什么还要简化?但是您可以检查父视图是否有带有预期文本的子视图。

onView(R.id.parentLayout)
  .check(matches(allOf(
    isDisplayed(), 
    withChild(withText("A")),
    withChild(withText("B"))
)));

检查父级是否显示就足够了,或者你做一些更疯狂的事情,比如

onView(R.id.parentLayout)
  .check(matches(allOf(
    withChild(allOf(withText("A"), isDisplayed())),
    withChild(allOf(withText("B"), isDisplayed())),
)));