# playwright 微软对标 selenium 浏览器自动化测试工具,支持nodejs,python等多语言sdk ## Usage 使用超级简单,代码运行后会自动下载最新版chrome,edge,firefox,ffmpeg ,以及driver,600MB,首次运行需要下载环境。 ``` ``` windows保存到 : C:\Users\xx\AppData\Local\ms-playwright 初始化一个项目: ``` npm init playwright@latest new-project #pip download playwright -d ./down pip install playwright==1.33.0 playwright install playwright install-deps ``` python: ``` from playwright.sync_api import sync_playwright ``` 代码生成: ``` playwright codegen https://playwright.dev ``` 访问 xx 链接的所有点击,表单等操作都会生成代码,类似于脚本录制。 需要更多自定义,采用 selenium ## MCP server 可以通过python 或者 nodejs 安装 playwright , ``` npm install -g @playwright/mcp@latest npm install -g @playwright@latest npx playwright install --with-deps ``` 然后再 vscode, cherry-studio,Claude ,Cursor、Windsurf、Cline 等安装 mcp server: ``` { "mcpServers": { "playwright": { "command": "cmd /c npx", // windows "command": "npx", "args": [ "@playwright/mcp@latest" ] } } } # 或者 { "mcpServers": { "playwright": { "command": "npx", "args": ["-y", "@executeautomation/playwright-mcp-server"] } } } # vscode 安装 playwright mcp server code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}' ``` 提示词: ``` 使用mcp,将 @星巴克营销活动配置数据.md 中的活动一数据填入 @starbucks_marketing_form.html 打开哔哩哔哩,搜索 playwright,点击第一条搜索结果,点击播放按钮,播放3s钟之后,点击暂停。 ``` ## Reference - [playwright](https://playwright.dev/)官网 - [microsoft/playwright-mcp](https://github.com/microsoft/playwright-mcp)