問題描述
目前有一個輸入用戶名/密碼并點擊登錄"的部分端到端測試.
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.
這個項目的新手,但我們正在使用 OAuth.
New to this project but we are using OAuth.
主要問題:這聽起來像是需要 http 模擬嗎?
更多細節:
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.
編輯 - 稍微總結一下:
- 我希望量角器在 /login 頁面上開始測試
- 量角器應該找到并填寫用戶名和密碼字段,然后點擊登錄
- 量角器成功登錄,看到一個/thankyou頁面,然后立即重定向到用戶的/dashboard頁面
- 也許我錯過了一個步驟,我們需要在量角器測試中手動重定向嗎?
- I would like protractor to begin tests on the /login page
- Protractor should find and fill out the username and password fields, then click Login
- Protractor successfully log in, to see a /thankyou page, then immediately redirect to the user's /dashboard page
- Maybe I'm missing a step, do we need to manually redirect in Protractor tests?
(當用戶通過瀏覽器手動登錄時,他們看不到 /thankyou 頁面 - 這是一個快速重定向到 /dashboard .量角器無法到達儀表板頁面.
(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.
推薦答案
您的帖子缺少信息,但我會嘗試做一個假設:
Your post lacks information but I'll try to make an assumption:
我懷疑您的感謝您已登錄"頁面會在超時后重定向 javascript.
I suspect that your "thanks you're logged in" page makes javascript redirect after a timeout.
所以當你點擊登錄"后,瀏覽器會加載謝謝你登錄"頁面,并且由于 .then()
的第二個參數什么都不做,browser.waitForAngular()
失敗,因為該頁面上沒有角度.
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.
您應該嘗試使用類似 browser.driver.wait()
之類的東西并設置合理的超時時間來檢測 url 更改(此處描述:https://github.com/angular/protractor/issues/610) 并在瀏覽器之后觸發 browser.waitForAngular()
進入 /success
頁面.
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.
這篇關于Protractor e2e 測試登錄重定向的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!