测试自动化套件

一个全面的Playwright测试自动化套件,支持Jira/Xray集成、Allure报告、自愈定位器和API测试。

  • by k2011rajesh
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 k2011rajesh/playwrightMCP

使用说明

剧作家MCP-测试自动化套件

全面的Playwright测试自动化套件,具有Jira/Xray集成、诱惑报告、自我修复定位器和API测试。

📊 实时报告和仪表板

特性

  • UI测试: 采用自愈定位策略的Playwright浏览器自动化
  • API测试: 使用GET、POST、PUT、DELETE操作进行REST API测试
  • 自我修复: 具有多策略回退和重试逻辑的弹性定位器
  • 诱惑报告: 带有时间线和指标的精美交互式测试报告
  • 电子邮件通知: 自动通知k2011.rajesh@gmail.com每次生成报告后
  • Jira集成: 使用Jira问题密钥自动映射测试用例
  • X射线上传: 通过X射线云API将测试结果直接导入Jira
  • CI/CD就绪: GitHub Actions工作流,具有自动报告发布功能
  • Git集成: 完成版本控制设置
  • GitHub页面: 测试报告的实时仪表板

快速开始

先决条件

  • Node.js 16+
  • npm或纱线
  • Git

安装

git clone <repository>
cd PlaywrightMCP
npm install
npx playwright install

运行测试

# Run all tests (UI + API)
npm run test:local

# Run API tests only
npm run test:api

# Run UI tests only
npx playwright test tests/self-healing.spec.ts tests/demo.spec.ts

# Run single URL test
npm run test:single

# Run with JUnit reporter
npm test

查看报告

# Generate and open Allure report
npm run allure:report

# Just open existing report
npm run allure:open

# Run tests, generate report, and send email notification
npm run test:full

# Send email for existing report
npm run notify:email

📧 电子邮件通知

每当测试完成并生成报告时,都会收到自动电子邮件通知!

设置(一次性)

  1. 启用两步验证 在您的Gmail帐户上
  2. 生成应用程序密码 在https://myaccount.google.com/apppasswords
  3. 添加GitHub机密:
    • EMAIL_FROM:您的Gmail地址
    • EMAIL_PASSWORD:生成的应用程序密码
    • EMAIL_TO:收件人电子邮件(可选)

本地测试

# Set environment variables (PowerShell example)
$env:EMAIL_FROM = "your-email@gmail.com"
$env:EMAIL_PASSWORD = "your-app-password"
$env:EMAIL_TO = "recipient@gmail.com"

# Run tests and send email
npm run test:full

# Or just send email for existing report
npm run notify:email

→ 完整指南: 电子邮件_通知_SETUP.md

测试用例摘要

总计:14次测试(100%通过率)

API测试(10次测试- tests/api.spec.ts)

  • PROJ-201到PROJ-210:JSON占位符和httpbin REST API

UI测试(4个测试)

  • PROJ-101:主页剧作家(demo.spec)
  • PROJ-102:自我修复演示网站(自我修复.spec.ts)
  • PROJ-103:自愈形式互动
  • 单URL运行(singlespec.ts)

Git工作流

初始设置

# Repository already initialized with .gitignore
git config user.name "Your Name"
git config user.email "your.email@example.com"

# Add all files
git add .

# Initial commit
git commit -m "Initial: Playwright suite with API, UI, self-healing, and Jira integration"

# Push to remote (after adding remote)
git remote add origin <your-repo-url>
git branch -M main
git push -u origin main

功能分支工作流

# Create feature branch
git checkout -b feature/new-tests

# Make changes and test
npm run test:local

# Commit changes
git add .
git commit -m "feat: add new test cases"

# Push to remote
git push origin feature/new-tests

# Create Pull Request on GitHub
# GitHub Actions will automatically run tests
## npm Scripts

```bash
npm test                # Run all with JUnit
npm run test:local      # Run all locally
npm run test:api        # API tests only
npm run test:single     # Single URL test
npm run test:allure     # Tests + Allure report
npm run test:full       # Tests + Allure + Email notification
npm run allure:open     # Open Allure report
npm run allure:report   # Tests + open report
npm run upload:xray     # Upload to Xray
npm run notify:email    # Send email for existing report

GitHub操作CI/CD

对每个推送和拉取请求进行自动测试:

  • 继续运行 main 和 develop 分支
  • 安装依赖项
  • 运行所有剧作家测试
  • 生成Allure报告
  • 发送电子邮件通知(如果已配置)
  • 上传工件
  • 部署到GitHub页面
  • 对带有结果的PR的评论

工作流文件: .github/workflows/playwright-tests.yml

Jira/X射线集成

将结果上传到Xray

export XRAY_CLIENT_ID=<your_client_id>
export XRAY_CLIENT_SECRET=<your_client_secret>
export XRAY_TEST_EXEC=PROJ-EXEC-1  # Optional

npm run upload:xray

项目结构

.
├── tests/
│   ├── api.spec.ts              # API tests
│   ├── demo.spec.ts             # Demo UI test
│   ├── self-healing.spec.ts     # Self-healing tests
│   ├── single.spec.ts           # Single URL test
│   └── helpers/
│       └── self-healing.ts      # Locator utilities
├── scripts/
│   ├── upload-xray.js           # Xray upload
│   └── xray-samples.md          # API docs
├── .github/
│   └── workflows/
│       └── playwright-tests.yml # CI/CD
├── .gitignore                    # Git ignore rules
├── playwright.config.ts          # Playwright config
├── package.json                  # Dependencies
└── README.md                     # This file

配置文件

微笑。

不包括:node_modules、测试结果、诱惑报告、IDE文件、日志

.github/workflows/playwright-tests.yml

用于自动化测试和报告的GitHub Actions工作流

剧作家配置ts

  • 记者:JUnit+Alure
  • 浏览器:Chromium(无头)
  • 测试目录: ./tests

故障排除

API测试不在诱惑?

rm -rf allure-results allure-report
npm run test:local
npm run allure:open

Git提交失败?

# Check git config
git config --list

# Set credentials if needed
git config --global user.name "Your Name"
git config --global user.email "email@example.com"

本地测试失败?

npx playwright install
npm run test:local --headed  # View browser

许可证

国际学生委员会