fus*_*sio 7 login wait protractor angular-ui-router
我有一个标准的用户名/密码/提交按钮表单,当用户点击表单提交的按钮时ng-submit="login.submit()",登录和成功使用ui.router($state.go("main"))重定向到主页面.
以下测试失败:
describe("login", function() {
beforeEach(function() {
var email = element(by.model("login.email"));
email.clear().sendKeys("mail");
var password = element(by.model("login.password"));
password.clear().sendKeys("pass");
var submit = element(by.id("submit"));
submit.click();
});
it("should be able to login", function() {
expect(element(by.css(".loginPage")).isPresent()).toBe(false);
expect(element(by.css(".mainPage")).isPresent()).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
如果我尝试添加等待时间,我可以看到浏览器一直停留在登录页面上(点击按钮后) - 然后我得到超时.
成功登录后,浏览器会收到一个带有令牌的cookie,用于验证每个后续请求.
编辑:通过一些修修补补,我发现它失败了..
function login(email, pass) {
alert("it gets here");
return _auth.post({ username: email, password: pass }).then(function(data) {
alert("does not get here");
console.log("loginok, token:" +$browser.cookies().apiToken); //this should be the received token
return data;
});
}
Run Code Online (Sandbox Code Playgroud)
EDIT2:Auth服务
var _auth = Restangular.withConfig(function(Configurer) {
Configurer.setBaseUrl("/");
}).service("auth/simple");
return {
login: login,
};
function login(email, pass) {
return _auth.post({ username: email, password: pass });
}
Run Code Online (Sandbox Code Playgroud)
手动一切都按预期工作.
尝试这个:
it("should be able to login", function() {
browser.wait(element(by.css(".mainPage")).isPresent);//this is different from sleep, this will stop the excecution of all the protractor code that is after it, until the element is present, but it won't prevent the application of loading or if is redirecting, it will keep working.
expect(element(by.css(".loginPage")).isPresent()).toBe(false);
expect(element(by.css(".mainPage")).isPresent()).toBe(true);
});
Run Code Online (Sandbox Code Playgroud)
});
| 归档时间: |
|
| 查看次数: |
4494 次 |
| 最近记录: |