Getting Playwright running locally is the first step toward using it in real projects. A clean installation and a simple first test help you verify that browsers, drivers, and the test runner are all wired correctly.
Installing Playwright and Scaffolding a Project
Playwright projects are usually TypeScript or JavaScript Node.js projects. The recommended way to start is with the official init command, which sets up the test runner, configuration, and example tests for you.
# 1. Create a new folder and initialise a Node.js project
mkdir playwright-demo
cd playwright-demo
npm init -y
# 2. Install Playwright test runner
npm install -D @playwright/test
# 3. Install browsers and scaffold config
npx playwright install
npx playwright test --init
# 4. Run the example tests
npx playwright test
# 5. Open the HTML report
npx playwright show-report
npx playwright test --init command creates a standard folder structure (tests, playwright.config, example tests) that follows Playwrightβs best practices.playwright.config and example tests to version control so new team members can run npx playwright test immediately after cloning.After running the example suite, you can rename the sample spec file and start adding your own tests. This iterative approach helps you evolve the project without losing the scaffoldβs structure.
Common Mistakes
Mistake 1 β Skipping the official init flow
This leads to ad hoc setups.
β Wrong: Manually creating random folders and configs with no standard layout.
β Correct: Use the built-in init command and then customise as needed.
Mistake 2 β Forgetting to install browsers
Tests then fail unexpectedly.
β Wrong: Installing @playwright/test but never running npx playwright install.
β Correct: Always install the browser binaries once per environment before running tests.