与异步/等待一起使用守夜

时间:2020-10-29 08:35:30

标签: javascript web nightwatch e2e

守夜人版本:1.3.5

我在PageObject中编写了一个Common,并返回了Promise,当我将其用作“ await xxx”时,出现一些错误。

但是我实际上返回了一个承诺...

PageObject中的共同点:

waitForAllElementNotPresent(selector = '.el-loading-mask', time = 10000) {
    const _that = this;
    return new Promise(function (resolve, reject) {
        _that.api.elements('css selector', selector, function (res) {
            let len = res.value.length;
            let times = 0;
            for (let i = 0; i < len; i++) {
                _that.api.waitForElementNotPresent('css selector', {
                    selector: selector,
                    index: i
                }, time, function () {
                    times++;
                });
            }
            let timeInterval = setInterval(() => {
                if (times >= len) {
                    resolve();
                    clearInterval(timeInterval);
                }
            }, 500);
        });
    });
}

像这样使用公地

await this.topNav.waitForAllElementNotPresent('.el-loading-mask');

这样的错误:

   - writing an ES6 async test case? - keep in mind that commands return a Promise;
   - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.

0 个答案:

没有答案