【问题标题】:appium nodejs (wd) hangs if element is not found如果找不到元素,appium nodejs (wd) 挂起
【发布时间】:2023-03-08 17:32:01
【问题描述】:

我在使用 appium + nodejs (wd) + mocha 时遇到了问题,因为我有一个加载视图(黑盒测试,我不是 android 应用程序开发人员),我想等待它消失。所以我尝试了这样的事情:

wd.addPromiseChainMethod('waitForElementByIdDisappears', function (id, retries) {
    var self = this;
    return new Promise(function (resolve, reject) {
        (function waitForElementDisappears(retry, context){
            if(retry < 0) {
              return reject();
            }
            else {
              try {
                context.elementByIdIfExists(id, function(err, element) {
                  console.log('Element found: ' + element + ' retry: ' + retry);
                  if(typeof element === 'undefined') {
                    return resolve();
                  }
                  else {
                    setTimeout(() => waitForElementDisappears(retry-1, context), 1000);
                  }                  
                });
              }
              catch (error) {
                console.log(error);
                return reject();
              }
            }
        })(retries, self);
    });
});

在加载视图消失之前一切正常,因为随后 nodejs 开始挂起 appium 独立控制台输出:

信息:[debug] [BOOTSTRAP] [debug] 使用:UiSelector[RESOURCE_ID=de.myapp.foo:id/loadingView] 信息:[debug] [BOOTSTRAP] [debug] getElements 选择器:UiSelector[RESOURCE_ID=de.myapp.foo:id/loadingView] 信息:[debug] [BOOTSTRAP] [debug] Element[] 为空:(0)

一遍又一遍地重复,直到超时。

我也试过了:

hasElementById(value, cb) -&gt; cb(err, boolean)

elementByIdOrNull(value, cb) -&gt; cb(err, element)

elementsById(value, cb) -&gt; cb(err, element) (并检查元素列表是否为空)

以及其他语法方式,例如:

context.elementByIdIfExists(id).then(element =&gt; { ... })

但每次我的输出都是这样的:

Element found: 15 retry: 30
Element found: 15 retry: 29
Element found: 15 retry: 28
Element found: 15 retry: 27

# hangs because the loading view was disappeared and appium standalone starts to repeat the [debug][info] section above ...

感谢阅读和帮助!

【问题讨论】:

    标签: javascript android node.js mocha.js appium


    【解决方案1】:

    我以前使用独立的 appium,现在更改为最新的 npm appium 版本 1.6.x。但最后在我的方法之前设置 .setImplicitWaitTimeout(250) 并在该方法对我有用之后重置它。

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2017-07-13
      • 2019-09-24
      • 2021-10-26
      • 2023-03-18
      • 2021-10-25
      • 1970-01-01
      • 2020-10-01
      • 2019-10-14
      相关资源
      最近更新 更多