Playwright Middle interview questions and answers
75 questions for a Playwright (Middle) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.What does
fullyParallel: truechange? - 2.Why do many configs set
workers: process.env.CI ? 1 : undefined? - 3.What does
retries: process.env.CI ? 2 : 0achieve? - 4.What does a test marked "flaky" in the Playwright report mean?
- 5.What does
forbidOnly: !!process.env.CIprotect against? - 6.What is the difference between
actionTimeoutand the testtimeout? - 7.How do you change options like locale for one group of tests only?
- 8.How do you create a custom fixture?
- 9.When does teardown code in a fixture run?
- 10.What is a worker-scoped fixture?
- 11.What does
{ auto: true }do for a fixture? - 12.What is the recommended way to log in once and reuse it?
- 13.How do you test with two different roles in one test, e.g. admin and user?
- 14.What are project
dependenciesused for? - 15.Why prefer a setup project over
globalSetup? - 16.What does this route do?
- 17.How do you simulate a server error for one endpoint?
- 18.How do you change a real API response slightly, e.g. one field?
- 19.What does
route.abort()do? - 20.How do you wait for a specific API response after a click?
- 21.What is
routeFromHARused for? - 22.How do you parameterize a test over several inputs?
- 23.How do you pass a value like a user role through project options?
- 24.What does
test.stepgive you? - 25.What does
expect.softdo? - 26.When is
expect.polluseful? - 27.How do you add a custom message to an assertion?
- 28.How do you attach a file or text to the test report?
- 29.What happens the first time
toHaveScreenshot()runs? - 30.Why are screenshot baselines often stored per platform?
- 31.How do you hide a changing element, like a clock, in a screenshot test?
- 32.What does
locator.or()do? - 33.What does
locator.and()do? - 34.How do you find list items that do NOT contain a "Sold out" label?
- 35.Do Playwright locators work inside open shadow DOM?
- 36.Why is
force: trueon a click risky? - 37.What does
locator.waitFor()do? - 38.Why can
await locator.isVisible()cause flaky tests? - 39.Why is
waitForLoadState('networkidle')discouraged? - 40.How do you run code in the page before any of its scripts load?
- 41.What does
page.evaluate()do? - 42.How do you test how a page behaves offline?
- 43.How do you test a location-based feature?
- 44.How do you test dark mode styles?
- 45.What does
page.clockhelp with? - 46.How do you drag an item onto a drop zone?
- 47.What does
trial: trueon an action do? - 48.How do you read the texts of all matching elements?
- 49.Which assertion checks the texts of a whole list in order?
- 50.What does
npx playwright test --last-faileddo? - 51.How do you check whether a test is flaky locally?
- 52.What does
video: 'retain-on-failure'do? - 53.What is the blob reporter for?
- 54.Which reporter is common for CI systems like Jenkins or GitLab?
- 55.Why use the official Playwright Docker image in CI?
- 56.Which artifacts should a CI job keep after a failed Playwright run?
- 57.What does a Page Object usually contain?
- 58.Why are page objects often provided through fixtures?
- 59.Where should assertions live in a Page Object Model?
- 60.What does
test.describe.configure({ retries: 3 })do? - 61.How can a test know it's running as a retry?
- 62.What happens to the worker process after a test fails?
- 63.How do you load environment-specific values like a staging URL?
- 64.How can you check a page for accessibility issues in a Playwright test?
- 65.What does
toMatchAriaSnapshotcompare? - 66.Which locator filters buttons by their checked state, like a toggle?
- 67.How do you handle a cookie consent banner that appears randomly?
- 68.How do you keep test data separate when tests run in parallel workers?
- 69.What does
test.describe.configure({ mode: 'serial' })do when a test fails? - 70.How do you make an API request with the cookies of the logged-in page?
- 71.How do you create a request context with an auth header for API tests?
- 72.Why combine API setup with UI checks in one test?
- 73.Which
useoption records traces only for failed tests? - 74.What do you see in the trace viewer for each action?
- 75.How do you test that a request is sent with the right body?