Playwright interviews usually test five things: how auto-waiting works, how you choose locators, how you keep tests independent (fixtures, contexts, saved login), how you handle network and API calls, and how you debug flaky tests in CI. Below are 28 questions with short answers. We ran every code sample on Playwright 1.65.1 on 15 Nov 2026 and quote the real output.
Table of Contents
Table of Contents
Most interview lists give you a sentence per question and no proof. We wanted answers you can say out loud and defend if the interviewer asks “have you actually done that?” So we built a small Demo Shop page, wrote tests for it, and ran them. Where an answer comes from the Playwright docs and we did not run it, we say so.
This guide is for QA engineers and SDETs preparing for Playwright rounds. For the wider interview (coding, framework design, behavioral), see our SDET interview questions. If you are still choosing a tool, start with Selenium vs Playwright.
How we tested these Playwright interview answers
Setup: Playwright Test 1.65.1 on Node.js, headless Chrome, on a Linux container with 2 CPU cores. The Demo Shop is one HTML page plus a tiny Node server. It has a login form (the token is saved in localStorage), a product list loaded from /api/products after an 800 ms delay, a cart, a “Clear cart” button that opens a confirm dialog, a checkout that posts to /api/orders, a link that opens a new tab, and an iframe with its own button. All timings below are single runs on this machine, so treat them as examples, not benchmarks.
Basic Playwright interview questions
1. What is Playwright and how is it different from Selenium?
Playwright is an open-source browser automation library from Microsoft that comes with its own test runner, Playwright Test. It controls Chromium, Firefox and WebKit, and you can write tests in JavaScript or TypeScript, Python, Java or .NET. Selenium is a browser automation library too, but you normally pair it with a separate runner and assertion library. The practical differences interviewers want to hear: Playwright waits for elements automatically, runs files in parallel by default, and records traces for debugging. Our Selenium vs Playwright and Cypress vs Playwright guides have the full comparison with code.
2. What is auto-waiting?
Before an action such as click or fill, Playwright checks that the element is ready. Per the docs the checks include visible, stable, receives events and enabled, and the locator must match exactly one element. If the checks do not pass before the timeout, the action fails with a TimeoutError.
We tested it with the Checkout button, which starts disabled. A timer enabled it 1.2 seconds after the test began, and the test simply called click():
const checkout = page.getByRole('button', { name: 'Checkout' });
await expect(checkout).toBeDisabled();
setTimeout(() => page.evaluate(() => { document.getElementById('checkout').disabled = false; }), 1200);
const t0 = Date.now();
await checkout.click();
console.log('click returned after', Date.now() - t0, 'ms');Result: click returned after 1,368 ms. No sleep, no retry loop. The click waited until the button became enabled, then clicked. That is the answer: the wait is built into the action and ends as soon as the element is ready.
3. What is the difference between isVisible() and expect(locator).toBeVisible()?
isVisible() checks once and returns immediately. expect(...).toBeVisible() is a web-first assertion that keeps retrying until the condition is true or the expect timeout runs out. The best-practices page in the docs tells you to prefer web-first assertions.
In our run, right after login the products had not loaded yet (the API has an 800 ms delay):
const now = await page.getByRole('button', { name: 'Add to cart' }).first().isVisible();
// now === false, returned after 12 ms
await expect(page.getByRole('button', { name: 'Add to cart' })).toHaveCount(3); // waits, then passesisVisible() returned false after 12 ms, even though the buttons appeared about 800 ms later. If you use it as a wait, you get a flaky test. Use it only when you really want a snapshot, for example to decide whether to close an optional cookie banner.
4. Is waitForTimeout() ever acceptable?
Only while debugging. A fixed sleep is either too short (flaky) or too long (slow), and it hides the real condition you are waiting for. Wait for that condition instead: an assertion such as toHaveText, a locator action, or page.waitForResponse() when the signal is a network call. This one is our opinion, not a docs quote, but it is the answer most interviewers expect.
5. What are Browser, BrowserContext and Page?
A browser is the running browser process. A context is an isolated, incognito-like profile with its own cookies and storage. A page is a tab inside a context. Playwright Test gives each test a fresh context and page by default, which is why tests do not leak state into each other.
We checked isolation by logging in inside one context and opening the site in a second context:
const c1 = await browser.newContext({ baseURL: 'http://127.0.0.1:8766' });
const c2 = await browser.newContext({ baseURL: 'http://127.0.0.1:8766' });
// log in on p1 (context 1), only open the site on p2 (context 2)
// token in context 1: "abc" token in context 2: nullContext 1 held the login token and context 2 had none. Two users in one test is the typical reason to create a second context yourself, for example a chat between a customer and an agent.
Locator and assertion interview questions
6. Which locators do you prefer, and why?
User-facing ones first: getByRole, getByLabel, getByText, then getByTestId when there is no good accessible name, and CSS or XPath last. The docs say to prefer user-facing attributes because they survive refactors and match what a user sees. A bonus point: getByRole failing to find a button can be a real accessibility bug.
await page.getByLabel('User').fill('demo');
await page.getByLabel('Password').fill('secret123');
await page.getByRole('button', { name: 'Log in' }).click();7. What is strict mode, and how do you fix a strict mode violation?
A locator used for an action must match exactly one element. If it matches more, Playwright throws instead of guessing. Our product list has three “Add to cart” buttons, so this fails:
await page.getByRole('button', { name: 'Add to cart' }).click();The real error starts with: strict mode violation: getByRole('button', { name: 'Add to cart' }) resolved to 3 elements. Fix it by narrowing to the right row, not by adding .first() unless the order is the point:
await page.getByRole('listitem').filter({ hasText: 'USB-C hub' })
.getByRole('button', { name: 'Add to cart' }).click();
await expect(page.getByRole('status')).toHaveText('Cart: 1 item');8. What are the default timeouts?
From the Playwright docs (test timeouts page): the test timeout is 30 seconds, the expect timeout is 5 seconds, and action, navigation and global timeouts are not set by default. Interviewers like to ask what happens when each one runs out, so we triggered both.
An assertion that cannot become true (we shortened its timeout to 1.5 s) fails with expect(locator).toBeVisible() failed and a call log. A whole test that waits too long (we set the test timeout to 3 s) fails with:
Test timeout of 3000ms exceeded.
Error: locator.click: Test timeout of 3000ms exceeded.
- waiting for getByRole('button', { name: 'Does not exist' })The second message is the one you see most in real life: the test ran out of time while a locator action was still waiting. Read the “waiting for” line first, it names the locator that never became ready.
9. What are soft assertions?
A normal expect stops the test at the first failure. expect.soft records the failure and keeps going, so one run reports every failed check. The docs recommend them for checking several independent things on one page.
await expect.soft(page.getByTestId('welcome')).toHaveText('Wrong text');
await expect.soft(page.getByRole('heading')).toHaveText('Nope');
await expect(page.getByTestId('welcome')).toBeVisible();Our run reported two separate errors from the same test (Expected “Wrong text”, received “Welcome back!”; expected “Nope”, received “Demo Shop”). The test is still marked failed. Use soft assertions for reports and form checks, not for steps that later steps depend on.
Fixture, page object and login interview questions
10. What is a fixture?
A fixture is setup and teardown code that Playwright Test hands to a test through its arguments. page, context and request are built-in fixtures. You can add your own with test.extend. Here is a fixture that gives a test an already logged-in shop page:
// fixtures.js
const base = require('@playwright/test');
exports.test = base.test.extend({
shopPage: async ({ page }, use) => {
await page.goto('/');
await page.getByLabel('User').fill('demo');
await page.getByLabel('Password').fill('secret123');
await page.getByRole('button', { name: 'Log in' }).click();
await base.expect(page.getByTestId('welcome')).toBeVisible();
await use(page); // the test runs here
},
});
exports.expect = base.expect;
// shop.spec.js
const { test, expect } = require('./fixtures');
test('fixture gives a logged-in page', async ({ shopPage }) => {
await shopPage.getByRole('listitem').filter({ hasText: 'Webcam' })
.getByRole('button', { name: 'Add to cart' }).click();
await shopPage.getByRole('button', { name: 'Checkout' }).click();
await expect(shopPage.locator('#result')).toHaveText(/Order #\d+ placed/);
});The test passed. The point to make in the interview: the fixture runs only for tests that ask for it, and code after use() is your teardown.
11. Fixtures or beforeEach? And where do page objects fit?
beforeEach runs for every test in its scope, whether the test needs it or not. A fixture is requested by name, can depend on other fixtures, and cleans up after itself. Page objects (classes that wrap a page’s locators and actions) still work well, and they combine with fixtures: build the page object inside a fixture and give it to the test. A small page object that we ran:
class ShopPage {
constructor(page) {
this.page = page;
this.user = page.getByLabel('User');
this.pass = page.getByLabel('Password');
this.logIn = page.getByRole('button', { name: 'Log in' });
this.cart = page.getByRole('status');
}
async login(u, p) { await this.page.goto('/'); await this.user.fill(u); await this.pass.fill(p); await this.logIn.click(); }
async add(product) {
await this.page.getByRole('listitem').filter({ hasText: product })
.getByRole('button', { name: 'Add to cart' }).click();
}
}Keep assertions in the test, not in the page object, so the test still reads like a description of behavior. That is our preference; some teams put checks in page objects, and an interviewer may push back. Be ready to explain the trade-off.
12. How do you log in once and reuse it across tests?
Save the browser state after logging in and load it in new contexts. storageState saves cookies and local storage. The docs recommend doing the login once in a dedicated setup project and pointing your test projects at the saved file. We tested the core idea:
await context1.storageState({ path: 'auth.json' }); // after logging in
const context2 = await browser.newContext({ storageState: 'auth.json' });
const page2 = await context2.newPage();
await page2.goto('/');
await expect(page2.getByTestId('welcome')).toBeVisible(); // no login form neededThe second context showed the shop straight away. Two warnings from the docs worth repeating: the file can contain sensitive cookies and headers, so add it to .gitignore, and session storage is not saved by storageState. We did not run the setup-project configuration, so for that part, follow the docs.
13. How do you handle test data when tests run in parallel?
Each test should create the data it needs and not depend on another test. Creating data through the API is faster and less fragile than clicking through the UI. The docs also suggest one account per parallel worker when tests change shared server-side state. In our demo, the request fixture can create an order directly (see question 16).
Network mocking and API testing interview questions
14. How do you mock an API response?
Use page.route() before the request is made, then route.fulfill() with your own data. We replaced the three-product list with one product:
await page.route('**/api/products', route => route.fulfill({
json: [{ id: 9, name: 'Mock mouse', price: 1 }],
}));
await login(page);
await expect(page.getByText('Mock mouse - $1')).toBeVisible();
await expect(page.getByRole('button', { name: 'Add to cart' })).toHaveCount(1);Both assertions passed: only the mocked product appeared. Register the route before the navigation or action that triggers the request.
15. How do you test the error path of a feature?
Make the request fail. route.abort() simulates a network failure, and route.fulfill({ status: 500 }) simulates a server error:
await page.route('**/api/products', route => route.abort());
await login(page);
await expect(page.getByText('Could not load products')).toBeVisible();The page showed its error message and the test passed. Error paths are hard to trigger against a real backend, so mocking is the normal way to cover them.
16. How do you test an API with Playwright, and do you need a browser?
No browser is needed. The request fixture sends HTTP calls with the same runner, reporters and retries:
const r = await request.post('/api/orders', { data: { items: 2 } });
expect(r.status()).toBe(201);
expect((await r.json()).items).toBe(2);
const list = await request.get('/api/orders');
expect((await list.json()).length).toBeGreaterThan(0);The order was created with status 201 and the list endpoint returned it. This is useful for setting up test data, checking a UI action with a backend call, or running a small API smoke suite. For a dedicated API-testing tool comparison, see best API testing tools.
17. When should you mock, and when should you use the real backend?
Mock what you do not control (payment providers, email, third-party APIs), and what is hard to trigger (errors, slow responses, rare data). Use the real backend for a small number of end-to-end flows so you still prove the pieces work together. The Playwright docs say the same: do not test third-party dependencies, mock them instead. How many real end-to-end flows you keep is a judgment call; say that you would keep the few that protect revenue or sign-up.
Frames, new tabs and dialogs interview questions
18. How do you work with an iframe?
Use frameLocator() to point at the frame, then use normal locators inside it. Auto-waiting applies inside frames too.
await page.frameLocator('iframe[title="Help"]')
.getByRole('button', { name: 'Contact support' }).click();The click worked on our embedded help page. Giving the iframe a title (an accessibility good practice) also gives you a stable selector.
19. How do you handle a link that opens a new tab?
Start waiting for the new page before you click, so you cannot miss the event:
const [tab] = await Promise.all([
context.waitForEvent('page'),
page.getByRole('link', { name: 'Terms' }).click(),
]);
await expect(tab.getByRole('heading')).toHaveText('Terms of use');The new tab opened at /terms.html and the heading assertion passed. The common mistake is clicking first and then waiting, which can miss a fast event.
20. How do you handle a JavaScript alert, confirm or prompt?
Register a dialog handler before the action that opens the dialog, then accept or dismiss it:
page.once('dialog', async d => { console.log(d.type(), d.message()); await d.accept(); });
await page.getByRole('button', { name: 'Clear cart' }).click();
await expect(page.getByRole('status')).toHaveText('Cart: 0 items');The handler saw confirm with the message “Clear the cart?” and the cart emptied after we accepted it.
Flaky tests, retries and CI interview questions
21. What happens when a test is retried, and how is a flaky test reported?
With retries set, a failed test runs again. If it passes on a retry, Playwright marks it flaky rather than passed or failed. We ran three tests with --retries=2: one that fails only on the first attempt, one that always fails, and one that passes. The output (file names removed):
✘ fails once then passes
✓ fails once then passes (retry #1)
✘ always fails
✘ always fails (retry #1)
✘ always fails (retry #2)
✓ passes
1 failed (always fails)
1 flaky (fails once then passes)
1 passedA strong answer adds the caveat: retries keep the pipeline green but hide the problem. Track the flaky list, fix the causes, and do not raise retries to cover bad tests. Our GitHub Actions for test automation guide shows a CI setup.
22. What is the Trace Viewer, and when do you record traces?
A trace is a zip file with a timeline of actions, screenshots, DOM snapshots, network calls and the call log, which you open with npx playwright show-trace. Recording a trace for every test is expensive. The docs recommend recording on the first retry of a failed test, and to use traces on CI instead of videos and screenshots. We tested the setting:
// playwright.config.js
module.exports = { retries: 1, use: { trace: 'on-first-retry' } };With one test that fails once and two stable tests, only one trace.zip was created: for the retry of the flaky test. The tests that passed first time left no trace. For comparison, a single test run with --trace=on produced an 80 KB trace.zip, so tracing everything adds up on a large suite.
23. How does Playwright run tests in parallel?
Test files run in parallel across workers. Tests inside one file run in order in the same worker, unless you set fullyParallel: true (globally or per project) or use test.describe.configure({ mode: 'parallel' }). We checked with two files of three tests and two workers, printing the worker index:
| Config | p1 a / b / c | p2 a / b / c |
|---|---|---|
Default (fullyParallel off) | worker 0 / 0 / 0 | worker 1 / 1 / 1 |
fullyParallel: true | worker 0 / 1 / 1 | worker 0 / 1 / 0 |
By default each file stayed on one worker. With fullyParallel the tests of one file spread over both workers. The consequence to mention: if your tests in a file depend on each other, fullyParallel will break them, which is a sign they should be independent.
24. What is sharding, and when do you need it?
Sharding splits a suite across machines with --shard=1/3, --shard=2/3 and so on, each CI job running one slice. You need it when one machine takes too long even with parallel workers. We ran two files of three tests each (with fullyParallel on) as two shards:
npx playwright test --shard=1/2 # ran p1.spec.js (3 tests)
npx playwright test --shard=2/2 # ran p2.spec.js (3 tests)Each shard ran a different set of three tests, and together they covered all six. On real CI, each shard also produces its own report, so you need a step that merges them; check the docs for the current merge workflow, we did not run that part.
25. A test passes locally but fails in CI. What do you do?
This is a process question, so answer in steps. This is our approach, not a docs quote:
- Open the trace from the failed run first (this is why
on-first-retryis worth having). The call log shows which locator or assertion timed out. - Compare the environments: browser version, viewport, locale and time zone, CPU speed (CI machines are often slower), and the number of workers.
- Check the data: does the test rely on data another test creates or changes? Does CI use a different database state?
- Reproduce it: run the same command with the same worker count, ideally inside the same container image.
- Fix the cause (a missing wait on a real condition, shared state, an unmocked third party), not the symptom. A longer timeout is a last resort.
Senior and scenario Playwright interview questions
26. How would you structure a Playwright framework for a team of 30?
There is no single right answer. A solid outline, in our opinion:
- One config with projects for the browsers you support and, if needed, mobile viewports.
- Custom fixtures for login, test data and page objects, so tests stay short.
- Test data created through the API, not through slow UI steps.
- Tags or folders to split smoke tests (every pull request) from the full regression (nightly).
- Trace on first retry, a flaky-test report, and a rule that a flaky test gets fixed or quarantined within an agreed time.
- Sharded CI jobs, and a place where all engineers can read failure reports.
27. When would you not use Playwright?
Playwright automates web browsers, including mobile browser emulation. In practice it is not the tool for native mobile or desktop apps, which need other tools. It may also not be worth adding to a team that has a healthy Selenium suite and no pain from it, because a migration has a cost. And for pure API checks a dedicated API tool can be simpler. An honest answer to this question shows judgment more than loyalty to a tool. For the migration case see Playwright vs Puppeteer and Selenium vs Playwright.
28. What do you know about AI-assisted Playwright testing?
Interviewers increasingly ask whether you have used AI to write or maintain tests, and what you check before you trust the output. A good answer is balanced: AI can draft locators and tests quickly, but you still review for stable locators, real assertions and independence between tests. We cover Playwright’s MCP server and test agents in our guide to Playwright AI test agents and MCP.
Playwright interview cheat sheet
| Topic | One-line answer | What we ran |
|---|---|---|
| Auto-waiting | Actions wait for the element to be ready; the check ends as soon as it is. | click on a disabled button returned after 1,368 ms |
| isVisible vs toBeVisible | isVisible does not wait; the assertion retries. | isVisible returned false after 12 ms |
| Strict mode | Actions need exactly one match; narrow the locator. | 3 matches threw a strict mode violation |
| Timeouts | Test 30 s, expect 5 s, action none (docs). | 3 s test timeout fired as expected |
| Fixtures | Setup by name through test.extend; teardown after use(). | logged-in fixture test passed |
| Login reuse | storageState saves cookies and local storage. | second context opened logged in |
| Mocking | page.route with fulfill or abort, set before the request. | mocked product list and error message |
| API testing | request fixture, no browser needed. | POST returned 201 |
| Retries | Pass on a retry means flaky, not passed. | 1 flaky, 1 failed, 1 passed |
| Traces | on-first-retry saves a trace only for retried tests. | 1 trace.zip for 3 tests (only the retry) |
| Parallel and shards | Files in parallel by default; shards split files across machines. | worker index and shard output above |
How should you prepare for a Playwright interview?
A week is enough if you already write tests. Our suggestion:
- Days 1 to 2: build a small test project like the one above (login, a list, a mocked API, one iframe or dialog) and run it yourself. Typing the code is what makes the answers stick.
- Day 3: break your own tests on purpose (a wrong locator, a slow response, a strict mode error) and read the error messages and traces.
- Day 4: set up retries, trace on first retry and a CI job that runs your tests, even on a free GitHub account.
- Day 5: practice the scenario questions (flaky test, passes locally but fails in CI, framework design) out loud.
- Day 6 to 7: review the wider SDET topics in our SDET interview questions and tidy your SDET resume so the Playwright projects are visible.
Frequently Asked Questions
Is Playwright good for beginners?
Yes. Auto-waiting removes the most common beginner problem (sleeps and flaky waits), and the test runner, assertions and trace viewer are included, so there is less to set up than with a library-only tool.
What languages can you use with Playwright?
JavaScript and TypeScript, Python, Java and .NET. Most interview questions and most online examples use JavaScript or TypeScript, so be ready to read it even if you write Python.
What is the difference between a locator and a selector in Playwright?
A selector is a string such as a CSS rule. A locator is an object that describes how to find an element and re-finds it every time you use it, which is what makes auto-waiting and retrying work.
How do you handle flaky tests in Playwright?
Find the cause with the trace, replace fixed sleeps with waits on real conditions, make tests independent, mock unstable third parties, and use retries only as a safety net. Track the flaky list so it shrinks.
How do you run Playwright tests in parallel?
Test files run in parallel across workers by default. Set fullyParallel to true to also run tests inside one file in parallel, and use the workers option to control how many run at once.
Do Playwright interviews include coding questions?
Often yes. Expect to write a short test live, for example log in, add an item and assert the cart, and to explain your locator choices. General coding questions (strings, arrays) depend on the role.
Final Thoughts
If you remember one thing, make it this: the strongest answers explain why Playwright behaves the way it does and show you have seen it. Auto-waiting, locators that must match one element, isolated contexts and traces are all design choices you can describe with an example. Run the code in this guide once, change something, and break it. After that, the interview questions turn into stories you can tell. When you are ready for the next step, read how to become an SDET and our visual regression testing guide.
Sources
- Playwright docs: Best practices (read 15 Nov 2026)
- Playwright docs: Timeouts (read 15 Nov 2026)
- Playwright docs: Parallelism (read 15 Nov 2026)
- Playwright docs: Auto-waiting (actionability) (read 15 Nov 2026)
- Playwright docs: Authentication (read 15 Nov 2026)
- Our own test runs: Playwright Test 1.65.1, Chrome, Node.js, Linux with 2 CPU cores, 15 Nov 2026.
One useful email a week
New guides, tool price changes and AI testing news. No spam.





