【问题标题】:Handling webdriverio timeouts处理 webdriverio 超时
【发布时间】:2021-02-09 09:42:01
【问题描述】:

这是我想要完成的:

check if element "Error" span exists
     then do something if it does ===
else check if element "el2" span exists
      then do something ====
else
      do something

这是我的代码

let done = false;
let errorOccured = false;
let isManualStep = false;
do {
    try {
        console.log('Checking span.label-red=Error...................')
        let errorStepExists = $('span.label-red=Error').isExisting();
        if (errorStepExists) {
            console.log('Error encountered...................')

            done = true;
        }
    } else {
        console.log('Error not encountered...................')
        let el2Exists = $('span>td.col-md-2=Waiting').isExisting();
        if (mel2Exists) {
            console.log('Encountered...................')
        }
    } catch (e) {
        console.log(e);
    }
}
while (!done);

如果元素不存在,它似乎不会进入 catch 块,而是因为超时错误而未能通过我的测试。

错误:超过 20000 毫秒的超时。测试“xxxxxx”中的执行时间过长。尝试减少运行时间或增加测试规范的超时时间 (https://webdriver.io/docs/timeouts.html)。

【问题讨论】:

    标签: javascript selenium-webdriver timeout


    【解决方案1】:

    不确定如何在编程语言绑定中实现目标的最佳方式,但是 java 中的最佳方式是使用 WebDriver 接口的“findElements(By locator)”方法。

    此方法返回一个列表。然后,您通过检查此列表的大小来检查您的 WebElement 是否存在。 (如果大小不为 0,则您的 WebElement 存在)。

    希望这可以帮助您在语言绑定中采用类似的方法。

    【讨论】:

    • 感谢 Sandeep,我也在 webdriverio 中使用 $$ 尝试了这种方法,但超时仍然会触发并且测试失败。我认为这是与“it”块本身有关的摩卡超时。
    • 我面临同样的问题,我的测试因超时错误“超过 60000 毫秒超时”而失败。并且 catch 块永远不会被击中。您是否找到任何解决方案或解决方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 2021-03-01
    • 2023-03-24
    • 2016-11-22
    • 2015-01-28
    • 2012-12-23
    • 1970-01-01
    相关资源
    最近更新 更多