Playwright interview questions usually cover what Playwright is and how it differs from Selenium, locators and auto-waiting, assertions, fixtures and the test runner, network mocking, parallel runs and debugging flaky tests. This guide gives you 30 questions asked in automation testing interviews for freshers and testers moving from manual to automation, with short answers and TypeScript examples.
Key takeaways
- Playwright is an open-source browser automation framework from Microsoft that drives Chromium, Firefox and WebKit through one API.
- Auto-waiting and web-first assertions remove most of the sleeps and explicit waits that cause flaky tests.
- Prefer user-facing locators such as getByRole, getByLabel and getByText over long CSS or XPath selectors.
- Fixtures, projects and storageState let you share setup, run on several browsers and reuse a login.
- The trace viewer is the first tool to open when a test fails in CI.
The examples use the Playwright Test runner with TypeScript, which is what most Indian product companies and service teams use with Playwright. Python and Java bindings follow the same ideas. If you are coming from Selenium, our Selenium tutorial for beginners and manual vs automation testing guide give useful background.
Playwright basics
1. What is Playwright?
Playwright is an open-source framework for end-to-end testing and browser automation, maintained by Microsoft. One API drives Chromium (Chrome and Edge), Firefox and WebKit (the engine behind Safari), in headed or headless mode.
2. Which languages does Playwright support?
JavaScript and TypeScript, Python, Java and .NET (C#). The Playwright Test runner with its fixtures and reporters is part of the Node.js package. Other languages use their usual test frameworks, such as pytest or JUnit.
3. How is Playwright different from Selenium?
| Point | Playwright | Selenium |
|---|---|---|
| Waiting | Built-in auto-waiting | Explicit or implicit waits you write |
| Browser drivers | Browsers installed by the tool | Uses WebDriver; Selenium Manager can fetch drivers |
| Test runner | Included in Node.js package | Use TestNG, JUnit, pytest and others |
| Network mocking | Built in with page.route | Limited, usually needs extra tools |
| Ecosystem age | Newer | Older, very large community |
4. How do you install Playwright?
npm init playwright@latest
npx playwright install
npx playwright testThe first command creates a config file, an example test and an optional GitHub Actions workflow. The second downloads the browsers.
5. What are Browser, BrowserContext and Page?
A Browser is a running browser instance. A BrowserContext is an isolated session inside it, like a fresh incognito profile with its own cookies and storage. A Page is a single tab in a context. Playwright Test creates a new context for each test, which keeps tests independent.
6. Write a simple Playwright test.
import { test, expect } from '@playwright/test';
test('user can search', async ({ page }) => {
await page.goto('https://example.com');
await page.getByRole('searchbox').fill('playwright');
await page.getByRole('button', { name: 'Search' }).click();
await expect(page.getByRole('heading', { level: 1 })).toContainText('Results');
});Locators and waiting
7. What is a locator?
A locator is a way to find elements on the page at the moment of an action. It is lazy and re-evaluated every time you use it, so it still works after the page re-renders.
8. Which locators does Playwright recommend?
User-facing locators: getByRole, getByLabel, getByPlaceholder, getByText, getByAltText, getByTitle and getByTestId. They match how users and assistive technology see the page, so they break less often than CSS or XPath tied to layout.
9. When would you still use CSS or XPath?
When there is no accessible role, label or test id, for example in an old application. Keep the selector short and stable, and ask developers to add a data-testid attribute where possible.
10. What is auto-waiting?
Before an action such as click, Playwright waits until the element is attached, visible, stable, enabled and able to receive events. You rarely need manual waits, which removes a big source of flaky tests.
11. Why should you avoid page.waitForTimeout?
A fixed sleep either wastes time or is too short on a slow machine. Wait for a condition instead, such as a web-first assertion or a specific network response.
12. What is strictness in locators?
If a locator used for an action matches more than one element, Playwright throws an error instead of clicking the first one. Make the locator more specific, or use first(), last() or nth() deliberately.
13. How do you filter and chain locators?
const row = page.getByRole('row').filter({ hasText: 'Order 1042' });
await row.getByRole('button', { name: 'Cancel' }).click();Assertions
14. What are web-first assertions?
Assertions such as toBeVisible, toHaveText, toHaveURL and toHaveCount retry until the condition is true or the timeout expires. Always await them.
15. What is the difference between expect(locator).toHaveText and checking textContent?
toHaveText retries until the text matches. Reading textContent once and comparing gives you the value at one instant, which may be before the page has updated, so the test becomes flaky.
16. What is a soft assertion?
expect.soft records a failure but lets the test continue, so you can see several problems in one run. The test is still marked as failed at the end.
Test runner, fixtures and configuration
17. What is playwright.config.ts used for?
It sets the test folder, timeouts, retries, reporters, base URL, number of workers and projects. Settings in the use section, such as baseURL or trace, apply to every test.
18. What are fixtures?
Fixtures provide ready-made objects to a test, such as page, context, browser and request. You can define your own, for example a logged-in page or a test data helper, with setup and teardown in one place.
import { test as base } from '@playwright/test';
export const test = base.extend({
adminPage: async ({ browser }, use) => {
const context = await browser.newContext({ storageState: 'admin.json' });
const page = await context.newPage();
await use(page);
await context.close();
},
});19. What are projects?
Projects let one config run the same tests with different settings, for example in Chromium, Firefox and WebKit, or on desktop and mobile viewports, or against staging and production.
20. What are hooks in Playwright Test?
beforeEach, afterEach, beforeAll and afterAll run setup and cleanup code around tests. Prefer fixtures for reusable setup, because they are easier to share and compose.
21. How do you reuse a login across tests?
Log in once in a setup project, save the cookies and local storage with context.storageState({ path: 'user.json' }), and point other projects at that file. Tests then start already logged in.
22. How does Playwright run tests in parallel?
Test files run in parallel in separate worker processes by default. Set fullyParallel to run tests inside one file in parallel too, and control the number of workers in the config or with –workers.
23. How do you tag and run a subset of tests?
Add a tag such as @smoke to the test title or the tag option, then run npx playwright test –grep @smoke. You can also run one file, or one test by line number.
Network, API and advanced topics
24. How do you mock an API response?
await page.route('**/api/products', route =>
route.fulfill({ status: 200, json: [{ id: 1, name: 'Test item' }] })
);This lets you test the UI for empty lists, errors or slow responses without changing the backend.
25. Can Playwright test APIs directly?
Yes. The request fixture sends HTTP calls without a browser, which is useful for API checks and for creating test data quickly before a UI test.
26. How do you handle frames, new tabs and dialogs?
Use page.frameLocator for iframes. For a new tab, wait for the popup event while clicking the link. For alerts and confirms, register page.on('dialog') and accept or dismiss it.
27. How do you upload and download files?
Use setInputFiles on a file input to upload. For downloads, wait for the download event while clicking the download button, then save it with download.saveAs.
28. What is visual comparison testing in Playwright?
expect(page).toHaveScreenshot captures a screenshot and compares it with a stored baseline image. Small rendering differences between operating systems mean baselines are best generated in the same environment as CI, such as a Docker image.
Debugging and CI
29. How do you debug a failing Playwright test?
Run with –debug to step through in the Playwright Inspector, use –ui for UI mode with time-travel, and turn on traces with trace: 'on-first-retry'. Open a trace with npx playwright show-trace to see each action, DOM snapshot, console log and network call.
30. How do you handle flaky tests?
Find the cause instead of adding sleeps. Common causes are weak locators, assertions that do not retry, shared test data and dependence on test order. Use retries in CI only as a safety net, and track tests that pass only on retry.
How to prepare
- Automate one real flow end to end, such as login, search, add to cart and logout, on a practice site.
- Add a fixture, an API mock and a test that runs in three browsers.
- Run it in GitHub Actions and read the HTML report and trace from a failed run.
- Revise API basics with our API testing tools guide.
Frequently asked questions
Is Playwright better than Selenium for freshers?
Playwright is easier to start with because waiting, browsers and the test runner are built in. Selenium still appears in many job descriptions, so learning the concepts of both helps you in more interviews.
Should I learn Playwright with JavaScript or Python?
TypeScript or JavaScript is the most common choice and has the full Playwright Test runner. Choose Python if your team already uses pytest or you know Python well.
Is Playwright free to use?
Yes. Playwright is open source under the Apache 2.0 licence. Paid cloud services exist for running tests at scale, so check the provider's official site for their terms.
Do Playwright interviews include coding?
Often, yes. Expect to write a short test, choose locators for a given page, or explain how you would fix a flaky test.
Read more testing guides in our software testing section.
