Protractor: browser.getCurrentUrl() returning an object instead of URL

Created on 9 Jul 2015  路  5Comments  路  Source: angular/protractor

I am running a protractor test to test if the proper URL is being displayed. When logging the method getCurrentUrl() within browser, I receive an object. Is there something I am missing?

describe('angularjs homepage todo list', function() {
    it('should add a todo', function() {
        browser.get('https://angularjs.org');

        console.log(browser.getCurrentUrl());
    });
});

Here is the output with the object logged instead of URL.

issue-url

Most helpful comment

@awarerahul you gotta resolve the promise liek this

wd.getCurrentUrl().then( function( url ) {
console.log(url);
});

All 5 comments

how can i get exact URL.

@awarerahul you gotta resolve the promise liek this

wd.getCurrentUrl().then( function( url ) {
console.log(url);
});

Thanks

or simply "await" for the .getCurrentUrl(), then the output will be the usable string
Example:

async function someFunc() {
  console.log(await browser.getCurrentUrl()); //output: "http://your-current.url"
}
Was this page helpful?
0 / 5 - 0 ratings