[英]How do I handle an array of promises using Protractor w/ chai-as-promised
我将Protractor与CucumberJS和chai-as-promised (假定CucumberJS没有内置的断言库)一起使用,以构建自动化测试套件。
一切对于单个断言都可以正常工作(使用chai-as-promised的期望功能)。 但是,在尝试在同一测试(步骤)中处理多个promise时遇到麻烦。 在以下示例中,verifyUserFirstName返回映射到特定行的td.getText()的promise。
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()行失败时,量角器将退出并保持浏览器窗口挂起,而不运行其余测试。
当仅包含单个Expect()的步骤失败时(请参见下面的示例),则一切正常。 它被记录为失败的步骤,并且量角器将继续运行其余测试以完成测试。 有人经历过吗?
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);
});
我遇到了同样的挑战,这就是我解决的方法:
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);
}
希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.