【发布时间】:2014-12-23 16:21:01
【问题描述】:
我使用 afterEach 注销,但我的测试尝试在 afterEach 完成注销之前登录。
我试图避免使用 sleep 语句(真的会减慢速度)。
如何让测试等待前一个 beforeEach 完成?
代码 sn-ps:
afterEach(function() {
AccountBlock.logout().then(function(){
browser.sleep(2000); // I want to get rid of this
});
});
logout() 方法(来自 AccountBlock 对象):
this.logout = function() {
var logoutLink = this.logoutLink;
var userName = this.userName;
return logoutLink.isDisplayed().then(function(isDisplayed){
if (!isDisplayed) {
return userName.click().then (function() {
return logoutLink.click();
}); // open the account menu before logout
} else { // account menu already displayed
return logoutLink.click();
}
});
}
this.userName = element(by.css('a[ng-bind="userName"]'));
this.logoutLink = element(by.css('a[ng-click^="logout"]'));
【问题讨论】:
-
请包含一些代码以便于回答。
-
作为代码 sn-ps 添加到原始帖子中
-
Protractor 推荐handling log in with an
onPrepare,因此您只需登录您的应用程序一次,然后再运行所有测试。您真的需要在每次测试后退出吗? -
如果他需要在每个测试用例@user29之后退出...我们应该尝试回答手头的问题。
-
@HenrikBechmann 因为您没有为
userName.click();添加return,所以不要期望及时解决该承诺。如果你解决了这个问题并且仍然看到问题,我想我有一个解决方案。
标签: angularjs testing jasmine protractor e2e-testing