【问题标题】:Spectron async isExisting doesnt return falseSpectron 异步 isExisting 不返回 false
【发布时间】:2018-05-04 22:23:44
【问题描述】:

我正在使用 spectron 3.8.0 并尝试检查 DOM 中是否存在 am 元素。我尝试将waitUntil 方法与try/catch 一起使用,但它没有按预期工作。最近我同步app.client.isExisting()如果元素存在则返回true,否则它会卡住并抛出超时异常(mocha)。

代码如下:

@log
protected async isExisting(element: string, name?: string): Promise<boolean> {
    await this.app.client.isExisting(element)
        .then(data => {
            const isExisting = data;
            console.log(CONSOLE_COLORS.YELLOW, "IS EXISTING???", isExisting);
            return isExisting;
        })
        .catch(e => {
            console.log(CONSOLE_COLORS.RED, "no existing elem")
            return false;
        });
}

【问题讨论】:

  • 我不确定应该如何调用 isExisting(),但看起来你应该返回来自 this.app.client.isExisting() 的承诺。您正在等待它,但没有获取或返回最终值。

标签: javascript webdriver electron webdriver-io spectron


【解决方案1】:

isExisting 应该可以正常工作。

你应该正确返回promise

return app.client.isExisting('#element');

这就像火花

如果给定选择器至少存在一个元素,则返回 true。如果不存在,则返回 false

要等待一个元素,请使用下面的

doesexist(app, element) {
    return app.client.waitforExist(element,60 * 1000);
}

只需传递需要检查的应用程序和元素。更简洁的方式避免等待

如果元素在 60 秒之前存在则返回 true,如果不存在则错误提示在 60 秒之后不存在

【讨论】:

  • 这段代码我看不懂,请输入相同的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-22
  • 1970-01-01
  • 2021-12-01
  • 2015-04-07
相关资源
最近更新 更多