Playwright interview questions for freshers start with setup and a first test, then move to locators, auto-waiting and assertions. Some interviewers also ask about the config file, traces and API tests. This page has 25 questions with short answers and TypeScript examples written for Playwright Test.
Snippets assume a project created with npm init playwright@latest. Each test file starts with import { test, expect } from '@playwright/test';, which is left out of short snippets.
How to answer Playwright interview questions
Explain what the tool does for you, then what you still decide. "Playwright waits for a button to be visible and enabled before clicking. I still choose a stable locator and assert the result."
Pro tip: Every Playwright action is async. Forgetting
awaitis the most common mistake in live coding rounds, so say it before the interviewer does.
Playwright basics questions
Q1. What is Playwright?
30-second answer: Playwright is an open-source framework from Microsoft for end-to-end testing of web apps. One API drives Chromium, Firefox and WebKit. It supports TypeScript and JavaScript, Python, Java and .NET, and comes with its own test runner called Playwright Test.
Q2. What are the main features of Playwright?
| Feature | What it means |
|---|---|
| Cross-browser | Chromium, Firefox and WebKit with one API |
| Auto-waiting | Waits for elements to be ready before acting |
| Web-first assertions | expect retries until the condition is true or times out |
| Browser contexts | Each test gets a fresh, isolated browser profile |
| Tracing | Records steps, DOM snapshots and network for debugging |
| Codegen | Records your clicks and writes test code |
| API testing | Sends HTTP requests with the request fixture |
30-second answer: The two features interviewers ask about most are auto-waiting and web-first assertions, because they remove most timing problems.
Q3. How do you set up Playwright?
30-second answer: Run the init command in a project folder. It installs Playwright Test, creates a config file and example tests, and offers to download the browsers.
npm init playwright@latest
npx playwright test
npx playwright show-report
The second command runs all tests. The third opens the HTML report. If browsers are missing, npx playwright install downloads them.
Q4. Write your first Playwright test.
import { test, expect } from '@playwright/test';
test('home page has the right title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});
test('get started link opens the installation page', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.getByRole('link', { name: 'Get started' }).click();
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
30-second answer: test defines a test. { page } is a fixture that gives a fresh page. goto opens the URL, and expect checks the result. Each action uses await.
Q5. What is headless mode, and how do you see the browser?
30-second answer: Headless means the browser runs without a visible window. Playwright Test runs headless by default, which is faster and suits CI. Use npx playwright test --headed to see the browser, or --ui to open UI mode, where you can run tests one by one and watch each step.
Q6. What is codegen?
30-second answer: Codegen opens a browser, records your actions and writes test code with suggested locators.
npx playwright codegen https://playwright.dev/
It is useful for finding locators and starting a test quickly. You still clean up the code, add assertions and move steps into page objects.
Locator questions
Q7. What is a locator in Playwright?
30-second answer: A locator describes how to find an element. It does not search the page when you create it. It finds the element at the moment you act on it, so it works even after the page re-renders.
const saveButton = page.getByRole('button', { name: 'Save' });
await saveButton.click();
Q8. Which built-in locators does Playwright recommend?
| Locator | Finds by |
|---|---|
getByRole |
Accessible role and name, such as a button named Save |
getByText |
Visible text |
getByLabel |
Form control linked to a label |
getByPlaceholder |
Input placeholder |
getByAltText |
Image alt text |
getByTitle |
Title attribute |
getByTestId |
data-testid attribute by default |
30-second answer: Playwright recommends getByRole first, because it matches how users and screen readers see the page. Use getByTestId when there is no good role or text. CSS and XPath work through page.locator(), but they break more easily.
Q9. What does it mean that locators are strict?
30-second answer: If an action such as click or fill matches more than one element, Playwright throws an error instead of picking the first one. This stops a test from silently clicking the wrong element. Make the locator more specific, or use .first(), .nth() or .filter() when you really mean one of several.
await page.getByRole('listitem').filter({ hasText: 'Pen' }).click();
Q10. How do you fill a form and submit it?
test('user can log in', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill('asha@example.com');
await page.getByLabel('Password').fill('Valid@123');
await page.getByRole('button', { name: 'Log in' }).click();
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
});
30-second answer: fill clears the field and types the value. The relative URL /login works when baseURL is set in the config. The last line checks that login worked.
Auto-waiting and assertion questions
Q11. What is auto-waiting?
30-second answer: Before an action, Playwright checks that the element is ready. For a click, it waits until the element is visible, stable (not animating), able to receive events and enabled. If the checks do not pass within the timeout, the action fails with a clear message.
This is why Playwright tests rarely need manual waits.
Q12. What are web-first assertions?
30-second answer: Assertions such as toBeVisible, toHaveText and toHaveURL keep retrying until the condition is true or the timeout ends. The default assertion timeout is 5 seconds.
await expect(page.getByText('Order placed')).toBeVisible();
await expect(page).toHaveURL(/\/orders\//);
await expect(page.getByRole('listitem')).toHaveCount(3);
Q13. Why should you avoid waitForTimeout?
30-second answer: page.waitForTimeout(3000) always waits three seconds. It slows the test and still fails if the app takes four. Wait for a real condition instead, using an assertion or a locator action. The Playwright docs warn that tests which wait for a fixed time are flaky.
Q14. What is the difference between expect(locator).toBeVisible() and await locator.isVisible()?
30-second answer: toBeVisible() retries until the element appears or the timeout ends. isVisible() checks once, right now, and returns true or false. In assertions, use toBeVisible(). Use isVisible() only when you need an instant check to choose a path.
Test structure questions
Q15. What are fixtures?
30-second answer: Fixtures give each test what it needs and clean up after it. Built-in fixtures include page, context, browser, browserName and request. You can create your own fixtures, for example a logged-in page or a page object, with test.extend.
Q16. What is a browser context?
30-second answer: A browser context is an isolated browser session, like a fresh incognito profile with its own cookies and storage. Playwright Test gives every test a new context, so tests do not share login state or data. Contexts are cheap to create, so isolation does not cost much time.
Q17. How do you group tests and use hooks?
test.describe('cart', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/shop');
});
test('add one item', async ({ page }) => {
await page.getByRole('button', { name: 'Add Pen to cart' }).click();
await expect(page.getByTestId('cart-count')).toHaveText('1');
});
});
30-second answer: test.describe groups tests. beforeEach and afterEach run around every test in the group. beforeAll and afterAll run once per worker for the group.
Q18. What goes in playwright.config.ts?
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
retries: process.env.CI ? 2 : 0,
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
],
});
30-second answer: The config sets the test folder, retries, shared options such as baseURL, traces and screenshots, and projects. Each project runs the tests with different settings, here three browsers.
Q19. How does Playwright run tests in parallel?
30-second answer: Playwright Test runs test files in parallel using worker processes. Tests inside one file run one after another by default. Set fullyParallel: true to run those in parallel too. Use --workers=1 when you need to run everything in sequence, for example while debugging.
Debugging and advanced basics
Q20. What is the trace viewer?
30-second answer: A trace records each action with DOM snapshots, screenshots, console logs and network calls. With trace: 'on-first-retry', a trace is saved when a failed test is retried. Open it from the HTML report or with npx playwright show-trace trace.zip and step through what happened.
Q21. How do you debug a failing test?
30-second answer: Run npx playwright test --debug to step through with the Playwright Inspector, or use UI mode with --ui. Check the trace, screenshot and error message. Most failures are a wrong locator, a missing await or a test that depends on data from another test.
Q22. How do you handle a new tab or popup?
const pagePromise = page.context().waitForEvent('page');
await page.getByRole('link', { name: 'Open invoice' }).click();
const invoicePage = await pagePromise;
await expect(invoicePage).toHaveTitle(/Invoice/);
30-second answer: Start waiting for the new page before the click, then click, then await the promise. If you wait after the click, you can miss the event.
Q23. How do you mock a network response?
30-second answer: Use page.route to catch a request and return your own response. This tests the UI without depending on a real backend.
await page.route('**/api/products', async (route) => {
await route.fulfill({ json: [{ id: 1, name: 'Pen' }] });
});
await page.goto('/shop');
await expect(page.getByText('Pen')).toBeVisible();
Q24. Can Playwright test APIs?
30-second answer: Yes. The request fixture sends HTTP requests without a browser. It is useful for API tests and for creating test data before a UI test.
test('get product 1', async ({ request }) => {
const response = await request.get('/api/products/1');
expect(response.ok()).toBeTruthy();
const body = await response.json();
expect(body.name).toBe('Pen');
});
The API testing interview questions page covers status codes and test design for APIs.
Q25. How is Playwright different from Selenium?
| Point | Playwright | Selenium |
|---|---|---|
| Waiting | Auto-waits before actions | Explicit waits written by you |
| Test runner | Built in (Playwright Test) | Uses TestNG, JUnit, pytest and others |
| Browsers | Chromium, Firefox, WebKit | Chrome, Firefox, Edge, Safari and others |
| Languages | TS/JS, Python, Java, .NET | Java, Python, C#, JS, Ruby and others |
| Debugging | Trace viewer, UI mode | Depends on your tools |
| Protocol | Its own connection to each browser | W3C WebDriver standard |
30-second answer: Playwright gives more built in and handles timing for you. Selenium follows the W3C WebDriver standard and has a larger existing user base. Say which one you used and why. A longer comparison is in Selenium vs Playwright. The Selenium interview questions page covers the other side.
Common mistakes in Playwright interviews
| Mistake | Better habit |
|---|---|
Missing await before an action |
Await every action and assertion |
Using waitForTimeout to fix flaky tests |
Assert on a real condition |
| Long CSS or XPath locators | Prefer getByRole, getByLabel, getByTestId |
| Tests that depend on each other | Give each test its own data and context |
| Checking only that no error appeared | Assert the actual result on the page |
How to prepare in one week
| Day | Task |
|---|---|
| 1 | JavaScript basics and async/await |
| 2 | Install Playwright and run the example tests |
| 3 | Write five tests with getByRole and getByLabel |
| 4 | Assertions, hooks and page objects |
| 5 | Config, projects, traces and the HTML report |
| 6 | One mocked route and one API test |
| 7 | Revise this page and do a mock interview |
If async code still feels unclear, read promises and async/await interview questions first. For framework design and the bigger picture, go back to automation testing interview questions.

