【问题标题】:how to retry if cannot find element in Nightwatch如果在 Nightwatch 中找不到元素,如何重试
【发布时间】:2017-08-22 20:25:20
【问题描述】:

如果 nightwatch 没有点击某个元素,我想重试。我怎样才能做到这一点?

我有以下代码:

 this.browser.isVisible('.signUp', function (result) {
            if (result.value && result.length) {
                for(var i = 0; i < 3; i += 1) {
                    this.browser.click(this.element.login.signInBtn);
                    var check = this.browser.url(function(result) {
                        // on login page
                        console.log(result);
                        if (result.value.indexOf("#login") !== -1) {
                            return false;
                        } else {
                            return true;
                        }
                    });
                    if (check) {
                        break;
                    }
                }
            }
        }.bind(this));

【问题讨论】:

  • 你能解释一下为什么你需要重试一些东西吗?一般来说,如果您需要重试,某些事情没有按预期工作,这就是应该解决的问题,而不是测试

标签: nightwatch.js


【解决方案1】:

-retries n 不会在函数之前和之后运行,因此这不会按预期工作。您应该尝试 --suiteRetries n。

【讨论】:

  • 两者有什么区别?
【解决方案2】:

您可以使用--retries 命令行选项重试测试用例。示例nightwatch --retries 2 将重试失败的测试用例两次。

但是我不建议您使用它。我将首先探索其他选项以确保可以单击该元素。比如等待它通过waitForElementVisible可见的示例

this.browser.waitForElementVisible(this.element.login.signInBtn, 1000);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2022-01-20
    • 2023-03-09
    • 2016-08-03
    • 2019-04-22
    相关资源
    最近更新 更多