arrow-left Back to topicQuizBest PracticesCheck yourself1.Which locator is most resilient to UI refactoring?page.locator('.btn-primary')page.getByRole('button', { name: 'Save' })page.locator('#save-btn')2.What's wrong with page.waitForTimeout(3000) before an assertion?It's deprecated in newer Playwright versions.It adds a fixed delay — too slow on fast machines, too short on slow CI.It only works in headed mode.It blocks all network requests during the timeout.3.Test B fails only when test A doesn't run first. What is this problem called, and how do you fix it?Flakiness — fix it by adding retries in playwright.config.ts.Test coupling — fix it by making test B create its own data (e.g., via API call) instead of relying on test A's side effects.Race condition — fix it by adding await page.waitForTimeout(1000) between tests.A worker conflict — fix it by setting workers: 1 in config.4.When should you use getByTestId() over getByRole() or getByText()?Always — test IDs are the most stable locator type.When the element has no stable accessible role or visible text, and adding an accessible name would be impractical.Only for buttons — role-based locators don't work reliably for buttons.In CI environments only — locally you should always use CSS selectors.5.You need to click a 'Details' button inside a specific order card (by order ID). Which approach is correct?page.getByRole('button', { name: 'Details' }).first().click()page.locator('[data-orderid="ORD-001"] button').click()page.getByRole('article').filter({ hasText: 'ORD-001' }).getByRole('button', { name: 'Details' }).click()page.locator('.order-card:first-child button.details').click()6.Where do assertions belong in a Page Object Model?Inside the Page Object methods — keeps tests short.In the tests — Page Objects contain only locators and actions.In a separate Assertions class that extends the Page Object.In beforeEach hooks — assertions there apply to all tests.7.You're testing a payment flow that calls a real Stripe API. What should you do instead?Use a Stripe test-mode API key — it's designed for automated testing.Mock the Stripe endpoint with page.route() and return the exact response your test needs.Skip the payment test in CI and run it only locally.Add a waitForTimeout(5000) to allow the Stripe request to complete.8.Which playwright.config.ts setting saves traces for debugging failures without slowing down passing tests?trace: 'on'trace: 'on-first-retry'trace: 'off'trace: 'retain-on-failure'Submit answersarrow-left PreviousVideosMigrating from Testing LibraryNext arrow-right