【问题标题】:Is there a way to continue test scenario execution after step failure in a previous scenario?有没有办法在前一个场景中的步骤失败后继续执行测试场景?
【发布时间】:2015-07-30 19:57:01
【问题描述】:

每当在远程服务器上运行时出现步骤失败,我想捕获失败的步骤,然后继续运行剩余的场景。然后将捕获的步骤包含在文件中以用于报告目的。这是一种可能吗?我在其他地方看到的所有回复都只是说你应该在继续之前修复测试。我同意,但我只希望测试在本地运行时停止,而不是远程运行。

➜ customer git:(pat104) ✗ cucumber.js -f progress (pat104⚡) ...F-----Failed scenario: View and select first contact from contact history ...F-Failed scenario: View and select a contact from multiple contacts in history ..................................................F---Failed scenario: Navigating to profile with url and enrollmentId ...................................................F-Failed scenario: Successful MDN Search with 1 result returned. Tech Selects and continues .............FFailed scenario: Successful MDN with multiple results

【问题讨论】:

  • 你能添加你用来运行测试的命令&&你得到的输出吗?你用什么来做报告?

标签: cucumberjs webdriver-io


【解决方案1】:

事实证明,其中一个步骤定义错误地使用了 .waitForExist。测试是这样写的:

this.browser
        .waitForExist('#someElement', 1000, callback)

回调不是.waitForExist的参数,重写为:

.waitForExist('#someElement',1000).then(function (exists) {
            assert.equal(exists, true, callback);
        })

【讨论】:

    【解决方案2】:

    这是默认行为,不是吗?示例命令

    cucumber.js -f json > cucumberOutput.json
    

    【讨论】:

    • 不,如果我使用 cucumber-js -f progress 运行测试,该步骤仍然会中断测试并且不会继续。
    • 这是关键,因为测试应该始终继续运行。
    • 我现在有一个失败的测试,它停止了黄瓜的执行,并且根本没有生成任何 json :(
    【解决方案3】:

    好吧,您需要使用callback.fail(e) 管理您的测试本身,如下所示。您可以使用 grunt-cucumberjs 之类的库将这些错误添加到漂亮的 HTML 报告中。

    this.Then(/^the save to wallet button reflects the offer is saved$/, function (callback) {
            merchantPage(this.nemo).doStuff().then(function () {
                callback();
            }, function (e) {
                callback.fail(e); //add this to report
            });
    });
    

    或者您可以使用Hooks 并检查场景是否失败并报告(截屏或添加日志等)

     this.After(function (scenario, callback) {
            var driver = this.nemo.driver;
            if(scenario.isFailed()){
                driver.takeScreenshot().then(function (buffer) {
                    scenario.attach(new Buffer(buffer, 'base64').toString('binary'), 'image/png');
                });
            }
            driver.quit().then(function () {
                    callback();
           });
     });
    

    【讨论】:

    • 将这个添加到测试后,仍然会在一个步骤失败后跳过该功能中的剩余场景。此外,必须将其添加到每个测试中似乎很麻烦。
    • [其中一个] 问题是即使 .After() 挂钩中没有 .quit() ,她的测试也会停止。有例外的时候你见过吗?我想我有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2021-12-06
    相关资源
    最近更新 更多