These Playwright test data and configuration interview questions cover what interviewers ask after “what is Playwright”: data-driven tests, environments and secrets, multiple configs, cross-browser and mobile runs. Each question is a real scenario with a step-by-step answer and TypeScript code that was run on Chromium, Firefox, WebKit and a Pixel 7 emulation against the SQA Tools practice shop. They follow Module 7 of the Playwright TypeScript tutorial.
📖 How to use this page: answer each scenario out loud first, then compare with the steps. Questions 1 to 5 suit 0 to 2 years of experience; the rest are common for 3+ years.
📊 Data-Driven Tests
Q1. Scenario: You have 30 invalid-login cases in a spreadsheet. A colleague wrote one test with a loop inside it; when case 4 fails, cases 5 to 30 never run.
What the interviewer is checking: generating one test per data row so each case passes or fails on its own.
Answer:
- Export the cases to JSON (or CSV) and keep them in the repo next to the tests.
- Loop outside
test()so Playwright registers one test per row. - Put the case name in the title so the report shows exactly which row failed.
- Each generated test runs in parallel and retries on its own.
📄 tests/data/login-cases.json and tests/login-data.spec.ts
// tests/data/login-cases.json
[
{ "case": "wrong password", "username": "testuser", "password": "wrong", "error": "Invalid username or password." },
{ "case": "locked account", "username": "lockeduser", "password": "Test@123", "error": "This account is locked. Please contact support." },
{ "case": "empty fields", "username": "", "password": "", "error": "Username and password are required." }
]
// tests/login-data.spec.ts
import { test, expect } from '@playwright/test';
import cases from './data/login-cases.json';
for (const c of cases) {
test(`login fails: ${c.case}`, async ({ page }) => {
await page.goto('#/login');
await page.getByTestId('login-username').fill(c.username);
await page.getByTestId('login-password').fill(c.password);
await page.getByTestId('login-button').click();
await expect(page.getByTestId('login-error')).toHaveText(c.error);
});
}
🖥️ Output
ok 11 [chromium] › interview\data.spec.ts:6:3 › login fails: wrong password (3.2s)
ok 12 [chromium] › interview\data.spec.ts:6:3 › login fails: locked account (3.9s)
ok 13 [chromium] › interview\data.spec.ts:6:3 › login fails: empty fields (3.3s)
Follow-up they may ask: How do you read a CSV instead of JSON? Read the file with fs.readFileSync and parse it with a library such as csv-parse/sync (parse(text, { columns: true })), then loop the same way. See reading CSV data in Playwright.
Red flag answer: “I loop inside one test.” One failure hides the rest, and the report shows a single result for 30 cases.
Q2. Scenario: After adding data rows, the whole suite stops before running anything, with an error about a duplicate title.
What the interviewer is checking: that you have seen this real error and know test titles must be unique in a file.
Answer:
- Read the error: Playwright refuses to run when two tests in one file have the same title.
- It happens when the loop variable is not in the title, or when two data rows are identical.
- Fix it by putting a unique field (case name or id) in the title, and remove duplicated rows from the data.
📄 dup.spec.ts (the mistake)
const users = ['testuser', 'testuser'];
for (const u of users) {
test('login works', async () => {});
}
🖥️ Output
Error: duplicate test title "login works", first declared in dup.spec.ts:4
at dup.spec.ts:4
Follow-up they may ask: Can two tests have the same title in different describe blocks? Yes. The full title includes the describe names, so describe('admin') and describe('viewer') can each contain test('login works').
Red flag answer: “Add a random number to the title.” Titles then change every run, which breaks test history, retries and --grep.
Q3. Scenario: Two parallel workers create a user with the same email, and one test fails with “email already exists” about once in five runs.
What the interviewer is checking: unique test data per worker and per retry.
Answer:
- Recognise the pattern: intermittent failures that disappear with
--workers=1point to shared data. - Build unique values from
testInfo.workerIndex,testInfo.retryand a timestamp, for example`qa+w${testInfo.workerIndex}-${Date.now()}@example.com`. - Create the data in a fixture and delete it in teardown.
- For data that must be shared (a reference product), make it read-only for tests.
Follow-up they may ask: What is the difference between workerIndex and parallelIndex? workerIndex is unique for every worker process ever started (it grows when a worker restarts after a failure); parallelIndex is between 0 and workers-1, good for picking one of N pre-created accounts.
Red flag answer: “Turn off parallel mode.” The suite gets slower and the bug in the test design stays.
⚙️ Environments, Secrets and Config Files
Q4. Scenario: The same suite must run against QA, staging and a developer’s local server. Today the URL is hard-coded in 40 files.
What the interviewer is checking: a single source of configuration: baseURL plus environment files.
Answer:
- Set
use.baseURLinplaywright.config.tsand use relative paths in tests (page.goto('/login')). - Keep one
.env.qa,.env.stagingfile per environment and load the right one with dotenv based on a variable such asTEST_ENV. - Fail fast if a required variable is missing, instead of running against
undefined. - In CI, set the same variables from the pipeline’s variables and secrets.
📄 playwright.config.ts
import { defineConfig } from '@playwright/test';
import dotenv from 'dotenv';
const env = process.env.TEST_ENV ?? 'qa';
dotenv.config({ path: `.env.${env}` });
if (!process.env.BASE_URL) {
throw new Error(`BASE_URL is missing in .env.${env}`);
}
export default defineConfig({
use: { baseURL: process.env.BASE_URL },
});
Follow-up they may ask: How do you run against staging from the command line on Windows PowerShell? Set the variable first: $env:TEST_ENV="staging"; npx playwright test. On macOS and Linux: TEST_ENV=staging npx playwright test.
Red flag answer: “I change the URL in the config before each run.” Someone will forget, and tests will run against the wrong environment.
Q5. Scenario: A test account password was found in the Git history of your automation repo.
What the interviewer is checking: secret handling, and what to do after a leak.
Answer:
- Treat it as leaked: ask for the password to be changed immediately. Deleting the line does not remove it from history.
- Move credentials to environment variables; commit only a
.env.examplewith dummy values and add.env*to.gitignore. - Store real values in the CI secret store and in a password manager for local runs.
- Add a secret scanner (for example GitHub secret scanning or gitleaks) to the pipeline.
- Mask secrets in reports: avoid logging them and do not put them in test titles.
Follow-up they may ask: Can secrets still leak into the Playwright HTML report? Yes. fill() steps, traces and screenshots can contain them. Use dedicated low-privilege test accounts, and do not publish traces from production-like environments publicly.
Red flag answer: “It is only a test account.” Test accounts often have real access to shared environments.
Q6. Scenario: Smoke tests should run in 2 minutes on every commit with no retries; the nightly regression needs 3 browsers, retries and video.
What the interviewer is checking: using multiple config files that share one base instead of copy-paste.
Answer:
- Keep shared settings in
playwright.config.ts(base URL, reporters, timeouts). - Create
playwright.smoke.config.tsthat imports the base and overridesgrep,retriesandprojects. - Run with
npx playwright test -c playwright.smoke.config.ts. - Alternatively, use one config with different
projectsand pick with--project.
📄 playwright.smoke.config.ts
import { defineConfig, devices } from '@playwright/test';
import base from './playwright.config';
export default defineConfig({
...base,
grep: /@smoke/,
retries: 0,
use: { ...base.use, video: 'off' },
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
});
Follow-up they may ask: Why spread base.use instead of replacing it? Replacing use drops the shared baseURL and other options; spreading keeps them and changes only what you list.
Red flag answer: “We keep two full copies of the config.” They drift apart within weeks.
Q7. Scenario: Admin and viewer users need to run the same tests with different credentials and expected permissions.
What the interviewer is checking: custom options: values set per project and read in fixtures.
Answer:
- Declare an option fixture with
{ option: true }, for examplerole. - Create one project per role in the config and set
use: { role: 'admin' }. - Read
rolein a fixture that logs in as that user, and in tests that expect different outcomes. - The report then shows each test once per role, labelled with the project name.
📄 fixtures/role.ts
import { test as base } from '@playwright/test';
export type Role = 'admin' | 'viewer';
export const test = base.extend<{ role: Role }>({
role: ['viewer', { option: true }],
});
// playwright.config.ts
// projects: [
// { name: 'admin', use: { role: 'admin' } },
// { name: 'viewer', use: { role: 'viewer' } },
// ]
Follow-up they may ask: How is this different from reading process.env.ROLE? Options are typed, visible in the config, and let both roles run in the same command; an environment variable gives one role per run.
Red flag answer: “I duplicate the test files for each role.”
🌐 Cross-Browser and Mobile
Q8. Scenario: A checkout test passes in Chromium and Firefox but fails only in WebKit. The release is tomorrow.
What the interviewer is checking: a calm, evidence-based process for browser-specific failures.
Answer:
- Reproduce with
npx playwright test --project=webkit --headedand open the trace. - Decide whether it is an app bug (real Safari users are affected) or a test issue (timing, a locator that depends on layout).
- If it is an app bug, raise it with the trace and keep the test failing or mark it
test.fail()with the ticket number. - If it is a known issue the team accepts, skip it only for that browser with a reason, so it still runs elsewhere.
- Remember WebKit in Playwright is close to Safari but not identical; confirm important bugs on a real Safari.
📄 tests/search.spec.ts
test('search works in every browser', async ({ page, browserName }) => {
test.skip(browserName === 'webkit' && !!process.env.SKIP_WEBKIT, 'Known WebKit issue: JIRA-123');
await page.goto('');
await page.getByTestId('search-input').fill('earbuds');
await page.getByTestId('search-button').click();
await expect(page.getByTestId('result-count')).toContainText('1 product');
});
Follow-up they may ask: What is the difference between test.skip, test.fixme and test.fail? skip does not run the test; fixme also skips it but marks it as needing a fix; fail runs it and expects it to fail, so you notice when the bug is fixed.
Red flag answer: “Remove WebKit from the config.” You stop testing a browser your users use.
Q9. Scenario: Your app shows prices in Indian format and dates in local time. Tests pass in India and fail on the CI server in the US.
What the interviewer is checking: controlling locale and time zone instead of depending on the machine.
Answer:
- Set
localeandtimezoneIdin the config or withtest.use(), so every machine behaves the same. - Verify what the browser actually reports, then assert the formatted values.
- Add a second project with another locale if the product supports it.
- Watch the browser differences: Chromium reports the old name
Asia/CalcuttaforAsia/Kolkata, so do not assert the zone name exactly.
📄 tests/locale.spec.ts
test.describe('Indian locale', () => {
test.use({ locale: 'en-IN', timezoneId: 'Asia/Kolkata' });
test('browser reports the emulated locale and time zone', async ({ page }) => {
await page.goto('');
const env = await page.evaluate(() => ({
lang: navigator.language,
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
price: new Intl.NumberFormat(navigator.language).format(119399),
}));
expect(env.lang).toBe('en-IN');
expect(env.price).toBe('1,19,399');
// Chromium reports the old ICU name Asia/Calcutta; Firefox and WebKit say Asia/Kolkata
expect(env.tz).toMatch(/^Asia\/(Kolkata|Calcutta)$/);
});
});
🖥️ Output
ok 15 [chromium] › interview\data.spec.ts:27:3 › Indian locale › browser reports the emulated locale and time zone
ok 20 [firefox] › interview\data.spec.ts:27:3 › Indian locale › browser reports the emulated locale and time zone
ok 25 [webkit] › interview\data.spec.ts:27:3 › Indian locale › browser reports the emulated locale and time zone
Follow-up they may ask: What did the first version of this test do in Chromium? It asserted tz: 'Asia/Kolkata' and failed with + "tz": "Asia/Calcutta". Both names are the same zone; the fix is the regular expression above.
Red flag answer: “Set the CI server’s time zone to India.” The next server or developer will break it again.
Q10. Scenario: Product asks for mobile coverage. A teammate suggests just setting a small viewport.
What the interviewer is checking: knowing what device emulation includes, and its limits.
Answer:
- Use a device descriptor such as
devices['Pixel 7']: it sets viewport, device scale factor, user agent,isMobileand touch, not only the size. - Add it as a project so the same tests run on desktop and mobile, or write mobile-only tests for different layouts.
- Test what really changes on phones: menus, collapsed filters, sticky buttons, touch targets.
- Be clear about the limits: emulation runs desktop browser engines, so use real devices or a device cloud for final checks.
📄 tests/mobile-filters.spec.ts
// playwright.config.ts → projects: [{ name: 'mobile-chrome', use: { ...devices['Pixel 7'] } }]
test('filters open from the Filters button on a phone', async ({ page, isMobile }) => {
expect(isMobile).toBe(true);
await page.goto('');
const toggle = page.getByRole('button', { name: 'Filters' });
await expect(toggle).toBeVisible();
await expect(page.getByTestId('apply-price')).toBeHidden();
await toggle.click();
await expect(page.getByTestId('apply-price')).toBeVisible();
});
🖥️ Output
ok 26 [mobile-chrome] › interview\mobile.spec.ts:4:1 › filters open from the Filters button on a phone (2.4s)
Follow-up they may ask: Can Playwright test a native Android app? No. It tests web apps in mobile browsers (and has experimental Android Chrome support over ADB). Native apps need tools like Appium.
Red flag answer: “Mobile testing is just a small viewport.”
Q11. Scenario: Running 3 browsers tripled CI time to 45 minutes. The team wants to drop Firefox and WebKit.
What the interviewer is checking: balancing coverage and speed with data, not removing coverage.
Answer:
- Check analytics: which browsers do your users actually use?
- Run the full suite on Chromium on every pull request, and the cross-browser projects nightly or before release.
- Tag a small
@cross-browsersubset (rendering, forms, uploads, dates) to run on all browsers per pull request. - Shard the nightly run across machines with
--shard=1/3and merge the reports.
Follow-up they may ask: How do you run one project only? npx playwright test --project=firefox. You can pass --project several times.
Red flag answer: “Browsers are all the same now, Chromium is enough.”
❓ Frequently Asked Questions
🤔 How do I run Playwright tests with different data?
Loop over the data outside test() and put a unique value in each title, so every row becomes its own test. Data can come from JSON, CSV, Excel or an API.
🤔 How do I use environment variables in Playwright?
Read them with process.env.NAME. Load a .env file with dotenv at the top of playwright.config.ts, and set the same variables as secrets in CI.
🤔 How do I run Playwright tests in all browsers?
Define one project per browser in the config (devices['Desktop Chrome'], 'Desktop Firefox', 'Desktop Safari') and run npx playwright test. Install browsers with npx playwright install.
🤔 Is Playwright mobile emulation enough for mobile testing?
It is good for layout and behaviour of responsive web apps, and fast enough for every build. It is not a real device, so confirm critical flows on real phones or a device cloud.
🔗 More Playwright Interview Preparation
- Playwright Interview Questions and Answers (scenario-based, all topics)
- Playwright Interview Questions for Experienced Engineers (2, 3 and 5+ years)
- 200 Playwright + TypeScript Interview Questions
- Playwright API Testing Interview Questions
- Playwright Cheat Sheet
- Playwright mock interviews: 13 timed tests, one per module
🎬 Watch the full Playwright tutorial series on YouTube!
Subscribe to SqaToolsByDY • Practice on sqatools.in