Introduction: Why Use VS Code for Playwright Automation?
If you are beginning Playwright automation testing, Visual Studio Code is one of the easiest environments in which to build and debug your test framework.
VS Code provides an editor, integrated terminal, debugger, extensions, Git integration, and a Testing interface in one place. The official Playwright VS Code extension also lets you run, debug, record, and inspect Playwright tests directly from the editor.
This makes Playwright setup for beginners in VS Code particularly useful for QA engineers moving from Selenium, students learning automation, developers writing end-to-end tests, and SDETs building a reusable test framework.
In this guide, you will learn how to:
- Install Node.js and VS Code
- Install the Playwright VS Code extension
- Create a Playwright TypeScript project
- Install Playwright browsers
- Understand the generated project
- Write your first test
- Run tests from the terminal and VS Code
- Debug tests with breakpoints and Playwright Inspector
- Capture screenshots, traces, and videos
- Generate HTML reports
- Configure Chromium, Firefox, and WebKit
- Build a real-world login test
- Prepare Playwright for CI/CD
- Troubleshoot common setup errors
By the end, you will have a working Playwright VS Code setup for beginners and the foundation for a professional automation framework.
Prerequisites for Playwright Setup in VS Code
Before starting the Playwright setup for beginners in VS Code, install these tools:
| Tool | Why You Need It |
| Node.js | Runs the Playwright TypeScript project |
| npm | Installs packages and dependencies |
| Visual Studio Code | Code editor and debugging environment |
| Git | Version control for automation projects |
| Basic TypeScript | Helps you understand test code |
Playwright’s Node.js setup uses TypeScript or JavaScript, and the Playwright Test runner provides features such as parallel execution, assertions, reporting, and tracing.
Recommended for Windows
If you are using Windows, download the current Node.js LTS release and VS Code, then restart VS Code after installation if necessary.
Verify Node.js:
node –version
Verify npm:
npm –version
You should see version numbers.
macOS and Linux
The overall process is almost identical.
Use:
node –version
npm –version
The main differences are usually terminal commands, file paths, and Linux system dependencies in CI environments.
Step 1: Install Visual Studio Code
Download and install Visual Studio Code.
After installation, open VS Code.
You can verify the installation from a terminal:
code –version
If the code command is not recognized on Windows, you can simply open VS Code from the Start menu and use File → Open Folder.
Step 2: Install the Playwright VS Code Extension
The official Playwright extension provides Playwright-specific functionality inside VS Code.
Open VS Code and press:
Ctrl + Shift + X
This opens the Extensions panel.
Search for:
Playwright
Install the official Playwright Test for VS Code extension from Microsoft.
The official extension supports running individual tests, running all tests, debugging, browser selection, test recording, locator inspection, and trace viewing.
Expected Result
You should see Playwright-related controls in VS Code, including the Testing interface.
Troubleshooting Tip
If the extension does not appear to detect your tests, make sure you have opened the project folder, not just an individual .ts file.
Step 3: Create a New Playwright Project in VS Code
There are two useful approaches.
Option 1: Create the project from the terminal
Open the VS Code terminal:
Terminal → New Terminal
Create a folder:
mkdir playwright-vscode-demo
cd playwright-vscode-demo
Then initialize Playwright:
npm init playwright@latest
The setup wizard asks questions such as:
- TypeScript or JavaScript
- Test directory
- Whether to add a GitHub Actions workflow
- Whether to install browsers
For this tutorial, choose TypeScript.
The Playwright setup process creates a configuration file and starter test structure.
Step 4: Install Playwright and Playwright Test
For a standard Playwright Test project, the recommended project initialization command is:
npm init playwright@latest
This is different from installing the lower-level browser automation library manually.
For a Playwright Test project, you normally import from:
import { test, expect } from ‘@playwright/test’;
The Playwright documentation distinguishes the test-runner setup from the lower-level playwright library installation.
Expected Result
Your package.json should contain Playwright-related dependencies.
You can verify the installation with:
npx playwright –version
Step 5: Install Playwright Browsers
Playwright requires browser binaries for the browser projects you want to execute.
Run:
This installs the Playwright-managed browser binaries.
You can also install a specific browser:
npx playwright install chromium
For Linux CI environments where system dependencies are needed:
npx playwright install –with-deps
Expected Result
Playwright downloads the required browser components.
Troubleshooting Tip
If you see an error saying a browser executable is missing, run:
npx playwright install
and then execute your test again.
Step 6: Understand the Generated Playwright Project Structure
A typical project looks like:
playwright-vscode-demo/
│
├── tests/
│ └── example.spec.ts
│
├── playwright.config.ts
├── package.json
├── package-lock.json
└── tsconfig.json
Some generated files can differ depending on your choices during installation.
tests/
Contains automated tests.
example.spec.ts
Contains a starter test.
playwright.config.ts
Controls settings such as:
- Browsers
- Base URL
- Timeouts
- Retries
- Screenshots
- Video
- Trace
- Reporter
package.json
Contains project dependencies and npm scripts.
tsconfig.json
Contains TypeScript configuration.
Understanding this structure is important before creating a larger Playwright Testing Framework.
Step 7: Create Your First Playwright Test
Create:
tests/first-test.spec.ts
Add:
import { test, expect } from ‘@playwright/test’;
test(‘verify Example Domain’, async ({ page }) => {
await page.goto(‘https://example.com’);
await expect(page).toHaveTitle(/Example Domain/);
await expect(
page.getByRole(‘heading’, { name: ‘Example Domain’ })
).toBeVisible();
});
This is a complete runnable Playwright TypeScript test.
Explanation
import { test, expect } from ‘@playwright/test’;
Imports Playwright’s test runner and assertion library.
test(‘verify Example Domain’, async ({ page }) => {
Creates a test and receives the page fixture.
await page.goto(‘https://example.com’);
Navigates to the webpage.
await expect(page).toHaveTitle(/Example Domain/);
Checks the page title.
await expect(
page.getByRole(‘heading’, { name: ‘Example Domain’ })
).toBeVisible();
Finds the heading and verifies that it is visible.
Step 8: Run Playwright Tests From the VS Code Terminal
Open:
Terminal → New Terminal
Run:
npx playwright test
By default, Playwright runs tests in headless mode, meaning the browser does not open visibly.
Run a specific file:
npx playwright test tests/first-test.spec.ts
Run a specific test by title:
npx playwright test -g “verify Example Domain
Expected Result
The terminal should report the number of tests executed and whether they passed or failed.
Step 9: Run Tests From the VS Code Testing Interface
After installing the Playwright extension, open the Testing view from the VS Code Activity Bar.
You should see your Playwright tests.
You can click the green play icon beside an individual test.
You can also run an entire test file or the complete suite.
The official extension provides test execution directly inside VS Code and displays test results in the editor.
Expected Result
The selected test executes without requiring you to type the CLI command manually.
Troubleshooting Tip
If no tests appear:
- Confirm the file is named something like example.spec.ts.
- Confirm the project folder is open.
- Check testDir in playwright.config.ts.
- Make sure @playwright/test is installed.
- Reload the VS Code window.
Step 10: Run Tests in Headed and Headless Modes
Headless mode is the default for normal CLI execution.
npx playwright test
Use headed mode when you want to see the browser:
npx playwright test –headed
Playwright also provides UI Mode:
npx playwright test –ui
UI Mode provides a visual way to explore test execution and inspect actions.
When Should Beginners Use Headed Mode?
Use it while learning:
- Navigation
- Locators
- Forms
- Login
- Dropdowns
- Browser interactions
Use headless mode for fast regular execution and CI.
Step 11: Debug Playwright Tests in VS Code
Debugging is one of the biggest advantages of the Playwright VS Code setup.
Consider:
import { test, expect } from ‘@playwright/test’;
test(‘debug example’, async ({ page }) => {
await page.goto(‘https://example.com’);
const heading = page.getByRole(‘heading’, {
name: ‘Example Domain’
});
await expect(heading).toBeVisible();
});
Set a breakpoint by clicking beside a line number.
For example:
await page.goto(‘https://example.com’);
Then right-click the test and choose Debug Test.
The VS Code extension supports breakpoints, stepping through code, inspecting variables, and viewing detailed test errors.
Expected Result
The test pauses at the breakpoint.
You can inspect variables and step through the test line by line.
Step 12: Use Playwright Inspector
You can also debug from the terminal:
npx playwright test tests/first-test.spec.ts –debug
Playwright Inspector allows you to step through test execution and inspect locators.
You can also use locator-picking features to determine how an element can be targeted.
Best Practice
Do not blindly copy every generated locator.
Review whether the locator is stable and meaningful.
Step 13: Capture Screenshots, Traces, and Videos
Configure these options in playwright.config.ts:
import { defineConfig } from ‘@playwright/test’;
export default defineConfig({
use: {
screenshot: ‘only-on-failure’,
video: ‘on-first-retry’,
trace: ‘on-first-retry’
}
});
This gives you useful debugging evidence without necessarily generating large artifacts for every successful test.
You can also capture a screenshot manually:
await page.screenshot({
path: ‘screenshots/homepage.png’,
fullPage: true
});
Expected Result
A PNG file is created in the specified location.
Step 14: Generate and View the HTML Report
Run your tests:
npx playwright test
Then open the report:
npx playwright show-report
The HTML reporter provides information about passed, failed, skipped, and flaky tests, along with test details and artifacts.
For QA engineers, reports are important because they provide evidence that can be shared with developers and other stakeholders.
Step 15: Configure playwright.config.ts
A practical beginner configuration could look like this:
import { defineConfig, devices } from ‘@playwright/test’;
export default defineConfig({
testDir: ‘./tests’,
timeout: 30_000,
expect: {
timeout: 5_000
},
fullyParallel: true,
retries: process.env.CI ? 2 : 0,
reporter: ‘html’,
use: {
baseURL: ‘https://example.com’,
screenshot: ‘only-on-failure’,
video: ‘on-first-retry’,
trace: ‘on-first-retry’
},
projects: [
{
name: ‘chromium’,
use: { …devices[‘Desktop Chrome’] }
},
{
name: ‘firefox’,
use: { …devices[‘Desktop Firefox’] }
},
{
name: ‘webkit’,
use: { …devices[‘Desktop Safari’] }
}
]
});
This configuration introduces several important Playwright concepts.
testDir
Defines where tests are located.
fullyParallel
Allows tests to run independently in parallel where configured.
retries
Can provide limited retries in CI.
reporter
Defines the reporting format.
baseURL
Allows you to write:
await page.goto(‘/login’);
instead of:
await page.goto(‘https://example.com/login’);
projects
Defines browser configurations.
Playwright projects can represent different browsers, devices, environments, or configurations.
Step 16: Run Tests Across Chromium, Firefox, and WebKit
Once the projects are configured:
npx playwright test
runs the configured projects.
To run only Chromium:
npx playwright test –project=chromium
Firefox:
npx playwright test –project=firefox
WebKit:
npx playwright test –project=webkit
Playwright’s project system is designed specifically for running the same tests against different browser and device configurations.
Career Tip
As a QA engineer, do not automatically assume that testing one browser is enough.
Choose browser coverage based on the application’s supported browser matrix and business risk.
Step 17: Create a Real-World Login Automation Example
Once the basic Playwright setup for beginners in VS Code works, replace the sample website with your application’s test environment.
Example:
import { test, expect } from ‘@playwright/test’;
test(‘successful login’, async ({ page }) => {
await page.goto(‘/login’);
await page.getByLabel(‘Username’).fill(‘testuser’);
await page.getByLabel(‘Password’).fill(‘Password123’);
await page.getByRole(‘button’, {
name: ‘Login’
}).click();
await expect(page).toHaveURL(/dashboard/);
await expect(
page.getByRole(‘heading’, {
name: ‘Dashboard’
})
).toBeVisible();
});
Replace the URL, labels, credentials, and expected dashboard elements with those from your application.
Why This Is Better Than a Hello World Test
You now have a complete QA workflow:
Open application
↓
Enter credentials
↓
Click Login
↓
Validate navigation
↓
Validate dashboard
This is the point where a beginner tutorial becomes practical Playwright automation testing.
Step 18: Keep Credentials Outside Your Source Code
Do not commit real passwords.
Instead:
const username = process.env.TEST_USERNAME;
const password = process.env.TEST_PASSWORD;
if (!username || !password) {
throw new Error(‘Test credentials are not configured’);
}
await page.getByLabel(‘Username’).fill(username);
await page.getByLabel(‘Password’).fill(password);
Use environment variables locally and secret storage in CI.
This is an important Playwright setup best practice for beginners.
Step 19: Basic CI/CD Setup
A basic GitHub Actions workflow can execute Playwright tests after code changes.
Create:
.github/workflows/playwright.yml
Use:
name: Playwright Tests
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
– name: Checkout repository
uses: actions/checkout@v4
– name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
– name: Install dependencies
run: npm ci
– name: Install Playwright browsers
run: npx playwright install –with-deps
– name: Run Playwright tests
run: npx playwright test
env:
CI: true
Playwright’s CI guidance uses the same general flow: install dependencies, install browsers and required system dependencies where needed, then run the tests.
Career Tip
For SDET roles, learn how to explain this pipeline in interviews:
The CI pipeline checks out the code, installs Node dependencies, installs Playwright browsers, runs the test suite, and publishes test artifacts when required.
Common Playwright VS Code Setup Errors and Solutions
Error 1: node is not recognized
Cause
Node.js is not installed or is missing from PATH.
Solution
Check:
node –version
If it fails, install Node.js and restart VS Code.
On Windows, reopening the terminal after installation is often necessary for PATH changes to become available.
Error 2: npm is not recognized
Cause
Node.js/npm is not available through PATH.
Solution
Restart VS Code and check:
npm –version
If it still fails, verify the Node.js installation and Windows PATH configuration.
Error 3: Cannot find module @playwright/test
Cause
Dependencies are missing or the terminal is in the wrong folder.
Solution
Run:
npm install
Then:
npx playwright test
Make sure your terminal is inside the project directory containing package.json.
Error 4: Browser executable doesn’t exist
Run:
npx playwright install
For Linux CI:
npx playwright install –with-deps
Error 5: Tests do not appear in VS Code
Check:
- Playwright extension is installed
- Correct project folder is open
- Test file uses .spec.ts or .test.ts
- testDir is correct
- Dependencies are installed
- VS Code has been reloaded
Error 6: TypeScript Errors
If VS Code highlights Playwright imports in red:
import { test, expect } from ‘@playwright/test’;
check:
npm install
Then confirm that @playwright/test exists in package.json.
Also check your TypeScript configuration.
Error 7: Wrong Working Directory
This is especially common for beginners.
Suppose your project is:
C:\Users\User\playwright-vscode-demo
Your terminal should be inside that directory before running:
npx playwright test
Use:
pwd
on macOS/Linux, or:
Get-Location
in PowerShell.
Playwright Setup Best Practices for Beginners
Use this checklist after completing your setup.
- Node.js works from the terminal.
- npm works from the terminal.
- VS Code is installed.
- Official Playwright extension is installed.
- Playwright project is initialized.
- Browsers are installed.
- First TypeScript test passes.
- Tests can run from the terminal.
- Tests appear in VS Code Testing.
- Debugging works with breakpoints.
- HTML reporting works.
- Screenshots/traces are configured appropriately.
- Browser projects are understood.
- Credentials are not hard-coded.
- CI can install browsers and run tests.
Avoid These Beginner Habits
Do not:
- Use waitForTimeout() for every synchronization problem.
- Hard-code passwords.
- Use fragile XPath for every element.
- Build a huge framework before writing tests.
- Ignore failed tests because they pass after retries.
- Test only locally.
- Assume one browser represents all users.
Playwright VS Code Setup Interview Questions
1. How do you install Playwright in VS Code?
You can install the official Playwright VS Code extension and initialize a project using the Command Palette or terminal:
npm init playwright@latest
2. How do you install Playwright browsers?
npx playwright install
3. How do you run Playwright tests?
npx playwright test
4. How do you run a Playwright test in headed mode?
npx playwright test –headed
5. How do you debug Playwright tests?
Use VS Code breakpoints and Debug Test, or run:
npx playwright test –debug
6. What does playwright.config.ts do?
It centralizes test configuration such as browser projects, timeouts, retries, reporters, base URLs, screenshots, videos, and traces.
7. Why use Playwright projects?
Projects let you execute tests using different browsers, devices, environments, or configurations.
8. How would you troubleshoot tests missing from VS Code?
Check the extension, project directory, test naming, testDir, installed dependencies, and Playwright configuration.
Playwright Learning Roadmap After VS Code Setup
Completing the Playwright setup for beginners in VS Code is only the first step.
Follow this learning path.
Level 1: Playwright Fundamentals
Learn:
- Playwright Basics
- Playwright for Beginners
- Playwright Installation Guide
- Playwright Getting Started Guide
- Playwright First Test Script
- Playwright Hello World Test
- Playwright Simple Example
- Playwright Basic Commands
- Playwright Learning Roadmap
Level 2: UI Automation
Learn:
- Playwright TypeScript
- Playwright Locators
- Playwright Auto Waiting
- Forms
- Dropdowns
- Frames
- Popups
- Keyboard and mouse actions
Level 3: Framework Design
Learn:
- Playwright Page Object Model
- Playwright Fixtures Tutorial
- Test data
- Environment configuration
- Authentication
- Reusable utilities
Level 4: Advanced Testing
Learn:
- Playwright API Testing
- Playwright Authentication Tutorial
- Playwright Reporting Tutorial
- Playwright Parallel Execution Tutorial
- Cross-browser testing
- Network mocking
- Test isolation
Level 5: DevOps
Learn:
- Playwright CI/CD Tutorial
- Playwright GitHub Actions Tutorial
- Playwright Docker Tutorial
- Test artifacts
- CI debugging
- Parallel CI execution
Level 6: Career Preparation
Finally, study:
- Playwright Troubleshooting
- Playwright Interview Questions
- Framework design interview questions
- SDET scenario-based questions
For someone transitioning from Selenium, focus especially on the differences in locators, auto-waiting, fixtures, browser contexts, isolation, tracing, and Playwright’s built-in test runner.
FAQs: Playwright Setup for Beginners in VS Code
How do I install Playwright in VS Code?
Install the official Playwright Test extension, create or open a Node.js project, and initialize Playwright using:
npm init playwright@latest
You can also use the VS Code Command Palette and the Test: Install Playwright command.
How do I set up Playwright in VS Code for beginners?
Install Node.js and VS Code, install the Playwright extension, initialize a TypeScript Playwright project, install browsers, create a .spec.ts test, and run it using either the terminal or VS Code Testing interface.
Is VS Code good for Playwright automation?
Yes. The official Playwright VS Code extension supports running tests, debugging, browser selection, test generation, locator picking, and trace inspection.
What should I install before Playwright?
You need Node.js and VS Code for a typical Playwright TypeScript setup. Basic TypeScript or JavaScript knowledge is also helpful.
How do I install Playwright browsers?
Run:
npx playwright install
For Linux environments that need system dependencies:
npx playwright install –with-deps
How do I run Playwright from VS Code?
Open the Testing sidebar and click the play icon next to a test. You can also use the integrated terminal:
npx playwright test
How do I debug Playwright in VS Code?
Set a breakpoint, right-click the test, and select Debug Test. The official extension supports breakpoints and step-by-step debugging.
How do I run Playwright on different browsers?
Configure Chromium, Firefox, and WebKit as projects in playwright.config.ts, then run:
npx playwright test
or a specific project:
npx playwright test –project=firefox
Can I use Playwright with TypeScript?
Yes. TypeScript is a standard option when creating a Playwright project, and Playwright’s Node.js test runner is designed to work with JavaScript and TypeScript.
Why is my Playwright test not appearing in VS Code?
Check that the Playwright extension is installed, the correct project folder is open, the test has a supported filename such as .spec.ts, dependencies are installed, and your testDir configuration points to the correct directory.
