将UIAutomator与Admob Cookie同意表一起使用

时间:2019-04-23 10:04:42

标签: android admob android-uiautomator admob-cookieconsent

运行测试时,EU Cookie Consent Form会不断弹出,并提供以下选项:

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

  • 否,看到不相关的广告

  • 为无广告版本付费

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

1 个答案:

答案 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);
}