Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run Playwright tests in VS Code, install Microsoft’s Playwright extension, open the project’s Testing view, and click the play icon beside a test, file, or suite. For a terminal run, use npx playwright test. The extension also lets you select browser projects, watch headed runs, and debug tests from the editor.

Set up Playwright in a VS Code project

You need Node.js, Visual Studio Code, and a project folder. The official Node.js guide recommends an LTS release. Playwright’s VS Code extension integrates Playwright Test into the editor; its installation command scaffolds a test project and can install the browser projects you choose.

  1. Install Node.js and VS Code if they are not already installed.
  2. Open VS Code’s Extensions view with Ctrl+Shift+X on Windows or Linux, or Cmd+Shift+X on macOS. Search for and install Microsoft’s official Playwright extension.
  3. Open the folder where you want the project to live. If you already have a Playwright project, open its root folder—the one containing its package metadata or Playwright configuration.
  4. Open the Command Palette with Ctrl+Shift+P or Cmd+Shift+P. Run Test: Install Playwright.
  5. Select the browser projects you want, such as Chromium, Firefox, or WebKit. The installer can also add a GitHub Actions workflow.

For a new project, the scaffold creates package metadata, playwright.config.ts, and an example test directory. The configuration is where the project’s test directory, browser projects, timeouts, retries, and reporters are set. Existing projects may already have different names or settings, so check their configuration rather than assuming the defaults.

Know whether you have a test or a standalone script

The VS Code Testing view is designed around Playwright Test: tests discovered from files and configuration. A standalone Node.js file that uses Playwright’s browser API can be launched from VS Code’s integrated terminal with Node, but it will not necessarily appear as a test in that view. If you want the extension’s per-test run and debug controls, write the browser flow as a Playwright Test test and ensure it is inside the configured test directory.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a test you can run

In a scaffolded project, open the example test or create a file such as tests/homepage.spec.ts (use the directory specified by testDir in your configuration). This basic test opens a page and checks its title:

import { test, expect } from '@playwright/test';

test('homepage has the expected title', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example Domain/);
});

This is a Playwright Test file, not a browser-only script to run with node. The Playwright Test runner discovers it, supplies the page fixture, and reports the assertion result. Replace the example URL and expected title with the page and condition your own test needs.

Run a test, file, or suite from VS Code

  1. Open the Testing icon in the VS Code Activity Bar.
  2. Wait for Playwright tests to appear in the tree. Expand the tree to locate a particular test or test file.
  3. Click the green play icon beside a single test to run just that test. Use the icon beside a test file to run that file, or the top-level play icon to run the suite.
  4. To choose browsers or other configured variants, use the project checkboxes in the Playwright sidebar. Select only the project or projects you want to run.
  5. To watch a browser window during execution, enable Show Browsers. Leave it disabled for a headless run.

The result appears in the Testing interface, where you can inspect passed and failed tests. A test’s green play icon is the most direct choice for a quick check; running the file or suite is more useful when you need to see whether a change affects neighboring tests.

Run Playwright from the integrated terminal

Open VS Code’s integrated terminal in the project root and run the full configured suite:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npx playwright test

To run one configured browser project, use its project name. For example, if the configuration defines a project named firefox:

npx playwright test --project=firefox

The value after --project= must match a project name in playwright.config.ts; it is not automatically the browser’s name in every project. The same terminal command is useful when a test does not appear in the Testing view or when you want the runner’s command-line output.

Rank #4
The Web Testing Handbook
  • Used Book in Good Condition
What you want to do VS Code Terminal
Run one test Click the play icon beside that test. Use the runner’s test selection options; see npx playwright test --help for the installed runner’s syntax.
Run a file or the full suite Click the play icon beside the file or at the top of the Testing tree. Run npx playwright test for the configured suite.
Run one browser project Select the project in the Playwright sidebar. Use npx playwright test --project=firefox, replacing firefox with a configured project name.
See the browser window Enable Show Browsers. Use the headed option supported by the installed Playwright runner, or use the VS Code control.

VS Code’s selected projects and a terminal command’s --project target are separate ways to choose execution scope. If the browser is not the one you expected, inspect both the project selection and the names defined in the configuration.

Choose headed or headless execution

A headed run displays a browser window, which helps when you need to observe navigation, overlays, or a failing interaction. In VS Code, enable Show Browsers before running the test. A headless run does not show a window and is generally the more convenient choice for ordinary automated execution; leave Show Browsers disabled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Browser selection and visibility are different decisions: a project determines which configured browser or environment runs, while headed versus headless determines whether you watch the window. A project can be selected without turning on visible browser windows.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Debug a failing test in the editor

  1. Open the test file and click in the gutter beside the line where you want execution to pause to set a breakpoint.
  2. In the Testing view, right-click the test and choose Debug Test.
  3. When execution pauses, inspect variables and the current failure in VS Code’s debugging controls.
  4. Use the Playwright sidebar’s Show Trace Viewer when you need to inspect the recorded test trace, or use Pick locator to help identify an element.

The sidebar also offers Record new and Record at cursor for authoring. Playwright code generation prioritizes role, text, and test-id locators when generating actions. Treat generated steps as a starting point: check that the resulting locator identifies the intended element and that the test asserts the outcome you actually care about.

Or skip the browser setup

If your goal is a screenshot of a URL rather than a Playwright interaction or assertion, ScreenshotNeo can return an image or PDF from one request. It is a screenshot API and MCP server, not a replacement for Playwright Test. Cookie banners are accepted and removed before capture, and known newsletter popups and chat widgets are removed; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

For example, the cURL request below captures a page as WebP. The ScreenshotNeo API documentation describes the request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same request in Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

Or in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Free includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Troubleshoot missing tests, browser selection, and failures

  • No tests appear: Confirm Playwright is installed in the workspace, that VS Code has the project root open, and that playwright.config.ts points testDir at the directory containing the test files. A standalone browser script may not be discovered as a Playwright Test test.
  • The wrong browser runs: Check the selected project in the Playwright sidebar and the projects section of playwright.config.ts. From the terminal, confirm that the name passed to --project matches the configuration.
  • A browser is missing or will not launch: Rerun Test: Install Playwright from the Command Palette, selecting the browser project you need, or install the required Playwright browser using the project tooling.
  • A test fails or a locator behaves unexpectedly: Use Debug Test, add a breakpoint, and inspect the trace before changing the locator or adding waits. This helps distinguish an incorrect locator or assertion from a load or interaction problem.
  • The visible browser setting seems ignored: Check that Show Browsers is enabled for the VS Code run. Browser visibility is separate from selecting a browser project.

When diagnosing, make one change at a time: first verify that the intended test and project are running, then use debugging and trace information to understand the failure. Changing locators or timing without checking the run context can mask the wrong problem.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.