返回博客
端到端测试
playwright
playwright 的安装
windows 11 的django 项目 建议 pip 包+node安装浏览器
1. 安装 Python 包(使用 pip)
pip install playwright
2. 安装浏览器(使用 npx,更稳定)
npm install -D @playwright/test npx playwright install chromium
Playwright 清理指南
📁 需要检查的目录
1. 浏览器二进制文件(主要)
C:\Users\pxsk\AppData\Local\ms-playwright\
当前状态:
- ✅ chromium-1208 (393 MB) - 旧版本
- ✅ chromium-1217 (406 MB) - 新版本(正在使用)
- ✅ chromium_headless_shell-1208 (257 MB) - 旧版本
- ✅ chromium_headless_shell-1217 (264 MB) - 新版本
- ✅ firefox-1511 (317 MB)
- ✅ webkit-2272 (163 MB)
- ✅ ffmpeg-1011 (3 MB)
- ✅ winldd-1007 (0.2 MB)
总占用: ~1.8 GB
2. Node.js 模块目录
C:\Users\pxsk\.qclaw\workspace\crm\node_modules\@playwright\
C:\Users\pxsk\.qclaw\workspace\crm\node_modules\playwright-core\
3. npm 缓存目录
C:\Users\pxsk\AppData\Local\npm-cache\
🧹 清理方案
方案 1: 保留最新版本,删除旧版本(推荐)
只删除旧版本的 Chromium:
# 删除旧版本 Chromium
Remove-Item -Path "$env:USERPROFILE\AppData\Local\ms-playwright\chromium-1208" -Recurse -Force
Remove-Item -Path "$env:USERPROFILE\AppData\Local\ms-playwright\chromium_headless_shell-1208" -Recurse -Force
可释放空间: ~650 MB
方案 2: 完全重新安装
如果想彻底清理:
# 1. 停止所有使用 Playwright 的进程
# 2. 删除 node_modules
Remove-Item -Path "node_modules" -Recurse -Force
# 3. 删除所有浏览器
Remove-Item -Path "$env:USERPROFILE\AppData\Local\ms-playwright" -Recurse -Force
# 4. 清理 npm 缓存
npm cache clean --force
# 5. 重新安装
npm install
npx playwright install chromium
方案 3: 使用 Playwright 自带工具
# 查看已安装的浏览器
npx playwright install
# 卸载特定浏览器
npx playwright uninstall chromium
# 只安装需要的浏览器(推荐只装 Chromium)
npx playwright install chromium
✅ 验证安装
清理后验证:
# 方法 1: 使用 npx
npx playwright install
# 方法 2: 使用 node 测试
node -e "const { chromium } = require('playwright'); console.log('OK')"
📊 当前版本信息
查看当前使用的版本:
const { chromium } = require('playwright');
console.log(`Playwright version: ${require('playwright/package.json').version}`);
当前安装:
- Chromium: 1217 (最新)
- Firefox: 1511
- WebKit: 2272
💡 建议
- 只保留 Chromium - 如果只需要 Chromium,可以删除 Firefox 和 WebKit
- 定期清理 - 每次 Playwright 升级都会下载新版本,建议定期清理旧版本
- 使用 npx 管理 - 推荐使用
npx playwright install而不是 pip 安装