playwright-cli 是做什麼的?
自動化瀏覽器操作、測試網頁並處理 Playwright 測試。
概觀
此技能讓開發者能夠使用 Microsoft 的 Playwright CLI 工具來自動化瀏覽器互動。支援多種瀏覽器(Chromium、Firefox、WebKit),可用於端對端測試、網頁擷取、表單填寫及螢幕截圖。
常用指令
npx playwright test— 執行所有測試npx playwright test --headed— 以可見視窗執行測試npx playwright show-report— 檢視測試報告npx playwright codegen— 記錄使用者操作並產生測試程式碼
使用範例
執行單一測試檔案
npx playwright test tests/example.spec.ts
安裝瀏覽器
npx playwright install
使用 codegen 記錄操作
npx playwright codegen https://example.com
設定
專案需要包含 playwright.config.ts(或 playwright.config.js)設定檔,並在 package.json 中安裝 @playwright/test。
{
"devDependencies": {
"@playwright/test": "^1.40.0"
},
"scripts": {
"test": "playwright test"
}
}