2016-02-04 48 views
2

我只需要這兩杯咖啡中的一張即可通過。我怎樣才能做到這一點?如果其中一個ViewAssertion s通過,我會很高興。意式濃縮咖啡 - 您如何執行OR(||)檢查?

onView(withId(R.id.mainview)) 
      .check(

        matches(not(isDisplayed())) 
      ) 

onView(withId(R.id.mainview)) 
      .check(

        doesNotExist() 
      ) 

回答

1

這不是最好的方法,但它會工作。理想情況下,您應該使用自定義視圖匹配器...但我們都很懶。

try { 
    // See if view is displayed 
    onView(withId(R.id.mainview)) 
      .check(
        matches(not(isDisplayed())) 
     ); 
} 
catch (NoMatchingViewException e){ 
    // Otherwise check it doesn't exist 
    onView(withId(R.id.mainview)) 
      .check(
        doesNotExist() 
     ); 
} 
0

我認爲你唯一的選擇是一個自定義匹配。