Playwright + JS · Lesson 20 of 35

0/35 done

Module 20: Auto-Waiting & Synchronization

20. Actionability Checks & Network Synchronization

16 minlesson

Try it yourself

Implement isActionable:

  1. Accept status object with attached, visible, stable, enabled booleans.
  2. Return true only if all 4 are true.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

Playwright's 5 Actionability Checks

Before performing an action like click(), Playwright verifies:

  1. Attached: Present in the DOM.
  2. Visible: Has non-empty bounding box, not hidden.
  3. Stable: CSS animations and transitions have finished.
  4. Receives Events: Not obscured by modal overlays or spinners.
  5. Enabled: disabled attribute is false.
javascript
// ✅ Best Practice: Wait for the exact network response
const responsePromise = page.waitForResponse("**/api/checkout");
await page.getByRole("button", { name: "Place Order" }).click();
const response = await responsePromise;
expect(response.status()).toBe(200);

Key Takeaways & Walkthrough Summary

Say goodbye to arbitrary sleep timers! Hard sleeps slow down test suites and create flaky runs. In this lesson, we will explore Playwright's actionability checks, auto-waiting mechanics, and how to synchronize with network responses cleanly. Let's eliminate flakiness!

Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why should waitForTimeout() (hard sleep) be avoided?

Hard sleeps waste time if the page is fast and still fail if the network is slower than the hardcoded sleep. Always wait for specific network responses or element assertions.

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

JavaScript
Skip