1 line
3.5 KiB
JSON
1 line
3.5 KiB
JSON
{"repo": "autotestclass/playwright-mind", "files": {"README.md": {"a0032f2d6e4cf9ab3a257ab42f19d7f678c8bf76": {"t": 1785674232.8223805, "n": 2526, "h": "97dda063e7ab3ebc", "c": "# playwright-mind\n\n> 基于`playwright`和`midscene.js`自动化测试项目,给`Playwright`插上AI的翅膀,目前可以落地的AI自动化测试项目。\n\n__技术栈:__\n\n* [plywright](https://github.com/microsoft/playwright) Web UI自动化测试工具。\n\n* [midscene.js](https://github.com/web-infra-dev/midscene) 提供AI定位断言能力。\n\n\n## 安装与配置\n\n1. 克隆项目到本地:\n\n```shell\ngit clone https://github.com/autotestclass/playwright-mind\n```\n\n2. 安装依赖\n\n```shell\ncd playwright-mind\nnpm install\n```\n\n3. 安装运行浏览器\n\n```shell\nnpx playwright install\n```\n\n4. 配置大模型\n\n> 本项目默认使用 `qwen-vl-max-latest` 模型, 经过验证可用,关键是免费。如果想其他模型请参考midscenejs官方配置。\n\n阿里云百练:https://bailian.console.aliyun.com/\n\n使用其他模型:https://midscenejs.com/zh/model-provider.html\n\n在 `.env` 文件中配置环境变量:\n\n```ts\nexport OPENAI_API_KEY=\"sk-your-key\"\nexport OPENAI_BASE_URL=\"https://dashscope.aliyuncs.com/compatible-mode/v1\"\nexport MIDSCENE_MODEL_NAME=\"qwen-vl-max-latest\"\n```\n\n## 使用示例\n\n在项目的`test`目录,附带了`bing-search-ai-example.spec.ts`例子。\n\n__示例代码__\n\n```ts\nimport { expect } from \"@playwright/test\";\nimport { test } from \"./fixture/fixture\";\n\ntest.beforeEach(async ({ page }) => {\n await page.goto(\"https://cn.bing.com\");\n});\n\ntest('search keyword on bing', async ({ page, ai, aiQuery, aiAssert }) => {\n // 👀 输入关键字,执行搜索\n await ai('搜索输入框输入\"playwright\"关键字,并回车');\n await page.waitForTimeout(3000);\n\n // 👀 找到列表里耳机相关的信息\n const items = await aiQuery(\n 'string[], 搜索结果列表中包含\"playwright\"相关的标题'\n );\n\n console.log(\"search result\", items);\n console.log(\"search result number\", items?.length);\n // 断言大于 1 条搜索结果\n expect(items?.length).toBeGreaterThan(1);\n\n // 👀 用 AI 断言\n await aiAssert('检查搜索结果列表第一条标题是否包含\"playwright\"字符串');\n});\n```\n\n三种关键方法:交互(.ai, .aiAction), 提取 (.aiQuery), 断言 (.aiAssert)。\n\n* `.ai`方法描述步骤并执行交互\n* `.aiQuery` 从 UI 中“理解”并提取数据,返回值是 JSON 格式,你可以尽情描述想要的数据结构\n* `.aiAssert` 来执行断言\n\n__运行测试__\n\n```shell\nnpx playwright test --headed tests/bing-search-ai-example.spec.ts\n\nRunning 1 test using 1 worker\n\n ✓ 1 [chromium] › baidu-search-ai-example.spec.ts:9:5 › search headphone on bing (52.1s)\nsearch result [ 'Playwright 中文网', '快速入门Playwright框架:从零到自动化测试的第一 ...' ]\nsearch result number 2\nMidscene - report file updated: /Users/fnngj/zhpro/github/playwright-mind/midscene_run/report/playwright-merged-2025-01-10_00-44-50-464.html\n\n Slow test file: [chromium] › baidu-search-ai-example.spec.ts (52.1s)\n Consider splitting slow test files to speed up parallel execution\n 1 passed (55.3s)\nMidscene - report file updated: /Users/fnngj/zhpro/github/playwright-mind/midscene_run/report/playwright-merged-2025-01-10_00-44-50-464.html\n```\n\n__测试报告__\n\n\n"}}}} |