【问题标题】:Protractor invisibilityOf flakiness, throwing NoSuchElementErrorProtractor invisibilityOf 片状,抛出 NoSuchElementError
【发布时间】:2015-07-24 10:07:09
【问题描述】:

我正在使用量角器测试一个非角度应用程序,在我的测试中我有一个登录助手功能,类似于以下内容:

function login() {
        return waitUntilVisible($('#txtUsername'))
            .then(function () {
                $('#txtUsername').sendKeys('tom');
            })
            .then(function () {
                $('#txtPassword').sendKeys('*');
            })
            .then(function () {
                $('#btnLogin').click();
            })
            .then(function () {
                // this is the flaky line
                return browser.wait(protractor.ExpectedConditions.invisibilityOf($('#txtUsername')), 20000, 'Element never disappeared');
            });
    }

browser.wait(protractor.ExpectedConditions.invisibilityOf($('#txtUsername')), 20000, 'Element never disappeared') 等待包含登录表单的引导模式关闭。然而,这条线被证明是非常不稳定的,偶尔会失败:

NoSuchElementError: No element found using locator: By.cssSelector("#txtUsername")

甚至:

StaleElementReferenceError:过时的元素引用:元素未附加到页面文档

我的第一个想法是在调用该行之前模态已关闭,但是,invisibilityOf 的文档建议它应该处理不存在的元素,并将其声明为:

检查元素是否不可见或不存在于 DOM 上的期望。

我怎样才能使这条线健壮?

【问题讨论】:

    标签: javascript twitter-bootstrap protractor


    【解决方案1】:

    函数visibilityOftextToBePresentInElement 不是原子的,可能会产生错误。在内部,它们依次检查isPresentisDisplayed/getText,但如果在这些检查之间恰好删除了一个元素,则会出现NoSuchElementErrorStaleElementReferenceError

    这个错误可能会在未来的版本中得到修复。在您可以使用我包装为 npm 模块的解决方法之前:

    https://www.npmjs.com/package/protractor-save-expected-conditions

    【讨论】:

      【解决方案2】:

      invisibilityOf 切换到stalenessOf 已经成功了。

      【讨论】:

        猜你喜欢
        • 2018-11-24
        • 1970-01-01
        • 1970-01-01
        • 2019-05-23
        • 2023-01-18
        • 1970-01-01
        • 2019-06-08
        • 1970-01-01
        • 2016-06-17
        相关资源
        最近更新 更多