question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Puppeteer - I.getCurrentUrl() returns last URL rather than current url

See original GitHub issue

What are you trying to achieve?

What do you get instead?

Provide console output if related. Use --verbose mode for more details.

Open Github @sample --
 open browser and navigate to github.com
 • I am on page "https://github.com/awshanks"
 • I click "codecept_training_material"
 • I get current url 
https://github.com/awshanks

Provide test source code if related

Scenario('open browser and navigate to github.com', (I) => {
I.amOnPage('https://github.com/awshanks');
I.click('codecept_training_material');
I.getCurrentUrl().then(function (result) {
    console.log(result);
});
});

Details

  • CodeceptJS version: 1.1.5 (puppeteer 1.1.0)
  • NodeJS Version: 8.9.4
  • Operating System: MacOS
  • Protractor || WebDriverIO || Nightmare version (if related)
  • Configuration file:
# paste suite config here

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
reubenmillercommented, Feb 26, 2018

Here is the full example of a custom helper for sake of completeness.

'use strict';

let Helper = codecept_helper;

class MyCustomHelper extends Helper {
  async getCurrentUrl() {
    const helper = this.helpers['Puppeteer'];
    return helper.page.url();
  }
}

module.exports = MyCustomHelper;
0reactions
awshankscommented, Mar 3, 2018

Okay, I think I’ve narrowed down the issue I was having and it seems that if a website use hash routing the page.url doesn’t update after a click that directs to another page.

The I.click works fine and goes to the page and I see the url in the verbose output.

If I go to the page with I.amOnPage(‘/#/page’) the route will change (and with show:true on I can see the correct page), but codecept doesn’t know that the page has changed and the amOnPage will fails after it retries and I always just have the baseUrl that I defined in the config. (related to https://github.com/Codeception/CodeceptJS/issues/945). Maybe a solution is for me not to use hashHistory.push(‘URL_HERE’) and instead use <Link>. Sharing my observation for awareness. https://github.com/GoogleChrome/puppeteer/issues/257

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer - I.getCurrentUrl() returns last URL rather than ...
No the Puppeteer api is a little different to WebDriverIO etc. The .url() function is actually on the Page object and not the...
Read more >
How To Get The URL After Redirecting from Current Page ...
type('input#password' , "puppeteer"); await page.click('#signBtn').then(await console.log(page.
Read more >
Puppeteer
Retrieves an attribute from an element located by CSS or XPath and returns it to test. Resumes test execution, so should be used...
Read more >
Get Current URL in Selenium using Python: Tutorial
Using the Current URL method in Selenium to perform a URL check on google.com. Step 1: Import the required packages using the following...
Read more >
Getting the URL of the current page using Selenium ...
We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found