Skip to content

Apple Playwright Testing Interview Questions & Answers

Curated interview practice questions with answers. These are practice scenarios, not a verified list of past interview questions.

Solved for AppleStart practicing
3 QUESTIONS FREESign up or log in to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
3 questions free Unlock the rest in seconds
01

What are global setup and teardown?

AppleMedium
Save to ▾
Show answer
Scripts that run once before or after the whole run, for seeding data, starting services or creating authentication state.
02

How does Playwright compare with Selenium and Cypress?

AppleMedium
Save to ▾
Show answer
Playwright supports multiple browsers, tabs, languages and has auto-waiting and tracing; Selenium has the widest ecosystem; Cypress runs in-browser with a great UI but has more limits across tabs.
03

What is the difference between page, context and browser?

AppleMedium
Save to ▾
Show answer
A browser is the engine instance; a context is an isolated session (cookies, storage); a page is a tab inside a context.
04

How do you validate JSON schema?

AppleMedium
Save to ▾
Show answer
Use a library such as zod or ajv to define the expected schema and parse the response to fail on missing or wrongly typed fields.
05

How do you reduce the execution time of a 2000-test suite?

AppleHard
Save to ▾
Show answer
Run in parallel with sharding, reuse authentication state, set up data through APIs, avoid unnecessary waits, run smoke on every commit and the full suite nightly.
06

How do you take screenshots and videos?

AppleMedium
Save to ▾
Show answer
page.screenshot() for captures and config options use: { screenshot: 'only-on-failure', video: 'retain-on-failure' } for automatic evidence.
07

What does the optional chaining operator do?

AppleMedium
Save to ▾
Show answer
obj?.a?.b safely reads nested properties and returns undefined instead of throwing if something in the chain is missing.
08

How do you handle GraphQL APIs in Playwright?

AppleMedium
Save to ▾
Show answer
POST the query and variables as JSON to the single endpoint and assert both data and errors fields in the response.
09

How do you structure environment-specific configs in Playwright?

AppleMedium
Save to ▾
Show answer
Use dotenv files per environment, read them in playwright.config and set baseURL and credentials from variables, selecting with an ENV flag.
10

How do you run Playwright in GitHub Actions?

AppleMedium
Save to ▾
Show answer
Workflow: checkout → setup-node → npm ci → npx playwright install --with-deps → npx playwright test → upload playwright-report as an artifact.
11

How do you run tests in Docker?

AppleMedium
Save to ▾
Show answer
Use the official Playwright image which contains browsers and dependencies, mount the project and run npx playwright test for consistent CI environments.
12

Promise.all vs Promise.allSettled vs Promise.race?

AppleMedium
Save to ▾
Show answer
all waits for every promise and rejects on the first failure; allSettled waits for all and reports each outcome; race settles with the first one to finish.
13

How do you write a Page Object in Playwright?

AppleEasy
Save to ▾
Show answer
A class receives page in its constructor, stores locators as properties and exposes actions like login(user, pass). Tests call page objects, not raw locators.
14

Design a Playwright framework for a 500-test suite.

AppleHard
Save to ▾
Show answer
TypeScript + POM + custom fixtures, environment configs, API helpers for test data, tags like @smoke, sharding across CI machines, retries with traces, HTML/Allure reports, lint and review rules.
15

How do you test geolocation, permissions and time zones?

AppleMedium
Save to ▾
Show answer
Set them in the context options (geolocation, permissions, timezoneId, locale) to simulate users from other regions.
16

How do you test API error scenarios?

AppleMedium
Save to ▾
Show answer
Send invalid payloads or missing auth and assert 400, 401 or 404 codes and the error message bodies.
17

How do you handle a new tab?

AppleEasy
Save to ▾
Show answer
const [newPage] = await Promise.all([ context.waitForEvent('page'), page.getByText('Open').click(), ]); await newPage.waitForLoadState();
18

What is the difference between waitForSelector and expect with locator?

AppleMedium
Save to ▾
Show answer
waitForSelector is a lower-level wait; locator assertions are preferred as they retry and are more readable.
19

Write an API test with the request fixture.

AppleMedium
Save to ▾
Show answer
test('get user', async ({ request }) => { const res = await request.get('/api/users/1'); expect(res.ok()).toBeTruthy(); expect((await res.json()).id).toBe(1); });
20

let vs const vs var?

AppleEasy
Save to ▾
Show answer
var is function-scoped and hoisted. let and const are block-scoped; const can't be reassigned (though an object it points to can change). Prefer const, then let.
21

What happens if you forget an await?

AppleMedium
Save to ▾
Show answer
The action runs without waiting, so the next step may run first — causing flaky failures or 'Target closed' errors. The @typescript-eslint/no-floating-promises rule catches it.
22

Why choose Playwright over Selenium?

AppleMedium
Save to ▾
Show answer
Auto-waiting, a built-in test runner, Chromium/Firefox/WebKit with one API, network interception, the trace viewer and parallel runs out of the box — usually faster and less flaky.
23

Tests are flaky in CI. How do you debug them?

AppleHard
Save to ▾
Show answer
Turn on trace: 'on-first-retry', open the trace viewer, check network and timing, replace hard waits with web-first assertions, isolate test data and check for sharding conflicts.
24

What is the difference between null and undefined?

AppleMedium
Save to ▾
Show answer
undefined means a variable has not been assigned; null is an intentional empty value.
25

How do you debug a Playwright test?

AppleMedium
Save to ▾
Show answer
Use --debug or the Inspector, page.pause(), UI mode, the trace viewer and headed runs with slowMo.
26

How do you shard tests across machines?

AppleMedium
Save to ▾
Show answer
Use npx playwright test --shard=1/4 in each CI job and merge reports afterwards to reduce total run time.
27

What is npm and package.json?

AppleEasy
Save to ▾
Show answer
npm is the Node package manager. package.json lists the project's dependencies and scripts, such as the command that runs the tests.
28

interface vs type in TypeScript?

AppleMedium
Save to ▾
Show answer
Both describe object shapes. Interfaces can be extended and merged; type aliases can also describe unions and primitives. Use interfaces for page or test-data shapes, types for unions.
29

What is destructuring and the spread operator?

AppleMedium
Save to ▾
Show answer
Destructuring pulls values from arrays or objects into variables; spread expands an array or object into another, useful for copying and merging config.
30

How do you run only smoke tests?

AppleEasy
Save to ▾
Show answer
Tag tests (in the title or with { tag: '@smoke' }) and run: npx playwright test --grep @smoke (use --grep-invert to exclude).
31

How do you set test timeouts?

AppleMedium
Save to ▾
Show answer
Use timeout and expect.timeout in config, test.setTimeout() for one test and test.slow() for known slower tests.
32

What are the main data types in JavaScript?

AppleEasy
Save to ▾
Show answer
string, number, boolean, null, undefined, symbol, bigint and object (including arrays and functions).
33

What is the difference between TypeScript and JavaScript?

AppleEasy
Save to ▾
Show answer
TypeScript adds static types on top of JavaScript and compiles to it. Types catch errors early and give better autocomplete, which helps in larger test suites.
34

How do you send a POST request with a JSON body?

AppleMedium
Save to ▾
Show answer
await request.post('/api/users', { data: { name: 'Asha' } }) automatically sets JSON headers and serialises the payload.
35

What reporters does Playwright provide?

AppleMedium
Save to ▾
Show answer
List, dot, line, HTML, JSON and JUnit reporters, plus integrations such as Allure, configurable per environment.
36

How do you test file downloads and verify their content?

AppleMedium
Save to ▾
Show answer
Capture the download event, save it with download.saveAs, then read the file in Node and assert on name, size or content.
37

How do you share cookies between API login and UI?

AppleMedium
Save to ▾
Show answer
Log in with request.post, call request.storageState(), and create a browser context using that state.
38

What is hoisting?

AppleMedium
Save to ▾
Show answer
Declarations of var and functions are moved to the top of their scope at compile time; let and const are hoisted but stay in the temporal dead zone until declared.
39

How do you handle iframes in Playwright?

AppleMedium
Save to ▾
Show answer
Use page.frameLocator('#frame').getByRole(...) so actions work inside the iframe with auto-waiting.
40

How do retries work?

AppleMedium
Save to ▾
Show answer
Set retries in the config or CLI and failed tests re-run in a fresh context, with trace recorded on first retry to diagnose flakiness.
41

What is the difference between map, filter and reduce?

AppleMedium
Save to ▾
Show answer
map transforms each item, filter keeps items that match a condition, and reduce combines all items into a single value.
42

How do you handle errors in async code?

AppleEasy
Save to ▾
Show answer
Use try-catch with await, or .catch() on promises, and make sure rejected promises are never left unhandled.
43

How do you mock an API response?

AppleMedium
Save to ▾
Show answer
await page.route('**/api/users', route => route.fulfill({ status: 200, json: [{ id: 1, name: 'Test' }] }) );
44

How would you design API test coverage for a new endpoint?

AppleHard
Save to ▾
Show answer
Cover happy path, validation errors, auth and permissions, boundary values, idempotency, schema, performance and data cleanup.
45

Locator vs ElementHandle?

AppleEasy
Save to ▾
Show answer
A Locator is lazy, re-resolved on every action and auto-waits (recommended). An ElementHandle points to one DOM node and can go stale.
46

How do you test file upload via API?

AppleMedium
Save to ▾
Show answer
Use request.post with multipart: { file: { name, mimeType, buffer } } and assert the response and stored file details.
47

How do you wait for a network response in Playwright?

AppleMedium
Save to ▾
Show answer
Use page.waitForResponse(res => res.url().includes('/api/orders') && res.ok()) together with the action that triggers it.
48

How do you handle shadow DOM?

AppleMedium
Save to ▾
Show answer
Playwright locators pierce open shadow roots by default, so getByRole and CSS locators work without special handling.
49

What is the difference between a type and an enum in TypeScript?

AppleMedium
Save to ▾
Show answer
A type alias describes a shape or union of values; an enum creates a named set of constants that exists at runtime.
50

Which locators does Playwright recommend?

AppleMedium
Save to ▾
Show answer
User-facing ones: getByRole, getByText, getByLabel, getByPlaceholder and getByTestId, which are more resilient than CSS or XPath.
51

How do you use test.step and test annotations?

AppleMedium
Save to ▾
Show answer
test.step groups actions into named steps in reports; annotations such as test.skip, test.fixme and test.slow communicate intent and adjust behaviour.
52

How do you handle rate limits or slow APIs in tests?

AppleMedium
Save to ▾
Show answer
Add retries with backoff for the API step, set a suitable timeout, and use mocks for non-critical dependencies.
53

How do you test a file download?

AppleMedium
Save to ▾
Show answer
const [download] = await Promise.all([ page.waitForEvent('download'), page.getByText('Export').click(), ]); await download.saveAs('reports/file.csv');
54

How do you manage test data and environments?

AppleMedium
Save to ▾
Show answer
Use environment variables or .env files, a baseURL in config, API calls for setup and cleanup, and unique data per run.
55

What is the difference between API testing and UI testing?

AppleEasy
Save to ▾
Show answer
API testing checks services directly and is fast and stable; UI testing checks the full user experience in the browser and is slower.
56

How do you make an API request in Playwright?

AppleEasy
Save to ▾
Show answer
Use the request fixture: const res = await request.get('/api/users'); expect(res.ok()).toBeTruthy(); const body = await res.json();
57

What are fixtures in Playwright?

AppleMedium
Save to ▾
Show answer
Reusable setup/teardown units injected into tests (page, context, request). You can extend test with custom fixtures such as loggedInPage.
58

How do you handle dialogs such as alerts?

AppleMedium
Save to ▾
Show answer
Register page.on('dialog', d => d.accept()) before the action triggers the dialog.