← Back to Discord Forum

How to make Playwright less flaky?

Playwright is great for avoiding a lot of manual QA in the browser, which is great!

On the project I'm working on however, it's incredibly flaky... I have set it to 2 retries and it still doesn't pass all the tests every time. The website I'm testing is not overly complex (no React or Angular, some modern JS).

Are there techniques to make it less flaky? It's gotten to a point where I just can't trust the Playwright test suite because I don't know if it's a flaky test or a failing-for-real one.

This thread is trying to answer question "Are there techniques to make Playwright less flaky?"

8 replies

Can you give us more details? What kind of errors do you get?

Just failing tests, like an element that's supposed to be hidden or visible isn't, but on the first, second, third, or fourth retry it will eventually be.

waitForResponse is usually what people miss in Playwright. If you know how the website is behaving in the background, then Playwright gives you enough tools to reduce flakiness.

Thanks, I'll check how I can use waitForResponse

Also, you can use expect(async () => {}).toPass() to enforce retries on parts of your test instead of retrying the whole test case.

or maybe try to experiment with waitForLoadState() https://playwright.dev/docs/api/class-page#page-wait-for-load-state

There are enough apis in PW to handle flakiness, kindly explore docs. Here are some I find useful waitFor({ state }), waitForRequest, waitForResponse, waitForURL, waitForEvent, waitForFunction, expect().toPass, expect.poll(), etc.

This 👆 but if you need those methods to avoid flakiness at every step then there are fundamental issues with the web application

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.