我如何用量角器瓦特/柴作为许诺的处理承诺的数组 [英] How do I handle an array of promises using Protractor w/ chai-as-promised
问题描述
我使用的量角器是 CucumberJS 和柴AS-承诺(假设CucumberJS不具有一个内置的断言库)建立一个自动化测试套件。
一切正常单断言(使用期待的功能钗-AS-承诺)。我遇到了麻烦,但是,试图处理相同的测试(步)内的多个承诺的时候。在下面的例子中,verifyUserFirstName返回映射到特定行的td.getText承诺()。
this.Then(/ ^我应该可以看到正确的价值观我的用户条目列表$ /,函数(回调){
期待(usersPage.verifyUserFirstName('tony@gmail.com'))to.eventually.equal。('托尼');
期待(usersPage.verifyUserLastName('tony@gmail.com'))to.eventually.equal。('裴');
期待(usersPage.verifyUserPhone('tony@gmail.com'))to.eventually.equal。('8764309111');
回电话();
目前,当任何期望()线失败,量角器将退出并离开浏览器窗口挂不运行测试的其余部分。
在具有只是一个单一的期望()的一个步骤失败了(见下面的例子),一切都完美。它被记录为失败的步骤,以及量角器继续试验的其余部分运行到完成。有没有人经历过这个?
this.Then(/ ^我应直接向用户列表页$ /,函数(回调){
expect(browser.getCurrentUrl()).to.eventually.equal('http://localhost:9001/#/nav/').and.notify(callback);
});
我有同样的挑战,我这是怎么解决的:
this.Then(/ ^我应该可以看到正确的价值观我的用户条目列表$ /,函数(回调){
VAR verifyUser = Q.all([
usersPage.verifyUserFirstName('tony@gmail.com'),
usersPage.verifyUserLastName('tony@gmail.com'),
usersPage.verifyUserPhone('tony@gmail.com')
]);
期待(verifyUser).to.eventually.deep.equal(['托尼','裴','8764309111')and.notify(回调)。
}
我希望帮助!
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);
});
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!
这篇关于我如何用量角器瓦特/柴作为许诺的处理承诺的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!