CTCaliberTek
Interview Questions

Playwright Fundamentals Interview Questions and Answers

15 Playwright questions on architecture, auto-waiting, locators, assertions, isolation, fixtures, and how it compares with Selenium.

Published October 24, 2026 · Updated October 29, 2026 · 15 questions·1 view

Edited by , Senior Data Analyst. How we make our content

  1. 1. What is Playwright, and why do teams choose it?

    Playwright is an open-source end-to-end testing framework from Microsoft that automates Chromium, Firefox, and WebKit with one API, in TypeScript, JavaScript, Python, Java, and .NET. Teams like its auto-waiting, fast parallel runs, built-in test runner and reports, trace viewer, network control, and good support for modern single-page apps.

  2. 2. How is Playwright different from Selenium?

    Playwright controls browsers through its own protocol and waits for elements automatically, includes a test runner with parallelism, retries, tracing, and reports, and isolates tests with browser contexts. Selenium uses the W3C WebDriver standard and supports more languages and legacy and real-device setups, but needs more assembly (test framework, waits, reporting). Both are valid; choose based on language, browser needs, and team skills.

  3. 3. What is auto-waiting?

    Before an action such as click, Playwright automatically waits until the element is attached, visible, stable (not animating), enabled, and able to receive events. This removes most manual sleeps and waits. Actions fail with a clear timeout error if the conditions are not met.

  4. 4. What are web-first assertions?

    Assertions from expect, such as toBeVisible and toHaveText, that retry until they pass or a timeout expires, instead of checking once. They keep tests stable against asynchronous updates. A plain assertion on a value you already read, such as expect(await locator.textContent()), does not retry, so prefer the locator forms.

    await expect(page.getByRole('status')).toHaveText('Saved');
  5. 5. What locators does Playwright recommend?

    User-facing locators first: getByRole (with name), getByLabel, getByPlaceholder, getByText, getByAltText, getByTitle, and getByTestId for a data-testid attribute. Fall back to CSS or XPath only when needed. Locators are lazy and re-resolve on every action, which avoids stale element errors.

    await page.getByRole('button', { name: 'Sign in' }).click();
    await page.getByLabel('Email').fill('ada@example.com');
  6. 6. What are the Browser, BrowserContext, and Page objects?

    A Browser is a browser instance. A BrowserContext is an isolated session inside it, like an incognito profile with its own cookies and storage, and is cheap to create. A Page is a tab within a context. Playwright Test creates a fresh context and page for every test, which gives isolation without restarting the browser.

  7. 7. What are fixtures in Playwright Test?

    Fixtures provide each test with what it needs, such as page, context, browser, and request, and can be extended with your own. They set up and tear down per test, only run when a test asks for them, and replace large beforeEach blocks.

    import { test as base } from '@playwright/test';
    
    export const test = base.extend<{ loggedInPage: Page }>({
      loggedInPage: async ({ page }, use) => {
        await page.goto('/login');
        await page.getByLabel('Email').fill('ada@example.com');
        await page.getByRole('button', { name: 'Sign in' }).click();
        await use(page);
      },
    });
  8. 8. How do you configure Playwright Test?

    In playwright.config.ts using defineConfig: testDir, timeout, retries, workers, reporter, a use block (baseURL, trace, screenshot, video), and projects for different browsers and devices. Projects let one test suite run on Chromium, Firefox, WebKit, and mobile emulation.

  9. 9. How do you handle authentication across many tests?

    Log in once in a setup project, save the browser state with storageState to a file, and configure projects to start from that file, so tests begin already signed in. This is much faster than logging in through the UI before every test. Use separate state files for different roles.

  10. 10. How do you test APIs with Playwright?

    Use the request fixture (APIRequestContext) to send HTTP requests, check status and body, and combine it with UI tests, for example creating data through the API before checking it in the UI.

    test('creates an item', async ({ request }) => {
      const response = await request.post('/api/items', { data: { name: 'Pen' } });
      expect(response.ok()).toBeTruthy();
    });
  11. 11. How do you mock or intercept network requests?

    Use page.route (or context.route) to fulfill, modify, or abort requests that match a URL pattern. Register the route before navigating. It makes tests deterministic by removing dependence on slow or unavailable back ends and lets you test error and empty states.

    await page.route('**/api/products', (route) =>
      route.fulfill({ status: 200, json: [{ id: 1, name: 'Mock' }] }));
  12. 12. How do you handle iframes, new tabs, and file downloads?

    For iframes use page.frameLocator('selector') and locate elements inside it. For popups and new tabs, wait for the event while clicking (const popupPromise = page.waitForEvent('popup')) and then use the new page. For downloads, wait for the download event, then inspect the file with download.saveAs or suggestedFilename.

  13. 13. What is the trace viewer?

    Playwright can record a trace: a timeline of every action with DOM snapshots before and after, network calls, console messages, and screenshots. Open it with npx playwright show-trace. A common setting is trace: 'on-first-retry', so failed CI runs include a trace you can step through.

  14. 14. How do you debug a failing Playwright test?

    Run with --debug to open the Playwright Inspector, or use UI mode (--ui) to step through, watch, and time-travel. Use the trace viewer for CI failures, page.pause() to stop at a point, codegen to record locators, and headed mode to watch the browser. Read the failure message first, since it usually names the locator and the condition that was not met.

  15. 15. What languages and test runners does Playwright support?

    Node.js (TypeScript and JavaScript) has Playwright Test, the full-featured runner. Python, Java, and .NET have official bindings that work with the usual runners (pytest, JUnit, NUnit, MSTest). Some features, such as the built-in runner's fixtures and test sharding, are specific to Playwright Test, so check the documentation for your language.

Interview Tips

  • Explain auto-waiting and web-first assertions; they are what make Playwright tests stable.
  • Have a clear comparison with Selenium ready, with honest trade-offs.
  • Mention how you debug with traces, since that is what CI failures need.