Playwright Tutorial for Beginners: Your First Test in 10 Minutes
Published: ·4 min read
Learn Playwright from scratch. This step-by-step tutorial will have you writing your first automated test in under 10 minutes — no prior automation experience required.
What You'll Learn
By the end of this tutorial, you'll have:
Playwright installed on your machine
Written and run your first automated test
Understood the basic Playwright concepts
A foundation to build real-world test suites
Total time: about 10 minutes. Let's go.
Prerequisites
You need Node.js 18+ installed. Check your version:
node --version
If you need to install Node.js, download it from nodejs.org.
That's it. No other dependencies required.
Step 1: Create Your Project
Open your terminal and create a new folder:
mkdir playwright-tutorial
cd playwright-tutorial
Step 2: Install Playwright
Run the Playwright installer:
npm init playwright@latest
You'll see some prompts. Accept the defaults:
TypeScript or JavaScript? → TypeScript (recommended)
Where to put tests? → tests
Add GitHub Actions? → Yes (optional, but useful later)
Install browsers? → Yes
This installs Playwright, downloads browser binaries, and creates a basic project structure.
Step 3: Explore the Project Structure
After installation, you'll see:
tests/ — Your test files go here
playwright.config.ts — Configuration file
tests/example.spec.ts — A sample test (we'll replace this)
Step 4: Write Your First Test
Delete the example test and create a new file called tests/first.spec.ts:
Add more tests — Start testing your own application
Learn Page Object Model — Organize tests for maintainability
Set up CI/CD — Run tests on every pull request
Explore API testing — Playwright also tests REST APIs
Common Beginner Mistakes to Avoid
1. Using sleep/delay:
Bad:
await page.waitForTimeout(5000);
Good: Let Playwright's auto-waiting handle it, or wait for specific conditions.
2. Fragile locators:
Bad:
page.locator('#app > div:nth-child(3) > button')
Good:
page.getByRole('button', { name: 'Submit' })
3. Not using test isolation:
Each test should be independent. Don't rely on state from previous tests.
Resources
Official docs: playwright.dev/docs/intro
Test generator:
npx playwright codegen [url]
UI mode:
npx playwright test --ui
Report viewer:
npx playwright show-report
Need Hands-On Help?
If you're building a test automation framework for your team and want guidance from someone who's done it at Apple and Fortune 500 companies, I offer consulting and training.
Native Drag-and-Drop Automation Arrives in Playwright MCP: What v0.0.71 Changes
Playwright MCP v0.0.71 ships browser_drop. It gives you native drag-and-drop from any MCP client. No more evaluate scripts. No more mouse.move chains. Grid reordering, file drop zones, text editor drags — all work the same way a real user does.