await page.getByRole("button", { name: "Save" }).click();
await page.waitForTimeout(2000);
expect(await page.getByText("Saved").count()).toBe(1);
Replace the last two lines with
await expect(page.getByText('Saved')).toBeVisible()The best fix is await expect(page.getByText('Saved')).toBeVisible(). A web-first assertion retries until the text appears or the expect timeout passes. The fixed sleep is the problem. It is too long on fast machines and too short on slow ones. The tempting 'retries set to 3' option is wrong. Retries only hide the flakiness, they don't fix it.
Read more
- Assertions (https://playwright.dev/docs/test-assertions)playwright.dev