-1

运行测试时,欧盟 Cookie 同意书不断弹出,提供以下选项:

  • 是的,继续查看相关广告

  • 不,查看相关性较低的广告

  • 为无广告版本付费

如何使用 , 访问这些按钮UIAutomator以继续?

4

1 回答 1

-1

可以将这些按钮作为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);
}
于 2019-04-23T10:04:41.537 回答