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.

[BUG] Problems with parallelism and page.waitForSelector

See original GitHub issue

Context:

  • Playwright Version: 1.19.1
  • Operating System: Linux
  • Node.js version: 14
  • Browser: Chromium
  • Extra: Our tests run on an Azure Devops pipeline agent with 2 cores and 7gb of RAM.
page.waitForSelector('[data-test-hook="home-page-container"]', { state: 'attached', timeout: 1_000 });

Describe the bug

While migrating our E2E tests from Puppeteer to Playwright, I’ve noticed that as we increase the amount of parallelism to speed up our tests, our calls to page.waitForSelector() get flakier. To the point that in our trace files we can see that the desired selector is already attached in the ‘before’ tab, and yet we still get timeout errors.

Below I have attached a screenshot showing the issue. If it is helpful, I can provide the full trace file internally at Microsoft.

It is worth noting that if I use page.$('[data-test-hook="home-page-container"]') to test for the element’s presence, it does not seem to be affected by the parallelism problem, but it comes with the major downside that it doesn’t put records of the action into the trace file, which is often essential to our debugging.

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dgozmancommented, Mar 24, 2022

@joshuacc Model B is almost exactly how it works. When you say “on the next turn of the event loop”, that’s not entirely accurate though. Checking something in the page involves going to the other OS process (browser process vs playwright’s node process), so the check is very much asynchronous as well. This also means that going to the Model A is impossible, because the very first iteration of checking for the element may take arbitrary amount of time.

In addition, I’d say page.waitForSelector() is rarely used. Most of the time you just do page.locator().click() and that waits for the element inside. If you had to resort of page.waitForSelector(), you have something unusual going on, and most likely the element is not immediately present in the page. Note this is just an opinion, no hard statistics behind it 😄

1reaction
dgozmancommented, Mar 22, 2022

@joshuacc There could definitely be a bug, but we’ll need to debug locally with a repro to find it 😄

When I use page.$() to check for the presence of that element, this failure doesn’t occur.

That’s because page.$() does not have a timeout, so no matter how slow the machine is, it will eventually respond with an element. If you bump your waitForSelector timeout, you’ll see less flakiness.

Overall, we recommend to run without any timeouts for specific actions (or with a rather large timeout like 30s), and instead rely on a single test timeout to find issues. This way, you usually do not have flakiness due to process scheduling under heavy load.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Puppeteer - Handlin page.waitForSelector() fails
waitForSelector () fails, it throws an error. Since this is run inside an async function if leads straight to the catch portion of...
Read more >
antisnatchor
Ex.: bugs or chains that need: ... Achieve parallelism with multiple browser tabs ... waitForSelector('#intro > div:nth-child(1) > div.row > div > h4')....
Read more >
Puppeteer infinite scroll
Web. I browse an infinite scroll page using Puppeteer but this page is really, really long. The problem is that the memory used...
Read more >
e2e Testing - Quality Thoughts
Jest by default runs tests across files in parallel and uses the available resources to scale appropriately using processes/threads. I've found this ...
Read more >
Design and Implementation of Test Suite for Modern Web SPA
for finding solutions to many problems on web application testing. ... Page class does expose a method called waitForSelector for this purpose.
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