量角器e2e测试登录重定向 [英] Protractor e2e Tests Login Redirection

查看:99
本文介绍了量角器e2e测试登录重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前有一个部分端到端测试,输入用户名/密码并点击登录。

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.

推荐答案

你的帖子缺乏信息,但我会尝试mak一个假设:

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(),检测到网址更改的合理超时时间(此处描述: 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.

这篇关于量角器e2e测试登录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆