2

With Espresso is it possible to simplify those two statements ?

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

I tried with this one but it doesn't work :

    onView(allOf(
            withText(expectedErrorTitle),
            withText(expectedErrorMessage)
    )).check(matches(isDisplayed()));
Yohan D
  • 930
  • 2
  • 7
  • 24

1 Answers1

1

Why simplify more? But you could check on a parent view to have children with expected text.

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

Checking that the parent is displayed could be enough or you do more crazy stuff like

onView(R.id.parentLayout)
  .check(matches(allOf(
    withChild(allOf(withText("A"), isDisplayed())),
    withChild(allOf(withText("B"), isDisplayed())),
)));
nenick
  • 7,340
  • 3
  • 31
  • 23