Playwright VS Code Development Environment Setup
For Playwright development, it is recommended to use VS Code, because it has strong support for JavaScript/TypeScript, debuggers, and extensions.
Install VS Code
- Go to VS Code official website Download and install.
- After installation, it is recommended to also install the Chinese language pack(search the Extensions marketplace for
Chinese (Simplified))。
VS Code related content reference:https://www.runoob.com/vscode/vscode-tutorial.html
Essential extensions
In the Extensions panel of VS Code, search for and install the following extensions:
Playwright Test for VSCode
- The official Playwright extension
- Features: run/debug test cases, view test reports, record scripts, generate trace
- Extension ID:
ms-playwright.playwright

JavaScript / TypeScript support(built into VS Code; usually no need to install separately)
Recommended (optional):
- ESLint(ensures consistent code style)
- Prettier - Code formatter(one-click code formatting)
Initialize a Playwright project
If you have not initialized a project yet, run:
npm init playwright@lates
The VS Code extension automatically detects the playwright.config.ts/jsin the project and enables the Test view.
VS Code settings
Open VS Code settings (shortcut Ctrl+, or Cmd+,), and confirm the following settings:
-
Format on save
Search
format on save → check Editor: Format On Save
-
Default terminal shell(choose according to your own system)
Recommended for Windows PowerShell or Git Bash
macOS/Linux defaults are fine
Debug configuration (launch.json)
Click on the left side of VS Code Run and Debug → Create a configuration, select Node.js, generating .vscode/launch.json, add a Playwright debug configuration, for example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Playwright Test",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/playwright",
"args": ["test", "--project=chromium", "--headed"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
This way, in VS Code you can press F5 to start debugging; Playwright will run in headed mode for easy observation.
Using the Playwright extension panel
After installing the Playwright Test for VSCode extension, a "Playwright" icon will appear on the left side:
- You can directly see the test files and test case list in the project
- Click the ▶ button to the right of a test case to run it
- Right-click and select Debug Test to step through debugging.
- For failed tests, you can directly view the trace file
Common Commands
Run in the VS Code terminal:
npx playwright test # 运行全部测试
npx playwright test login.spec.js # 运行指定文件
npx playwright codegen # 启动录制工具(自动生成脚本)
npx playwright show-report # 打开测试报告
Testing Sidebar
After installing the extension, a Testing icon (laboratory beaker icon) appears on the left side of VS Code.
Click to enter the Testing Sidebar, where you can see the list of all test files.
Here you can:
- Expand a file to view each
describeandtest - Click the play button to run a single test or all tests
- View test execution status in real time (green = passed, red = failed, gray = skipped)
- Right-click a test for more options (debug, go to definition, etc.)
Debug Mode
The VS Code extension lets you debug Playwright tests just like ordinary code:
Set breakpoints
Click to the left of a code line number to add a red breakpoint.
Right-click beside the breakpoint and select Debug Test; the test will pause at the breakpoint.
Debugging features
- Step over (F10), step into (F11), step out (Shift+F11)
- View current variable values
- View the call stack
- Execute expressions in the debug console
Live Debugging
Live Debugging is a unique feature of the VS Code extension.
When running tests with the Show Browser option enabled, clicking a Locator in the code highlights the corresponding page element in the browser window.
If a Locator matches multiple elements, Playwright highlights all matches at the same time.
You can edit a Locator directly in the code, and the browser shows the updated match results in real time.
Pick Locator
Click the Pick Locator button at the bottom of the Testing Sidebar.
Click the target element in the browser that pops up, and the best locator will appear in VS Code's Pick Locator box.
Press Enter to copy to the clipboard, then paste it into your test code.
Playwright automatically chooses the most stable, most semantic locator strategy (priority: role > text > testid).
Record New Test
Click the Record new button in the Testing Sidebar.
Playwright opens a browser window, and all your actions in it (navigation, clicks, typing) are recorded.
You can also generate assertions through the toolbar:
- Assert visibility -- assert element is visible
- Assert text -- assert element contains text
- Assert value -- assert element's value
After recording, close the browser, and the code is automatically generated in test-1.spec.ts file.
Record at Cursor
In existing test code, place the cursor where you want to insert the action, then click Record at cursor.
Playwright records subsequent actions in the browser and inserts the generated code at the cursor position.
This feature is ideal for adding steps to existing tests.