Reputation: 76799
When running tests, the EU Cookie Consent Form keeps popping up, providing these options:
Yes, continue to see relevant ads
No, see ads that are less relevant
Pay for the ad-free version
How to access these buttons with the UIAutomator
, in order to continue?
Upvotes: -1
Views: 98
Reputation: 76799
One can get these buttons as an 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);
}
Upvotes: -1