Playwright test flaky after a click (count still 3, expected 4) with page.waitForTimeout(500): use expect.poll or a web-first assertion instead of a fixed sleep
Fix: replace the sleep plus a one-time read with an assertion that retries until the DOM catches up: await expect(page.getByText(/Total messages: 4/)).toBeVisible(), or for a computed value, await expect.poll(async () => parseInt((await page.textContent('#count'))?.match(/\d+/)?.[0] ?? '0'), { timeout: 5000 }).toBe(initial + 1). In an Electron + React app tested through Playwright's _electron, submitting a form went through IPC to the main process (a better-sqlite3 insert), a second IPC call to reload, then setState and a re-render. After waitForTimeout(500), textContent still showed the old count, and the test failed with 'Expected: 4, Received: 3', even though the insert had worked. Fixed sleeps either race like this on a busy CI box or waste time on a fast one. page.textContent() and locator.textContent() read once and never retry, whereas expect(locator).toHaveText()/toBeVisible() and expect.poll() keep re-checking until their timeout. Prefer a locator assertion when the value is visible text (toHaveText(/4/)), and keep expect.poll for values you have to compute or fetch, such as rows in SQLite via electronApp.evaluate. Playwright's docs discourage waitForTimeout in tests for this reason.