[英]Protractor e2e Tests Login Redirection
Currently have a partial end-to-end test that enters a username/password and clicks 'sign in'. 目前有部分端到端测试,输入用户名/密码并点击“登录”。
It does that successfully, but concludes at a "thanks you're logged in" page, instead of being redirected to the 'account portal' or 'dashboard', the way it would if I logged in through the browser.\\ 它成功地做到了,但是在“谢谢你登录”页面结束,而不是重定向到“帐户门户”或“仪表板”,就像我通过浏览器登录一样。
New to this project but we are using OAuth. 这个项目的新功能,但我们正在使用OAuth。
Main question: Does this sound like a need for http mocking? 主要问题:这听起来像需要http嘲笑吗?
Further details: 更多详情:
spec.js spec.js
describe('login page', function() {
browser.driver.get('http://url.path/login');
it('should render login page', function() {
// Checking the current url
var currentUrl = browser.driver.getCurrentUrl();
expect(currentUrl).toMatch('/login');
});
it('should sign in', function() {
// Find page elements
var userNameField = browser.driver.findElement(By.id('username'));
var userPassField = browser.driver.findElement(By.id('password'));
var userLoginBtn = browser.driver.findElement(By.id('loginbtn'));
// Fill input fields
userNameField.sendKeys('test@user.com');
userPassField.sendKeys('1234');
// Ensure fields contain what we've entered
expect(userNameField.getAttribute('value')).toEqual('test@user.com');
expect(userPassField.getAttribute('value')).toEqual('1234');
// Click to sign in - waiting for Angular as it is manually bootstrapped.
userLoginBtn.click().then(function() {
browser.waitForAngular();
expect(browser.driver.getCurrentUrl()).toMatch('/success');
}, 10000);
});
});
If I quickly click on the testing window, I can see it successfully reaches the 'success' page - but it does not redirect to the dashboard (it redirects when you manually sign in, through the browser). 如果我快速点击测试窗口,我可以看到它成功到达“成功”页面 - 但它没有重定向到仪表板(当您通过浏览器手动登录时,它会重定向)。 How can I continue this test to remain signed in and access the dashboard like a user would? 如何继续此测试以保持登录并像用户一样访问仪表板?
// New to the project, angular and and protractor. //新项目,角度和量角器。
EDIT - Summarizing this a bit: 编辑 - 总结一下:
(When a user manually logs in through the browser, they don't see the /thankyou page - it's a quick redirect to /dashboard . Protractor does not reach the dashboard page. (当用户通过浏览器手动登录时,他们看不到/ thankyou页面 - 它是一个快速重定向到/仪表板 。量角器没有到达仪表板页面。
Your post lacks information but I'll try to make an assumption: 你的帖子缺乏信息,但我会尝试做出一个假设:
I suspect that your "thanks you're logged in" page makes javascript redirect after a timeout. 我怀疑你的“谢谢你登录”页面会在超时后重定向javascript。
So after you click "Login", the browser loads "thanks you're logged in" page, and since the second parameter to .then()
does nothing, browser.waitForAngular()
fails because there is no angular on that page. 因此,在您单击“登录”后,浏览器会加载“感谢您已登录”页面,并且因为.then()
的第二个参数不执行任何操作,所以browser.waitForAngular()
失败,因为该页面上没有角度。
You should try to use something like browser.driver.wait()
with a reasonable timeout to detect url change (described here: https://github.com/angular/protractor/issues/610 ) and trigger browser.waitForAngular()
after the browser get to /success
page. 你应该尝试使用一些像browser.driver.wait()
这样的东西来检测网址的变化(在这里描述: https : //github.com/angular/protractor/issues/610 )并触发browser.waitForAngular()
之后浏览器进入/success
页面。
Have you tried using an explicit wait? 你尝试过使用明确的等待吗?
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /success/.test(url);
});
}, 10000);
Your code would be like that: 你的代码就像那样:
// Click to sign in - waiting for Angular as it is manually bootstrapped.
userLoginBtn.click();
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /success/.test(url);
});
}, 10000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.