How to Run Playwright Tests in VS Code: Complete Beginner Guide
If you are learning Playwright and already use Visual Studio Code, you do not need to run every test only from the terminal. The official Playwright VS Code extension lets you discover tests, run individual tests, run complete test files, debug failures, select browser projects, record tests, and work with Playwright tools directly inside VS Code.
This makes the development process easier because your test code, execution controls, browser projects, and test results are available in one editor.
In this guide, you will learn how to set up Playwright in VS Code, run a single test, run all tests, debug failures, select browsers, use the Testing sidebar, and troubleshoot common problems.
How Can You Execute Playwright Tests in VS Code?
To run Playwright tests in VS Code:
Install Node.js and Visual Studio Code.
Install the official Playwright extension from Microsoft.
Create or open a Playwright project.
Open the Testing sidebar in VS Code.
Find your Playwright test.
Click the green play button next to the test.
Use Debug Test when you need to investigate a failure.
The official Playwright VS Code extension also provides features such as test recording, locator picking, browser selection, and trace-related tools.
What is Playwright VS Code integration?
Playwright VS Code integration connects Playwright Test with the Visual Studio Code editor.
Instead of switching repeatedly between your code editor and terminal, you can use the VS Code Testing interface to find and execute tests.
For example, suppose you have:
playwright-project/
├── tests/
│ └── login.spec.ts
├── playwright.config.ts
├── package.json
└── playwright-report/
You can open login.spec.ts, see the tests in the Testing sidebar, and run an individual test without manually typing the complete command.
This is especially useful for beginners because the editor shows which tests passed and which tests failed.
Step 1: Install Node.js and VS Code
Playwright runs on Node.js, so Node.js should be available on your machine.
You also need Visual Studio Code.
The official Playwright documentation lists Node.js and Visual Studio Code as prerequisites for its VS Code integration.
After installation, verify Node.js from the terminal:
node --version
You can also check npm:
npm --version
If both commands return versions, your Node.js environment is available.
Step 2: Install the Playwright VS Code extension
Open VS Code.
Go to:
Extensions → Search for Playwright
Install the official Playwright extension from Microsoft.
The extension adds Playwright testing features to the editor, including test execution and debugging.
Step 3: Install and Configure Playwright
If you already have a Playwright project, open that project folder in VS Code.
If you are starting from an existing Node.js project, Playwright can be installed according to the current Playwright setup process.
The VS Code extension also provides:
Command Palette → Test: Install Playwright
This can be used to install Playwright and select the browsers you want to test.
Step 4: Open the Testing sidebar
Locate the Activity Bar on the left side of the VS Code window.
Select the Testing icon.
The Testing sidebar displays your discovered tests.
For a Playwright project, this becomes your central place for running and debugging tests.
You may see something similar to:
Testing
Playwright
login.spec.ts
Login test
Invalid login test
The exact display depends on your project.
Step 5: Run one Playwright test
Open a test file such as:
import { test, expect } from '@playwright/test';
test('login page opens', async ({ page }) => {
await page.goto('/login');
await expect(
page.getByRole('heading', { name: 'Login' })
).toBeVisible();
});
You should see a green play icon near the test.
Click it.
VS Code runs that test and displays the result.
A successful test is shown as passed, while a failed test provides information that can help you investigate the problem. The official extension documentation describes this green play-button workflow for individual tests.
Step 6: Run all Playwright tests
You do not have to execute tests individually.
From the Testing sidebar, click the play button at the appropriate project or test-suite level.
You can run:
One test
All tests in a file
All tests in the project
Tests for selected browser projects
The official Playwright extension supports running tests at different levels from the Testing interface.
You can also run everything from the terminal:
npx playwright test
By default, Playwright runs tests in headless mode and uses the browser projects configured in playwright.config.ts.
Step 7: Run a test with the browser visible
Sometimes you want to watch what Playwright is doing.
You can use headed execution from the command line:
npx playwright test --headed
The --headed option allows you to see the browser while the test runs.
The VS Code extension also provides a Show Browser option.
This is useful when you want to visually understand actions such as:
Open page
↓
Enter username
↓
Enter password
↓
Click Login
↓
Verify dashboard
Step 8: Find and Fix Playwright Test Failures
Running a test tells you that something failed.
Debugging helps you understand why it failed.
Place a breakpoint on a line in your test.
Then use the VS Code Playwright controls to debug the test.
For example:
test('login', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Username').fill('tester');
await page.getByLabel('Password').fill('password');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByText('Dashboard')).toBeVisible();
});
If the test stops at the button click, you can inspect what happens before and after that action.
Playwright's documentation recommends debugging locally through VS Code with the Playwright extension.
Step 9: Select different browsers
Modern web applications may need testing across Chromium, Firefox, and WebKit.
Playwright uses projects to represent different configurations, often including different browsers.
For example:
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
]
The VS Code Playwright sidebar lets you select projects and execute tests against the configurations you need.
You can also use the CLI:
npx playwright test --project=webkit
Playwright supports running tests against configured browser projects using --project.
Step 10: Use Playwright UI Mode when you need deeper debugging
VS Code is not the only visual testing option.
Playwright also provides UI Mode.
You can start it with:
npx playwright test --ui
UI Mode provides a visual way to inspect test execution, including steps and debugging information.
This is useful when a failure is difficult to understand from terminal output alone.
Troubleshooting Playwright Tests in VS Code
Tests are not appearing
First check that:
The correct project folder is open.
Playwright is installed.
Your test files are inside the configured test directory.
The Playwright extension is installed.
Your configuration file is valid.
The testDir option controls where Playwright looks for tests.
The browser does not open
This may be expected.
Playwright runs tests in headless mode by default.
Use headed execution when you need to see the browser:
npx playwright test --headed
The test works in one browser but fails in another
Check the browser project configuration.
A test may expose browser-specific behavior that is not visible in another engine.
Run the test against the required projects before concluding that the application behaves consistently.
A test passes locally but fails in CI
Check configuration such as:
Retries
Workers
Browser projects
Environment variables
Base URL
Web server
Authentication
Trace collection
Playwright's configuration supports options specifically useful for CI environments, including retries and worker configuration.
Best Ways to Write Playwright Tests in VS Code
Keep tests small enough to understand.
Use meaningful test names.
Prefer reliable locators.
Use Playwright's web-first assertions instead of manually checking values without waiting.
For example:
await expect(page.getByText('Welcome')).toBeVisible();
rather than immediately checking a boolean state.
Playwright specifically recommends web-first assertions because they wait for the expected condition.
Also keep your configuration in playwright.config.ts instead of scattering execution settings throughout test files.
FAQs
Is It Possible to Run Playwright Tests in VS Code?
Yes. The official Playwright VS Code extension lets you run individual tests, test files, and test suites through the Testing interface.
Do I need the VS Code extension to run Playwright?
No. You can run Playwright from the command line with npx playwright test. The extension provides an integrated VS Code experience.
Is Playwright Debugging Available in VS Code?
Yes. You can set breakpoints and debug tests through the Playwright VS Code extension.
How to Run Playwright Tests Across Different Browsers in VS Code ?
Yes. Playwright projects can represent different browser configurations, and the VS Code extension allows you to select projects.
What command runs all Playwright tests?
Use:
npx playwright test
How do I see the browser during execution?
Use headed mode or the browser-display options available through the Playwright VS Code integration.
Can I use Playwright UI Mode with VS Code?
Yes. UI Mode is available through the Playwright CLI and can complement the VS Code workflow.
Conclusion
Playwright VS Code integration makes test development easier by bringing test discovery, execution, debugging, browser projects, recording, and other testing tools into the editor.
A practical learning path is:
Install Playwright → Create tests → Learn locators → Learn assertions → Run tests in VS Code → Debug failures → Configure browsers → Run tests in CI/CD
If you are building your Playwright skills step by step, continue with a guide on Playwright locators and then explore Playwright assertions.
For learners building a complete automation-testing foundation, the Playwright syllabus can help organize the topics you need to study.

Comments
Post a Comment