Playwright · Reliable end-to-end tests
How do you set up a Playwright project?
Short answer
Install @playwright/test, download the browsers, and add a playwright.config.ts. The config defines the test directory, browser projects, base URL, retries, reporters and trace settings.
A clean setup has four parts: the package, the browser binaries, the config file and a tests directory. The config is the source of truth for how tests run locally and in CI, so keep environment-dependent settings such as retries and workers conditional.
npm i -D @playwright/test
npx playwright install
npx playwright testimport { defineConfig, devices } from "@playwright/test";
export default defineConfig({
testDir: "./tests",
fullyParallel: true,
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: "webkit", use: { ...devices["Desktop Safari"] } },
],
});Settings worth deciding early
- How the app is started, through
webServeror an external orchestration step - Whether tests run fully in parallel or only file by file
- Retries and workers for CI versus local development
- Trace, screenshot and video policy for debugging artifacts
- Browser and device projects, including a mobile viewport if relevant
- A reporter that matches how the team reads failures, such as HTML, JUnit or GitHub
Use npx playwright test --ui locally for a watch-style interface, and keep auth state, test results and reports out of version control. Generated config from npm init playwright@latest is a useful starting point, but it should be reviewed rather than accepted blindly.
npx playwright install, the runner will fail with a missing executable error, which is a common first setup issue in CI.Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does the `webServer` config option do?
- 2Why are browser binaries installed separately from the package?
- 3When would you turn off full parallelism?
- 4How do you run one project from the command line?
Say it in the interview
I install the test package, install the browser builds, and create a Playwright config with a test directory and at least one browser project. I set baseURL, trace on first retry and CI-aware retries and workers. I also configure webServer when the test run should start the app itself. The generated config is a starting point, but I review it so local and CI behaviour stay predictable.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.