Playwright interview questions — Medium

803 medium-level Playwright questions from our Automation Testing bank, each with the correct answer and an explanation of why it is correct.

What this covers

Playwright appears throughout Automation Testing interviews. At medium level, interviewers are typically checking that you have used it in practice: what you configured, what broke, and how you knew it worked. Work through these, then explain your answer out loud; the second part is what interviews actually test.

20 example questions

  1. 1. Why are Playwright Locators preferred over $() handles?

    • A. Lazily re-resolved on each action, avoiding stale elements.correct
    • B. Handles auto-wait but locators don't.
    • C. Locators only work on inputs.
    • D. $() supports assertions, locators don't.

    Why: Locators are lazy and re-resolved at action time with auto-wait.

  2. 2. "Executes JavaScript in the page's context and returns the result" — in Playwright, this describes which of the following?

    • A. Locator.fill().
    • B. GetByText().
    • C. Page.evaluate().correct
    • D. Page.screenshot().

    Why: page.evaluate(): Executes JavaScript in the page's context and returns the result.

  3. 3. Which Playwright tool lets you replay a recorded run with DOM snapshots, network, and console to debug failures?

    • A. Selenium IDE.
    • B. Trace Viewer.correct
    • C. JMeter Listener.
    • D. Appium Inspector.

    Why: Playwright's Trace Viewer replays a run with screenshots, DOM snapshots, network, and console logs — excellent for diagnosing CI failures.

  4. 4. "Opens the HTML report of the last test run" — in Playwright, this describes which of the following?

    • A. Trace: 'on-first-retry'.
    • B. Npx playwright show-report.correct
    • C. Page.screenshot().
    • D. Test.step().

    Why: npx playwright show-report: Opens the HTML report of the last test run.

  5. 5. "Waits for a network response matching a URL or predicate" — in Playwright, this describes which of the following?

    • A. Npx playwright show-report.
    • B. Page.waitForResponse().correct
    • C. Browser.newContext().
    • D. GetByTestId().

    Why: page.waitForResponse(): Waits for a network response matching a URL or predicate.

  6. 6. "Retrying assertion that the element is visible" — in Playwright, this describes which of the following?

    • A. Expect(locator).toBeVisible().correct
    • B. Test.use().
    • C. Page.screenshot().
    • D. Npx playwright show-report.

    Why: expect(locator).toBeVisible(): Retrying assertion that the element is visible.

  7. 7. "Config option that records a trace only when a test is retried" — in Playwright, this describes which of the following?

    • A. Test.use().
    • B. Page.evaluate().
    • C. Trace: 'on-first-retry'.correct
    • D. GetByTestId().

    Why: trace: 'on-first-retry': Config option that records a trace only when a test is retried.

  8. 8. "Captures a screenshot of the page or viewport" — in Playwright, this describes which of the following?

    • A. Page.goto().
    • B. Npx playwright show-report.
    • C. Projects.
    • D. Page.screenshot().correct

    Why: page.screenshot(): Captures a screenshot of the page or viewport.

  9. 9. "Overrides fixtures/options such as viewport or locale for a test group" — in Playwright, this describes which of the following?

    • A. GetByText().
    • B. Page.screenshot().
    • C. Test.use().correct
    • D. Test.step().

    Why: test.use(): Overrides fixtures/options such as viewport or locale for a test group.

  10. 10. Which of the following statements about Playwright is TRUE?

    • A. Playwright's codegen tool records user interactions and generates test code.correct
    • B. Playwright can only test Chromium-based browsers.
    • C. Playwright assertions evaluate exactly once and fail immediately if the condition is not yet true.
    • D. GetByRole() is discouraged in favor of XPath as the most resilient locator strategy.

    Why: npx playwright codegen bootstraps tests from recorded actions.

  11. 11. Which statement correctly describes Playwright?

    • A. BrowserContexts share cookies and localStorage with each other by default.
    • B. Playwright cannot send API requests without opening a browser page.
    • C. GetByRole() locates elements by their ARIA role and accessible name, making tests resilient to DOM changes.correct
    • D. Playwright assertions evaluate exactly once and fail immediately if the condition is not yet true.

    Why: Role-based locators mirror how users and assistive tech perceive the page.

  12. 12. Identify the accurate statement about Playwright:

    • A. Playwright's auto-waiting performs actionability checks (visible, stable, enabled) before interacting with an element.correct
    • B. Playwright can only test Chromium-based browsers.
    • C. BrowserContexts share cookies and localStorage with each other by default.
    • D. Playwright assertions evaluate exactly once and fail immediately if the condition is not yet true.

    Why: Actions wait for elements to be actionable, reducing flakiness.

  13. 13. "Clears and types text into an input field" — in Playwright, this describes which of the following?

    • A. Locator.fill().correct
    • B. Page.waitForResponse().
    • C. Locator.click().
    • D. Page.goto().

    Why: locator.fill(): Clears and types text into an input field.

  14. 14. Which Playwright concept matches this description: "Overrides fixtures/options such as viewport or locale for a test group"?

    • A. Page.screenshot().
    • B. Page.waitForResponse().
    • C. GetByTestId().
    • D. Test.use().correct

    Why: test.use(): Overrides fixtures/options such as viewport or locale for a test group.

  15. 15. In Playwright, which of the following is described as: "Captures a screenshot of the page or viewport"?

    • A. Page.goto().
    • B. Page.evaluate().
    • C. Test.use().
    • D. Page.screenshot().correct

    Why: page.screenshot(): Captures a screenshot of the page or viewport.

  16. 16. In the context of Playwright, which of the following is a correct statement?

    • A. Playwright requires a separate driver binary (like ChromeDriver) for each browser.
    • B. Playwright assertions evaluate exactly once and fail immediately if the condition is not yet true.
    • C. Playwright can only test Chromium-based browsers.
    • D. Playwright MCP exposes structured browser-control tools that AI models can call to drive a live browser.correct

    Why: MCP (Model Context Protocol) bridges LLMs and Playwright sessions for AI test generation.

  17. 17. Which Playwright concept matches this description: "Captures a screenshot of the page or viewport"?

    • A. Expect(locator).toBeVisible().
    • B. Page.evaluate().
    • C. Npx playwright show-report.
    • D. Page.screenshot().correct

    Why: page.screenshot(): Captures a screenshot of the page or viewport.

  18. 18. Which Playwright concept matches this description: "Locates elements by the data-testid attribute"?

    • A. Page.screenshot().
    • B. Locator.click().
    • C. Test.use().
    • D. GetByTestId().correct

    Why: getByTestId(): Locates elements by the data-testid attribute.

  19. 19. In Playwright, which of the following is described as: "Performs an actionability-checked click on the matched element"?

    • A. Page.evaluate().
    • B. Npx playwright show-report.
    • C. Locator.click().correct
    • D. Page.screenshot().

    Why: locator.click(): Performs an actionability-checked click on the matched element.

  20. 20. Which Playwright concept matches this description: "Creates a fresh isolated browser session"?

    • A. Browser.newContext().correct
    • B. Expect(locator).toBeVisible().
    • C. Test.step().
    • D. Locator.fill().

    Why: browser.newContext(): Creates a fresh isolated browser session.

Related Automation Testing topics