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

查看:22
本文介绍了Protractor 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.

推荐答案

您的帖子缺少信息,但我会尝试做一个假设:

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 测试登录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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