TrackFlow TestWright MCP服务器
一个MCP(模型上下文协议)服务器,它将TestWright(Playwright)与基于Frappe的应用程序集成在一起,用于自动化测试。
特性
- 对Frappe应用程序运行Playwright测试
- 创建和管理测试文件
- 使用Frappe进行身份验证
- 对Frappe后端进行API调用
- 运行测试套件
安装
- 克隆此存储库:
git clone https://github.com/chinmaybhatk/trackflow-testwright-mcp.git
cd trackflow-testwright-mcp- 安装依赖项:
npm install- 安装Playwright浏览器:
npx playwright install用法
作为MCP服务器
- 启动MCP服务器:
npm start- 配置您的MCP客户端(如Claude)以连接到此服务器。
直接运行测试
# Run all tests
npm test
# Run tests with UI
npm run test:ui
# Run tests in headed mode
npm run test:headed可用的MCP工具
1. run_playwright_test
对Frappe应用程序运行单个Playwright测试。
参数:
testName:测试名称url:Frappe应用程序的URLtestCode:测试的JavaScript代码headless:是否在无头模式下运行(默认值:true)
2. create_test_file
在tests目录中创建新的测试文件。
参数:
fileName:测试文件的名称testContent:测试文件的内容
3. frappe_login
登录Frappe应用程序并返回会话Cookie。
参数:
url:键入应用程序URLusername:用户名password:密码
4. frappe_api_call
对Frappe后端进行API调用。
参数:
url:键入应用程序URLmethod:HTTP方法(GET、POST、PUT、DELETE)endpoint:API端点data:请求数据(可选)cookies:会话Cookie(可选)
5. run_test_suite
运行与模式匹配的所有测试。
参数:
pattern:测试文件模式(默认:“\*.spec.js”)headless:是否在无头模式下运行(默认值:true)
环境变量
FRAPPE_URL:Frappe应用程序的基本URL(默认值:http://localhost:8000)FRAPPE_USER:测试的默认用户名FRAPPE_PASSWORD:测试的默认密码
示例测试
import { test, expect } from '@playwright/test';
test('should create a new document', async ({ page }) => {
// Login
await page.goto('/login');
await page.fill('input[name="usr"]', 'administrator');
await page.fill('input[name="pwd"]', 'admin');
await page.click('button[type="submit"]');
// Navigate to DocType
await page.goto('/app/your-doctype');
// Create new document
await page.click('button:has-text("New")');
await page.fill('input[name="field_name"]', 'Test Value');
await page.click('button:has-text("Save")');
// Verify
await expect(page.locator('.toast-message')).toContainText('Saved');
});与Claude整合
要将此MCP服务器与Claude一起使用:
- 将服务器配置添加到MCP设置中
- 然后,Claude可以使用这些工具:
- 编写并执行测试 - 调试测试失败 - 创建测试套件 - 与Frappe应用程序交互
许可证
麻省理工学院
