Q1
Why is page.waitForLoadState('networkidle') officially discouraged by Playwright for SPAs—and what should replace it?
Modern apps keep analytics beacons, WebSockets, or polling pings open so networkidle either hangs until 30s timeout or resolves prematurely before lazy React chunks render! Wait explicitly for user-visible locators (expect(locator).toBeVisible()) or specific API responses (page.waitForResponse(...)).
Q2
How do Playwright Locators differ fundamentally from Puppeteer/Selenium element handles—and why do they almost never go stale?
A Playwright Locator does NOT hold a cached DOM handle; it represents an instruction to re-query cleanly right before every action with built-in strictness checks (errors cleanly if >1 match) and auto-waiting for visibility, stability, and enabled state.
Q3
Unlike Selenium, why does Playwright pierce Open Shadow DOM automatically—yet how do frameLocator iframes behave differently?
Playwright CSS/role locators traverse open Shadow Roots seamlessly without special helper calls, whereas iframe contexts still require scoping via page.frameLocator('#payFrame').getByRole(...) (and closed Shadow DOM still blocks standard DOM queries).
Q4
How does `Browser -> BrowserContext -> Page` isolation let Playwright run 20 parallel authenticated tests in < 2 seconds without launching 20 Chromium binaries?
Each BrowserContext acts like an isolated incognito profile (~milliseconds to create) with separate cookies, localStorage, and permissions inside a single shared Chromium OS process.
Q5
How do you reuse authenticated login state (storageState.json) safely across Playwright workers WITHOUT hitting login UI 100 times?
Run a single setup project (globalSetup / setup dependency) that logs in once via API or UI, saves context.storageState({ path: '.auth/user.json' }), and injects that storageState cleanly into every worker—with isolated per-worker accounts if tests mutate user state!
Q6
Why is await expect(locator).toBeVisible() vastly superior to expect(await locator.isVisible()).toBe(true)?
locator.isVisible() resolves *immediately* once without auto-retrying—failing flakily if the spinner hides 50ms later! Web-first assertion await expect(locator).toBeVisible() auto-polls reliably until timeout.
Q7
How do page.route('**/api/**', ...) network mocks vs APIRequestContext hybrid testing speed up E2E reliability?
Use request (APIRequestContext) to seed/clean real test DB records fast over HTTP before the test, and use page.route selectively to simulate tricky 503 server failures, offline timeouts, or third-party payment webhooks.
Q8
Why do headless CI Playwright tests sometimes pass locally yet fail in GitHub Actions—and how does Trace Viewer (`trace: 'on-first-retry'`) diagnose it in 30 seconds?
CI containers have slower CPUs, narrower viewports, or timezone differences. Enabling trace: 'on-first-retry' records DOM snapshots per action, network HAR timelines, and console logs—letting you scrub step-by-step visually offline.
Q9
What breaks when testing window.open / OAuth popups or multi-tab checkout without Promise.all([page.waitForEvent('popup'), btn.click()])?
Clicking *before* registering the waitForEvent listener loses the race if the popup opens synchronously! Starting waitForEvent('popup') / waitForEvent('download') concurrently inside Promise.all guarantees capture.
Q10
How do you avoid race conditions when parallel Playwright workers modify the same database search records?
Give each worker unique prefixed test data (testInfo.workerIndex / UUIDs) or separate per-worker accounts rather than asserting global shared row counts across parallel specs.