2016-05-23 34 views
2

用Espresso可以簡化這兩個陳述嗎?查看AlertDialog的標題和信息

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

我想這一個,但它不工作:

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

回答

1

爲什麼簡化嗎?但是,您可以檢查父視圖,讓孩子看到期望的文字。

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())), 
)));