lmiguelvargasf lmiguelvargasf - 1 year ago 200
Javascript Question

how can I get the current url using protractor?

I am testing a website using protractor, and jasmine. I would like to know the current url in order to verify a test.

I have tried

function waitForUrlToChangeTo(urlRegex) {
var currentUrl;

return browser.getCurrentUrl().then(function storeCurrentUrl(url) {
currentUrl = url;
).then(function waitForUrlToChangeTo() {
return browser.wait(function waitForUrlToChangeTo() {
return browser.getCurrentUrl().then(function compareCurrentUrl(url) {
return urlRegex.test(url);

and I am using this function in this way

it('should log', function() {

Answer Source

Here is a working code based on the example provided by the author of the Expected Conditions:

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


browser.wait(urlChanged("http://localhost:9000/#/solicitudes"), 5000);