Use role-based locators, web-first assertions, Page Object Model, fixtures for dependency injection, and tracing for CI debugging.
0 / 5 completed
1 / 5
What are Playwright locators and why are they preferred over CSS selectors?
Locators: role-based locators (getByRole, getByLabel, getByText, getByPlaceholder) encourage testing from the user's perspective rather than implementation details. They auto-wait for the element to be visible and stable before acting, eliminating the flakiness of manual waitForSelector calls. They also align with accessibility best practices.
2 / 5
What does expect(locator).toBeVisible() do in Playwright and how does it differ from a regular assertion?
Web-first assertions: regular assertions (expect(el.isVisible()).toBe(true)) check once and fail immediately. Playwright's built-in assertions retry automatically with the same auto-wait engine used by actions. toBeVisible, toHaveText, toHaveValue, and toBeChecked all retry until the condition is met or the timeout is reached.
3 / 5
What is the Page Object Model in Playwright and what benefits does it provide?
Page Object Model: when a selector changes, you update it in one page class instead of every test that uses it. Page objects also make tests more readable — await loginPage.loginAs("admin") is more expressive than raw Playwright API calls. Playwright recommends using locators inside page objects for the auto-wait benefits.
4 / 5
What are Playwright fixtures and how do they differ from beforeEach hooks?
Playwright fixtures: fixtures are composable — a adminPage fixture can depend on an authenticatedPage fixture. Only fixtures declared in the test function signature are instantiated, reducing unnecessary setup. Custom fixtures can scope resources to the test or the worker, enabling efficient parallelisation with shared costly resources like database seeding.
5 / 5
What does Playwright tracing capture and when is it most useful?
Playwright tracing: enable with await context.tracing.start({ screenshots: true, snapshots: true }) and stop with await context.tracing.stop({ path: "trace.zip" }). Configure in playwright.config.ts with trace: "on-first-retry" to capture traces only on failures. The Trace Viewer shows every action with a before/after DOM snapshot and the network waterfall.