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