0

I would like to get the current URL using protractor, and then verify that this URL is the one that I need. I am using:

istheSameURL(url) {
    return browser.getCurrentUrl() === 'http://localhost:9000/#/analysis/62/1';
}

However, it is not working.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
  • 1
    What's not working about it? Does browser.getCurrentUrl() not return anything? – barbiepylon Apr 28 '15 at 17:22
  • it returns false, although I have called browser.waitForAngular(), so it is supposed in this case the value has to be true. – lmiguelvargasf Apr 28 '15 at 17:31
  • @lmiguelvargasf debug it a little bit and see what the real url value is at the moment: `expect(browser.getCurrentUrl()).toEqual('http://localhost:9000/#/analysis/62/1');`. How does it fail now? Thanks. – alecxe Apr 28 '15 at 17:36
  • 1
    what about `expect(browser.getLocationAbsUrl()).toEqual(someUrl);`? – Aaron Apr 28 '15 at 18:29
  • Aaron, it worked. Thank you so much. If you want you can create an Answer, and I can accept it as valid. – lmiguelvargasf Apr 29 '15 at 15:40

2 Answers2

1

Yes, browser.getCurrentUrl() should be used. It could be that you need to wait for the URL to be changed using browser.wait():

var urlChanged = function(url) {
  return function () {
    return browser.getCurrentUrl().then(function(actualUrl) {
      return url != actualUrl;
    });
  };
};

browser.wait(urlChanged("http://localhost:9000/#/analysis/62/1"), 5000); 
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I am getting a time out error. What if I do not want to wait I mean if after having used a waitForAngular I want to check the URL exactly at that moment. – lmiguelvargasf Apr 28 '15 at 17:19
1

browser.getCurrentUrl() doesn't work with IE 10 if I recall. If you want to test against IE, you'll have to write some jquery that does that. I combined both the browser.getCurrentUrl method and the jquery into a function, did an if-check on the browser, and then put that in a common function library.

Zach Folwick
  • 893
  • 10
  • 18