2

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?

giri-sh
  • 6,934
  • 2
  • 25
  • 50
whd
  • 1,819
  • 1
  • 21
  • 52

1 Answers1

5

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.

giri-sh
  • 6,934
  • 2
  • 25
  • 50