【问题标题】:How do I handle an array of promises using Protractor w/ chai-as-promised如何使用带 chai-as-promised 的 Protractor 处理一系列承诺
【发布时间】:2016-09-09 17:56:46
【问题描述】:

我将 ProtractorCucumberJSchai-as-promised 一起使用(因为 CucumberJS 没有内置的断言库)构建自动化测试套件。

对于单个断言来说一切正常(使用 chai-as-promised 的 expect 特性)。但是,当尝试在同一个测试(步骤)中处理多个承诺时,我遇到了麻烦。在以下示例中,verifyUserFirstName 返回一个映射到特定行的 td.getText() 的承诺。

this.Then(/^I should see my user entry with proper values in the list$/, function (callback) {
    expect(usersPage.verifyUserFirstName('tony@gmail.com')).to.eventually.equal('Tony');
    expect(usersPage.verifyUserLastName('tony@gmail.com')).to.eventually.equal('Bui');
    expect(usersPage.verifyUserPhone('tony@gmail.com')).to.eventually.equal('8764309111');
    callback();

目前,当任何 expect() 行失败时,Protractor 将退出并让浏览器窗口挂起,而不运行其余测试。

当仅包含一个 expect() 的步骤失败时(参见下面的示例),一切正常。它被记录为失败的步骤,并且 Protractor 继续运行其余的测试以完成。有人经历过吗?

this.Then(/^I should be directed to the user list page$/, function (callback) {
    expect(browser.getCurrentUrl()).to.eventually.equal('http://localhost:9001/#/nav/').and.notify(callback);
});

【问题讨论】:

    标签: javascript angularjs cucumber protractor chai-as-promised


    【解决方案1】:

    我遇到了同样的挑战,我就是这样解决的:

    this.Then(/^I should see my user entry with proper values in the list$/, function (callback) {
        var verifyUser = Q.all([
            usersPage.verifyUserFirstName('tony@gmail.com'),
            usersPage.verifyUserLastName('tony@gmail.com'),
            usersPage.verifyUserPhone('tony@gmail.com')
        ]);
        expect(verifyUser).to.eventually.deep.equal(['Tony', 'Bui', '8764309111').and.notify(callback);
    }
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 1970-01-01
      • 2013-10-23
      相关资源
      最近更新 更多