docs/src/getting-started-vscode-js.md
import LiteYouTube from '@site/src/components/LiteYouTube';
The Playwright VS Code extension brings the power of Playwright Test directly into your editor, allowing you to run, debug, and generate tests with a seamless UI-driven experience. This guide will walk you through setting up the extension and using its core features to supercharge your end-to-end testing workflow.
<LiteYouTube id="WvsLGZnHmzw" title="Getting Started with Playwright in VS Code" />
Before you begin, make sure you have the following installed:
Ctrl+Shift+X or Cmd+Shift+X) and search for "Playwright". Install the official extension from Microsoft.Ctrl+Shift+P or Cmd+Shift+P) and run the Test: Install Playwright command.playwright.config.ts file.Click the Testing icon in the VS Code Activity Bar to open the Test Explorer. Here, you'll find your tests, as well as the Playwright sidebar for managing projects, tools, and settings.
<LiteYouTube id="mQmcIBMsc38" title="Running Playwright Tests in VS Code" />
<LiteYouTube id="tJF7UhA59Gc" title="Debugging Playwright tests in VS Code" />
The VS Code extension provides powerful debugging tools to help you identify and fix issues in your tests. You can set breakpoints, inspect variables, view detailed error messages, get AI-powered suggestions to resolve test failures, and use the comprehensive trace viewer to analyze test execution step-by-step.
Using Breakpoints: Set a breakpoint by clicking in the gutter next to a line number. Right-click the test and select Debug Test. The test will pause at your breakpoint, allowing you to inspect variables and step through the code.
Live Debugging: With Show Browsers enabled, click on a locator in your code. Playwright will highlight the corresponding element in the browser, making it easy to verify locators.
Debugging with Trace Viewer: For comprehensive debugging, enable the Show Trace Viewer option in the Playwright sidebar. When your test finishes, a detailed trace will automatically open, providing you with a complete timeline of your test execution. The trace viewer is particularly useful for:
The trace viewer is especially valuable when debugging flaky tests or understanding complex user interactions.
To learn more, see our Trace Viewer guide.
CodeGen is Playwright's powerful test generation tool that automatically creates test code by recording your interactions with a web page. Instead of writing tests from scratch, you can simply navigate through your application while CodeGen captures your actions and converts them into reliable test code with proper locators and assertions.
<LiteYouTube id="5XIZPqKkdBA" title="Generating Playwright tests in VS Code" />
Record at Cursor: Place your cursor inside an existing test and click Record at cursor to add new actions at that specific point.
Pick a Locator: Use the Pick locator tool to click on any element in the opened browser. Playwright will determine the best locator and copy it to your clipboard, ready to be pasted into your code.
To learn more, see our CodeGen guide.
Use project dependencies to define setup tests that run before other tests. For example, you can create a login test that runs first, then reuse that authenticated state across multiple tests without having to log in again for each test. In VS Code, you can see these setup tests in the Test Explorer and run them independently when needed.
To learn more, see our Project Dependencies guide.
For tasks that need to run only once before all tests (like seeding a database), use Global Setup. You can trigger the global setup and teardown manually from the Playwright sidebar.
If you have multiple playwright.config.ts files, you can switch between them using the gear icon in the Playwright sidebar. This allows you to easily work with different test suites or environments.
| Action | How to do it in VS Code |
|---|---|
| Install Playwright | Command Palette → Test: Install Playwright |
| Run a Test | Click the "play" icon next to the test |
| Debug a Test | Set a breakpoint, right-click the test → Debug Test |
| Show Live Browser | Enable Show Browsers in the Playwright sidebar |
| Record a New Test | Click Record new in the Playwright sidebar |
| Pick a Locator | Click Pick locator in the Playwright sidebar |
| View Test Trace | Enable Show Trace Viewer in the Playwright sidebar |