答案 0 :(得分:0)
人们可以将这些按钮作为UiCollection
:
@Test
public void CookieConsent() {
UiSelector selector = getSelector("buttons");
UiCollection elements = new UiCollection(selector);
UiObject buttonYes, buttonNo, buttonAdFree;
try {
if (elements.getChildCount() == 3) {
// Yes, continue to see relevant ads
buttonYes = elements.getChild(getSelector("btn0"));
assertNotNull(buttonYes);
// No, see ads that are less relevant
buttonNo = elements.getChild(getSelector("btn1"));
assertNotNull(buttonNo);
// Pay for the ad-free version
buttonAdFree = elements.getChild(getSelector("btn2"));
assertNotNull(buttonAdFree);
/* click "yes" */
assertTrue(buttonYes.isClickable());
buttonYes.click();
}
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
}
private UiSelector getSelector(String resourceId) {
return new UiSelector()
.className(android.view.View.class.getName())
.resourceId(resourceId);
}