有没有办法在前一个场景中的步骤失败后继续测试场景执行?

时间:2015-07-30 19:57:02

标签: cucumberjs webdriver-io

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

➜ 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

3 个答案:

答案 0 :(得分:3)

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

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

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

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

答案 1 :(得分:0)

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

cucumber.js -f json > cucumberOutput.json

答案 2 :(得分:0)

好吧,您需要使用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();
       });
 });
相关问题