【问题标题】:Protractor / cucumber test suite stop running when expect fails in promise.thenProtractor / cucumber 测试套件在 promise 中预期失败时停止运行。then
【发布时间】:2014-07-29 23:26:46
【问题描述】:

我正在开发一个使用 Protractor(v 0.24.1)、Cucumber(v 0.4.0)、Chai(v 1.9.1) 和 Chai-as-promised (v 4.1.1) 的测试框架。

Selinium-server-standalone.jar (v 2.41.0) chromedriver(v 2.10)

在这一步中,我以 2 种不同的方式验证计数。一种在 promise 的 then 中,第二种方式使用 chai-as-promised 库来验证计数。

element.all(by.css('[ticket-id]')).then(function (tickets) {
    expect(tickets.length).to.equal(2, "length correct");
    //expect(tickets.length).to.equal(3, "length wrong");
});
expect(element.all(by.css('[ticket-id]')).count()).to.eventually.to.equal(2).and.notify(next);

这通过了,我收到了消息:

1 scenario (1 passed)
3 steps (3 passed)
Process finished with exit code 0

现在,当我在 then 中更改期望失败时,一切都会消失。

element.all(by.css('[ticket-id]')).then(function (tickets) {
    //expect(tickets.length).to.equal(2, "length correct");
    expect(tickets.length).to.equal(3, "length wrong");
});

现在我只收到消息:

Process finished with exit code 1

此故障会在没有堆栈跟踪或任何帮助调试的情况下停止测试执行。 有谁知道为什么或解决这个问题的方法?

我们正在考虑更新 Protractor,这可能会有所帮助。

【问题讨论】:

  • 其他人的更新,布拉德打开了这个issue on HitGub,它已在黄瓜 v0.4.7 中解决,已关闭。

标签: javascript testing cucumber protractor chai


【解决方案1】:

以下解决方案解决了您的问题:

element.all(by.css('[ticket-id]')).then(function (tickets) {
    expect(tickets.length).to.equal(2, "length correct");
    //expect(tickets.length).to.equal(3, "length wrong");
}).catch(function(err){
    callback(err);
});
expect(element.all(by.css('[ticketid]')).count()).to.eventually.to.equal(2).and.notify(next);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多