2017-10-17 38 views

回答

0

可以刷卡一次,如果您的显示TextView的验证执行刷卡动作。如果不是,再次刷卡。

或者,您可以在您验证了TextView的方法...如果“NoMatchingViewException”被抛出,你刷卡。

像这样(没有测试的代码):

public static boolean swipeUntilExists(int resourceId) { 
    final ViewInteraction uiElement = onView(withId(resourceId)); 
    boolean isVisible = false; 
    while (!isVisible) { 
     try { 

      // do swipe here 

      uiElement.check(matches(isDisplayed())); 
      isVisible = true; 
     } catch (NoMatchingViewException e) { 
      // do nothing here 
     } 
    } 
    return isVisible; 
} 
0

这可以在一个公正的一个循环,使刷卡完成,然后检查该元素在try/catch块是可见直到到达浏览量结束或该项目被发现。

如果达到浏览量的结束,该项目没有找到,那么你可以这样做Assert.fail(“元素还没有被发现。”);

试试这个代码:

boolean found = false; 
int i = 0; 
while (!found && i < NUM_PAGES) { 
    onView(withId(R.id.viewPager)).perform(swipeLeft()); 
    SystemClock.sleep(500); 

    try { 
     if (checkElementVisible()) { 
      found = true; 
     } 
    } catch (Exception e) { 
     // The search continues 
    } 
    i++; 
} 

if (!found) { 
    Assert.fail("The element has not been found."); 
}