whd
whd

Reputation: 1861

Protractor and Jasmine: How can I test redirects?

I'm trying to write a set of e2e tests using Protractor and Jasmine. 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. Is there any way to test such redirects?

Upvotes: 2

Views: 914

Answers (1)

giri-sh
giri-sh

Reputation: 6962

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. Here's how -

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

Hope it helps.

Upvotes: 5

Related Questions