playwright-perl icon indicating copy to clipboard operation
playwright-perl copied to clipboard

await waitForNavigation times-out?

Open Deracination opened this issue 2 years ago • 2 comments

Using waitForNavigation after a click always times-out.

Here's an example:

my $pw = Playwright->new();
my $browser = $pw->launch( headless => 1, type => 'chrome' );
my $page = $browser->newPage({ viewport => { width => 2048, height => 1024 }});

$page->goto('https://github.com/teodesian/playwright-perl', { waitUntil => 'networkidle' });
$page->click('text="Go to file"');

$pw->await( $page->waitForNavigation({ waitUntil => "domcontentloaded" }));

This is based on a JS playwright test script which does the following:

await Promise.all([
            this.page.click(sel),
            this.page.waitForNavigation({ waitUntil: "domcontentloaded" }),
        ]);

Deracination avatar Oct 04 '22 23:10 Deracination

Note that you have done your waiting in JS in a Promise.all, which fires both requests simultaneously.

In the perl you are clicking the link that executes navigation, and then waiting. I suspect if you do your wait before the click, and then await the promise like so:

my $promise = $page->waitForNavigation({ waitUntil => "domcontentloaded" }));
$page->click('text="Go to file"');
$pw->await($promise);

the code will work. See the example here: https://github.com/teodesian/playwright-perl/blob/main/example.pl#L96


In summary, because perl is not an event-driven language like javascript, you have to handle things slightly differently than you would expect. From a technical point of view, this is not actually any different than what is going on in JS -- you have to set up the relevant listener before the required event happens, or a timeout will occur. Promise.All simply allows you to not feel that pain.

teodesian avatar Oct 05 '22 13:10 teodesian

I can on the other hand say with confidence that it would be valuable and a good user experience to implement a similar capability to promise.All which may be used to abstract away such akwardness. Reopening as a feature request along those lines.

teodesian avatar Oct 05 '22 13:10 teodesian