stephanec
stephanec

Reputation: 325

How to show the current URL in protractor debug

I'm using protractor to test my angular application.

I want to show the current URL when a console.log is show in the browser. I use this for now but I don't find the solution to show the current URL.

afterEach(function() {
  browser.manage().logs().get('browser').then(function(browserLog){
    var message = JSON.parse(browserLog[i].message).message.parameters[0].value;
    expect(message.indexOf("localizationService") > -1).toBe(false, 'because\n There is a I18N error somewhere.\n Please see the error above in\n >>ERROR I18Ns : \n' + message + '\n' + browser.getCurrentUrl());
  }
}

I just need to know what I have to use instead of browser.getCurrentUrl() which is returning a Promise

Upvotes: 2

Views: 1667

Answers (1)

giri-sh
giri-sh

Reputation: 6962

You can get the url by resolving the promise that getCurrentUrl() function returns and then expect your requirement. Here's how you can do it -

afterEach(function() {
  browser.manage().logs().get('browser').then(function(browserLog){
    var message = JSON.parse(browserLog[i].message).message.parameters[0].value;
    browser.getCurrentUrl().then(function(url){
        expect(message.indexOf("localizationService") > -1).toBe(false, 'because\n There is a I18N error somewhere.\n Please see the error above in\n >>ERROR I18Ns : \n' + message + '\n' + url);
    });
  }
}

Hope this helps.

Upvotes: 2

Related Questions