How do I handle an array of promises using Protractor w/ chai-as-promised

ε祈祈猫儿з 提交于 2019-12-14 02:20:52

问题


I am using Protractor with CucumberJS and chai-as-promised (given that CucumberJS does not have a built-in assertions library) to build an automated test suite.

Everything works fine for single assertions (using the expect feature of chai-as-promised). I run into trouble, however, when attempting to handle multiple promises within the same test (step). In the following example, verifyUserFirstName returns a promise mapped to a certain row's 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();

Currently, when any of the expect() lines fail, Protractor will exit and leave the browser window hanging without running the rest of the tests.

When a step featuring just a single expect() fails (see example below), everything works perfectly. It is logged as a failed step, and Protractor continues to run the rest of the tests to completion. Has anyone experienced this?

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);
});

回答1:


I had same challenge, this is how I solved:

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);
}

I hope that helps!



来源:https://stackoverflow.com/questions/27865536/how-do-i-handle-an-array-of-promises-using-protractor-w-chai-as-promised

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!