【问题标题】:Use UIAutomator with Admob Cookie Consent Form将 UIAutomator 与 Admob Cookie 同意书一起使用
【发布时间】:2019-04-23 10:04:41
【问题描述】:

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

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

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

  • 为无广告版本付费

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

【问题讨论】:

    标签: android admob android-uiautomator admob-cookieconsent


    【解决方案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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-01
      • 2011-09-03
      • 2018-02-01
      • 2016-02-14
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 2021-07-18
      相关资源
      最近更新 更多