Skill Booster

Quick Reference for Interviews...

Top 100 Playwright Interview Questions and Answers

Prepare for Playwright interviews with this complete FAQ guide. Learn how to automate browser testing, build resilient test suites, handle selectors, work with APIs, integrate with CI/CD, debug failures, and design scalable end-to-end automation solutions.

Q1: What is Playwright? basics

Playwright Fundamentals

Playwright is an open-source browser automation framework for end-to-end testing with cross-browser support for Chromium, Firefox, and WebKit.

Q2: Which browsers does Playwright support? basics

Browser Support

Playwright supports Chromium, Firefox, and WebKit on Windows, macOS, and Linux, including headless and headed modes.

Q3: What are Playwright selectors? selectors

Selectors

Selectors identify UI elements using CSS, text, XPath, role selectors, test IDs, and built-in locator strategies.

Q4: What is a Locator in Playwright? selectors

Selectors

A Locator is a Playwright API that represents a UI element and provides methods for actions and assertions with automatic waiting.

Q5: How do you launch a browser in Playwright? setup

Browser Setup

Use playwright.chromium.launch(), playwright.firefox.launch(), or playwright.webkit.launch() for browser instances, with options like headless and slowMo.

Q6: What is a browser context? architecture

Browser Context

A browser context is an isolated session within a browser instance, allowing parallel tests with separate cookies, storage, and cache.

Q7: How do you create a new page in Playwright? setup

Browser Setup

Use browser.newContext() followed by context.newPage() to create a new browser page for navigation and interaction.

Q8: What is Playwright Test? framework

Test Runner

Playwright Test is the official test runner that provides fixtures, test configuration, parallelism, retries, and built-in reports.

Q9: How does Playwright handle waiting? synchronization

Auto-waiting

Playwright auto-waits for elements, network events, and navigation, reducing the need for explicit waits in most cases.

Q10: What is the difference between locator.click() and page.click()? api

API usage

Locator.click() retries automatically and handles waiting better than page.click(), which is a lower-level action using selectors directly.

Q11: How do you wait for navigation in Playwright? navigation

Navigation

Use page.waitForNavigation(), or rely on actions like click() with waitUntil options to wait for page transitions.

Q12: What is network interception? network

Automation

Network interception allows you to monitor, modify, or stub HTTP requests and responses using route() and request interception APIs.

Q13: How do you mock network responses? network

Automation

Use page.route(url, route => route.fulfill({ status, contentType, body })) to mock API responses during tests.

Q14: How do you handle file uploads? forms

File Handling

Use input.setFiles(filePath) or locator.setInputFiles() to upload files through input elements in Playwright.

Q15: How do you download files? files

File Handling

Use page.waitForEvent('download') and download.path() or download.saveAs() to manage downloaded files.

Q16: What are test fixtures in Playwright? framework

Test Runner

Fixtures provide reusable setup and teardown logic for tests, such as browser, context, and page objects.

Q17: How do you run tests in parallel? framework

Performance

Configure workers in Playwright Test using the workers option or pass --workers to run tests in parallel across CPU cores.

Q18: How do you retry failing tests? framework

Stability

Use retries in test configuration or the retries option in test annotations to rerun flaky tests automatically.

Q19: How do you take screenshots? debugging

Debugging

Use page.screenshot({ path }) or locator.screenshot() to capture screenshots of pages or individual elements.

Q20: How do you record videos? debugging

Debugging

Enable video recording in browser context options so Playwright saves video artifacts for later review.

Q21: What is trace collection? debugging

Debugging

Trace collection records browser actions and network events to help debug test failures with Playwright Trace Viewer.

Q22: How do you use Playwright Trace Viewer? debugging

Debugging

Open the trace file with playwright show-trace to inspect step-by-step events, network calls, and DOM snapshots.

Q23: What is the Playwright Inspector? debugging

Debugging

Playwright Inspector is an interactive tool that pauses tests and lets you step through actions, inspect elements, and replay steps.

Q24: How do you handle popups and dialogs? dialogs

Automation

Use page.on('dialog', dialog => dialog.accept()) or dialog.dismiss() to handle alerts, confirms, and prompts.

Q25: How do you handle multiple pages or tabs? windows

Automation

Use context.waitForEvent('page') to catch new tabs and then interact with the returned Page object.

Q26: What is the difference between page and context? architecture

Browser Model

A context is an isolated browser session; a page is a single tab within that context.

Q27: How do you handle authentication in Playwright? security

Security

Use storage state, HTTP basic auth options, or intercept network requests to authenticate before tests run.

Q28: How do you use storage state? security

State Management

Save cookies and localStorage to a file with context.storageState() and reuse it when launching new contexts.

Q29: What is the difference between headless and headed mode? setup

Browser Modes

Headless mode runs without a visible UI for speed, while headed mode shows the browser window for debugging and visual checks.

Q30: How do you configure timeouts? reliability

Stability

Use setDefaultTimeout(), setDefaultNavigationTimeout(), or options like timeout when waiting or performing actions.

Q31: How do you handle flaky tests? reliability

Stability

Use retries, stable selectors, retries, and traces to diagnose and reduce flaky behavior.

Q32: What is a test hook in Playwright? framework

Test Runner

Test hooks like beforeEach and afterEach let you run setup and cleanup steps around each test.

Q33: How do you use test.describe? framework

Test Structure

test.describe groups tests together with shared setup, fixtures, and naming conventions.

Q34: What are annotations in Playwright Test? framework

Test Metadata

Annotations like test.skip, test.only, and test.fail mark how tests should execute or be reported.

Q35: How do you run a specific test file? cli

Execution

Run npx playwright test path/to/file.spec.ts or use grep to target tests by name.

Q36: How do you run tests in a specific browser? cli

Execution

Use --project=chromium, --project=firefox, or --project=webkit when running playwright test.

Q37: What is playwright.config.js? configuration

Settings

The config file defines projects, timeouts, retries, testDir, reporter settings, and shared options for Playwright Test.

Q38: How do you use multiple projects? configuration

Parallelism

Define multiple projects in config to run tests across browser types, devices, or parallel environments.

Q39: What is a reporter in Playwright? reports

Test Reports

Reporters format test output; built-in options include list, dot, json, html, and junit.

Q40: How do you generate HTML reports? reports

Test Reports

Configure the html reporter in playwright.config.js and run playwright show-report to view results in a browser.

Q41: How do you inspect element selectors? selectors

Automation

Use the Playwright Inspector and browser.devtools for the best selectors, and prefer role selectors or test IDs for stability.

Q42: What are role selectors? accessibility

Selectors

Role selectors use accessibility roles, such as page.getByRole('button', { name: 'Submit' }), for robust, human-readable targeting.

Q43: What is text selector? selectors

Selectors

Text selectors locate elements by visible text and can be used with page.getByText('Sign in') or the text= syntax.

Q44: How do you use nth selectors? selectors

Selectors

Use locator.nth(index) to select a specific instance of a matching locator when multiple elements match.

Q45: How do you wait for an element to be visible? synchronization

Auto-waiting

Use locator.waitFor({ state: 'visible' }) or expect(locator).toBeVisible() for explicit visibility checks.

Q46: How do you assert text content? assertions

Validation

Use expect(locator).toHaveText('expected text') to assert that the visible text matches the expected string.

Q47: How do you assert element count? assertions

Validation

Use expect(locator).toHaveCount(n) to verify the number of matching elements.

Q48: How do you fill forms? forms

Forms

Use locator.fill('value') or page.fill('selector', 'value') to set input values in form fields.

Q49: How do you select dropdown options? forms

Forms

Use locator.selectOption(value) or page.selectOption('select', value) to choose items from a dropdown.

Q50: How do you handle hovering? interactions

User Actions

Use locator.hover() to simulate mouse hover on an element before interacting with tooltips or menus.

Q51: How do you handle keyboard input? interactions

User Actions

Use page.keyboard.type('text') or locator.press('Enter') to simulate keyboard entry and key presses.

Q52: How do you handle mouse events? interactions

User Actions

Use page.mouse.click(x,y), mouse.move, or locator.click() to simulate mouse interactions in tests.

Q53: What are auto-waiting conditions? synchronization

Auto-waiting

Playwright auto-waits for elements to be actionable, stable, and attached before performing actions like click or type.

Q54: How do you evaluate JavaScript in the page? advanced

Advanced

Use page.evaluate(fn) to execute JavaScript in the browser context and return results to the test runner.

Q55: How do you access element attributes? selectors

Automation

Use locator.getAttribute('name') or page.evaluate(() => element.getAttribute('name')) to read attributes.

Q56: How do you handle hover-triggered menus? interactions

Automation

Use locator.hover() then click the submenu item once it becomes visible to interact with hover-triggered UIs.

Q57: How do you handle custom browser launch arguments? setup

Customization

Pass args to launch() or newContext() to enable browser features, disable sandbox, or configure proxy settings.

Q58: How do you use browser context permissions? security

Security

Set permissions in context options for geolocation, notifications, camera, and microphone access during tests.

Q59: What is the playwright install command? setup

Installation

Run npm install -D @playwright/test followed by npx playwright install to install browsers and test dependencies.

Q60: How do you run Playwright tests on GitHub Actions? ci

CI/CD

Use actions/setup-node and npx playwright install --with-deps in a workflow, then run npx playwright test to execute tests.

Q61: How do you test mobile devices? devices

Cross-platform

Use device descriptors in projects, such as iPhone 13 or Pixel 5, to emulate mobile browsers in Playwright.

Q62: How do you test with geolocation? devices

Cross-platform

Set geolocation in context options and grant geolocation permission to simulate location-based behavior.

Q63: How do you use cookies with Playwright? state

State Management

Use context.addCookies() or context.storageState() to manage cookies and session data during tests.

Q64: How do you handle secure origins? security

Security

Use context options for ignoreHTTPSErrors and set baseURL to test HTTPS apps or self-signed certificates.

Q65: What is the difference between Playwright and Selenium? comparison

Comparison

Playwright is modern, handles auto-waiting, supports multiple browsers in one API, and has built-in test runner; Selenium is older and requires more manual waits.

Q66: What is the difference between Playwright and Cypress? comparison

Comparison

Playwright supports multiple browsers and cross-process automation, while Cypress is browser-limited and runs within the browser process.

Q67: How do you use playwright CLI? cli

Execution

Use npx playwright test, npx playwright codegen, npx playwright show-report, and other commands for test execution and debugging.

Q68: What is codegen in Playwright? debugging

Debugging

playwright codegen opens a browser and records actions as code, helping create initial test scripts quickly.

Q69: How do you handle browser alerts? dialogs

Automation

Use page.on('dialog', dialog => dialog.accept()) to handle alerts and confirm dialogs during tests.

Q70: How do you use locators for nested elements? selectors

Selectors

Chain locators with locator.locator('selector') or use locator.filter() to target nested or filtered child elements.

Q71: How do you capture browser console logs? debugging

Debugging

Use page.on('console', msg => ...) to listen for console messages and record them during tests.

Q72: How do you capture network requests? network

Debugging

Use page.on('request') and page.on('response') to inspect outgoing and incoming network traffic.

Q73: How do you handle single-page applications? advanced

SPA Testing

Use waitForLoadState(), URL assertions, and stable locators to handle dynamic navigation in SPAs.

Q74: How do you test dynamic content? advanced

SPA Testing

Wait for elements or API responses, then assert final state with locator conditions and expect matchers.

Q75: How do you use fixture parameters? framework

Test Runner

Define fixtures in test.extend() and use parameterized fixtures for reusable test setup across environments.

Q76: What is test.parallel in Playwright? framework

Parallel Execution

test.parallel() allows tests within a describe block to run concurrently in the same worker for faster execution.

Q77: How do you use fixtures for page objects? design

Test Design

Use fixtures to provide page objects and reusable helpers to tests, improving maintainability.

Q78: How do you manage test data? design

Test Design

Use separate test data files, fixtures, and setup hooks to keep test data organized and reusable.

Q79: How do you test file uploads in headless mode? files

Automation

Use locator.setInputFiles() with absolute file paths and ensure the page input is visible or attachable in headless mode.

Q80: How do you use request fixtures? network

Automation

Use page.route() in fixtures to stub network responses and keep tests deterministic.

Q81: How do you integrate Playwright with CI? ci

CI/CD

Configure CI pipelines to install dependencies, browsers, and run playwright test with reporting or artifact uploads.

Q82: How do you run tests on multiple browsers in CI? ci

CI/CD

Use projects in playwright.config.js and run tests once; CI will execute each browser project separately.

Q83: How do you use Playwright with Docker? deployment

Containerization

Install Playwright browsers in the Docker image and run tests inside the container with proper libraries and display options.

Q84: How do you secure Playwright tests? security

Security

Keep credentials out of code, use environment variables, and avoid storing sensitive data in logs or screenshots.

Q85: How do you measure test performance? performance

Maintenance

Track execution time, reduce unnecessary waits, and use parallel workers to improve test suite performance.

Q86: How do you debug tests locally? debugging

Debugging

Run tests with --debug or use test.only and page.pause() to inspect test execution in Playwright Inspector.

Q87: What is browserContext.overridePermissions? security

Security

The overridePermissions API grants permissions like geolocation or notifications within a browser context for tests.

Q88: How do you test offline behavior? network

Network

Use browserContext.setOffline(true) or intercept network requests to simulate offline conditions.

Q89: How do you work with iframes? advanced

Advanced

Use frame = page.frame({ name: 'frameName' }) or locator.frameLocator() to interact with iframe content.

Q90: How do you validate page title? assertions

Validation

Use expect(page).toHaveTitle('expected title') to assert the page title matches the expected string.

Q91: How do you test authentication flows? security

Security

Use storage state, login helpers, and API call stubbing to test login/logout flows consistently.

Q92: How do you test browser dialogs? dialogs

Automation

Set up page.on('dialog') handlers before actions that trigger dialogs to accept or dismiss them.

Q93: How do you handle lazy-loaded content? advanced

Automation

Wait for the specific element or network event that loads lazy content before asserting its presence.

Q94: How do you use test step reporting? reports

Reporting

Use test.step() to group actions and make reports more readable by adding named steps in test output.

Q95: How do you capture device metrics? devices

Cross-platform

Use context options with device descriptors to emulate viewport size, user agent, and device scale factor.

Q96: How do you configure baseURL? configuration

Settings

Set baseURL in playwright.config.js for shorter page.goto() calls and easier environment switching.

Q97: How do you use test fixtures to share data? design

Test Design

Define shared fixtures in test.extend() and pass them into tests to reuse setup data and helpers.

Q98: How do you test animations and transitions? advanced

Automation

Use waitForTimeout or element state assertions to wait until animations complete before verifying UI state.

Q99: What are the best practices for Playwright tests? best practices

Guidelines

Use stable selectors, isolate tests with fresh contexts, keep tests small, and add useful artifacts for debugging failures.

Q100: How do you scale Playwright automation? best practices

Guidelines

Scale tests by organizing suites, using parallel workers, integrating with CI, and separating page objects from test logic.