简体   繁体   English

量角器和茉莉花:如何测试重定向?

[英]Protractor and Jasmine: How can I test redirects?

I'm trying to write a set of e2e tests using Protractor and Jasmine. 我正在尝试使用量角器和茉莉花编写一组e2e测试。 I started with this: 我从这个开始:

describe('app login page', function() {
  it('shoudl be redirected to /#/login', function() {
    browser.get('http://127.0.0.1:8090');
    jasmine.log(window.location.pathname);
    expect(window.location.pathname).toEqual('/#/login');
  });
});

But looks like it does not pass in console. 但是看起来它没有通过控制台。 I receive the following error ReferenceError: window is not defined . 我收到以下错误ReferenceError: window is not defined Is there any way to test such redirects? 有什么方法可以测试这种重定向?

You can use getLocationAbsUrl() to get the current url that is opened in the browser and match its contents with toMatch() function that jasmine provides. 您可以使用getLocationAbsUrl()获取在浏览器中打开的当前URL,并将其内容与jasmine提供的toMatch()函数进行匹配。 Here's how - 这是如何做 -

browser.get('http://127.0.0.1:8090');
expect(browser.getLocationAbsUrl()).toMatch('/#/login');

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM