Playwright 1.63
Playwright 1.63 是 2026 年 10 月发布的版本,安装流程和以往基本一致,但新增了不少面向 CI、调试和并发控制的新能力。
1. 先确认环境
Playwright Test 推荐使用:
- Node.js 18 / 20 / 22 最新小版本
- macOS、Linux、Windows 均可
- 如果已有项目,直接安装到项目依赖里即可
2. 安装 Playwright 1.63
如果只想用 Playwright Test:
npm install -D @playwright/test@1.63.0如果同时需要浏览器自动化库:
npm install -D playwright@1.63.0安装后检查版本:
npx playwright --version如果输出包含 1.63.0,说明包版本正确。
3. 安装浏览器
npx playwright install这会下载 Chromium、Firefox、WebKit 三个浏览器内核。
如果只想装 Chromium:
npx playwright install chromiumCI 或容器环境建议加上系统依赖:
npx playwright install --with-deps如果希望保留本机已有的其他 Playwright 浏览器,可以使用:
npx playwright install --no-remove4. 初始化一个测试项目
如果是新项目,可以直接用脚手架:
npm init playwright@latest它会生成:
playwright.config.ts
package.json
tests/
example.spec.ts
tests-examples/
demo-todo-app.spec.ts注意:脚手架默认会拉最新稳定版。如果你必须锁定 1.63,建议手动修改 package.json:
{
"devDependencies": {
"@playwright/test": "1.63.0"
}
}然后重新执行:
npm install
npx playwright install5. 运行第一个测试
npx playwright test常用命令:
# 有头模式运行,能看到浏览器
npx playwright test --headed
# 打开 UI 模式
npx playwright test --ui
# 调试模式
npx playwright test --debug
# 只看 HTML 报告
npx playwright show-report6. 简单示例
tests/example.spec.ts:
import { test, expect } from '@playwright/test';
test('打开 Playwright 官网', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});运行:
npx playwright test tests/example.spec.ts7. Playwright 1.63 值得关注的新变化
| 新能力 | 用途 |
|---|---|
| Test locks | 给共享账号、外部服务等用例加互斥锁,避免并发冲突 |
| Reporter 插件化 | ReporterV2 可返回 PluginInfo,报告更可插拔 |
| 多 reporter 并行输出 | 例如 --reporter=line,[{name:'json',outputFile:'e2e.json'}] |
| 跨 frame 定位增强 | page.frame_locator() 无选择器时可在子树任意 frame 中搜索 |
| 仅可见定位器 | locator.visible 替代 :visible 伪类 |
| Trace 增强 | tracing.start() 支持 aria_snapshots、screen_snapshots |
| CLI 改进 | 新增 install --no-remove、codegen --http-credentials |
8. 常见排错
- 浏览器找不到:执行
npx playwright install - 版本不一致:确认
package.json中是1.63.0,再跑npm install - Linux/macOS 权限报错:必要时加
sudo或检查 Node 权限 - CI 中浏览器启动失败:优先使用
npx playwright install --with-deps