Skip to main content
Glama

🎭 Playwright MCP - AI 驱动的测试自动化(OrangeHRM)

Playwright TypeScript MCP OrangeHRM

一个概念验证项目,演示了使用 Playwright 集成 模型上下文协议(MCP)AI 驱动的浏览器测试自动化。测试使用 TypeScript 编写,采用 页面对象模型(POM) 设计模式,针对 OrangeHRM 演示应用


📋 目录


Related MCP server: MCP Playwright Server

🎯 概述

本项目展示了 AI + Playwright 如何通过 模型上下文协议(MCP) 使用 纯英文提示 来自动化浏览器测试。无需手动编写每一行自动化代码,您只需用自然语言描述要测试的内容,AI 即可帮助生成并执行自动化操作。

核心概念

组件

作用

类比

LLM(大语言模型)

理解请求并生成指令

🧠 大脑

Agent(智能体)

自动执行任务

⚡ 执行者

MCP(模型上下文协议)

连接 AI 与真实工具(浏览器、API 等)

🔗 翻译器


🏗 架构

           Plain English Prompt
                    │
                    ▼
        Large Language Model (LLM)
                    │
          Generates Instructions
                    │
                    ▼
                AI Agent
                    │
         Executes the Instructions
                    │
                    ▼
      Model Context Protocol (MCP)
                    │
     Connects to Real Applications
                    │
                    ▼
          Playwright + Browser
                    │
                    ▼
          Browser Automation

💻 技术栈

技术

用途

Playwright ^1.60

浏览器自动化框架

TypeScript

编程语言

MCP

AI 与工具间的通信协议

csv-parse

用于数据驱动测试的 CSV 解析

Node.js

运行时环境


📁 项目结构

├── 📂 pages/                          # Page Object Model classes
│   ├── LoginPage.ts                   # Login page locators & actions
│   └── PimPage.ts                     # PIM module locators & actions
│
├── 📂 tests/                          # Test specifications
│   ├── example.spec.ts                # Sample Playwright test
│   ├── orangehrm-login-data-driven.spec.ts       # Data-driven login (inline)
│   ├── orangehrm-login-data-driven-csv.spec.ts   # Data-driven login (CSV)
│   ├── orangehrm-logout.spec.ts                  # Logout flow test
│   ├── orangehrm-admin-system-users.spec.ts      # Admin module test
│   ├── orangehrm-buzz-post.spec.ts               # Buzz social feed test
│   ├── pim-search.spec.ts                        # PIM employee search
│   └── add-employee.spec.ts                      # Add employee (POM)
│
├── 📂 test_data/                     # Test data files
│   └── loginData.csv                 # CSV test data for login
│
├── 📂 playwright-report/             # HTML test reports
├── 📂 test-results/                  # Test execution artifacts
│
├── 📄 playwright.config.ts           # Playwright configuration
├── 📄 package.json                   # Dependencies & scripts
├── 📄 README.md                      # This file
│
├── 📄 Playwright_MCP_Guide.md        # Detailed MCP concepts guide
├── 📄 PlaywrightMCP_Vs_CLI.md        # MCP vs CLI comparison
├── 📄 playwright-context.md          # MCP test generator context
├── 📄 playwright-context-pom.md      # MCP POM test generator context
├── 📄 prompts.md                     # Sample AI prompts used
└── 📄 notes.md                       # Architecture & concept notes

🧪 测试场景

测试文件

描述

模式

orangehrm-login-data-driven.spec.ts

使用内联数据(有效 + 无效凭据)进行登录验证

数据驱动

orangehrm-login-data-driven-csv.spec.ts

使用 CSV 数据源进行登录验证

数据驱动(CSV)

orangehrm-logout.spec.ts

登录、注销,并验证重定向到登录页面

线性

orangehrm-admin-system-users.spec.ts

导航到 Admin → 验证系统用户页面

线性

orangehrm-buzz-post.spec.ts

在 Buzz 信息流上发布消息并验证其出现

线性

pim-search.spec.ts

在 PIM 模块中按姓名搜索员工

线性

add-employee.spec.ts

使用页面对象模型添加新员工

POM

example.spec.ts

默认的 Playwright 示例测试

线性


🚀 快速开始

先决条件

安装

# Clone the repository
git clone https://github.com/pavanoltraining/POC_Playwright_MCP_orangehrm.git

# Navigate to the project directory
cd POC_Playwright_MCP_orangehrm

# Install dependencies
npm install

# Install Playwright browsers
npx playwright install chromium

▶️ 运行测试

运行所有测试

npx playwright test

运行特定测试文件

npx playwright test tests/orangehrm-login-data-driven.spec.ts

在 UI 模式下运行测试

npx playwright test --ui

查看 HTML 报告

npx playwright show-report

使用调试模式运行

npx playwright test --debug

🧩 页面对象模型

本项目采用 页面对象模型(POM) 设计模式,以实现可维护和可复用的测试代码。

示例:LoginPage.ts

export class LoginPage {
  readonly usernameInput = page.getByPlaceholder("Username");
  readonly passwordInput = page.getByPlaceholder("Password");
  readonly loginButton = page.getByRole("button", { name: "Login" });

  async login(username: string, password: string) {
    await this.usernameInput.fill(username);
    await this.passwordInput.fill(password);
    await this.loginButton.click();
  }
}

示例:PimPage.ts

export class PimPage {
  async navigateToPim() {
    /* ... */
  }
  async openAddEmployee() {
    /* ... */
  }
  async addEmployee(firstName: string, lastName: string) {
    /* ... */
  }
}

📊 数据驱动测试

内联数据驱动

使用内联定义的多个凭据测试登录:

用户名

密码

预期结果

Admin

admin123

仪表板

fakeuser

fakepass

凭据无效

ESSUser1

ess123

凭据无效

CSV 数据驱动

测试从 test_data/loginData.csv 读取测试用例:

Username,Password,Expected
Admin,admin123,Dashboard
fakeuser,fakepass,Invalid credentials
ESSUser1,ess123,Invalid credentials

🤖 Playwright MCP 与 Playwright CLI 对比

特性

Playwright CLI

Playwright MCP

用途

Playwright 的命令行工具

连接 LLM 和 Playwright 的 AI 桥梁

使用者

开发人员与测试人员

AI 智能体

输入

终端命令

自然语言提示

浏览器控制

直接通过 Playwright 脚本

通过 AI + MCP 服务器

需要编码

极少编码

生成代码

是(AI 生成)

执行测试

使用无障碍树

支持 AI 自动化

最适合

传统自动化

AI 驱动的自动化


📚 资源


📄 许可证

本项目仅用于教育和演示目的


使用 Playwright + MCP + AI 构建,并倾注了热情

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables browser automation and web page interaction through Playwright's accessibility tree, allowing LLMs to navigate, fill forms, click elements, and extract content without requiring vision models or screenshots.
    4,588,713
    Apache 2.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to control web browsers through Playwright automation, providing 50+ tools for navigation, interaction, testing, accessibility audits, and visual testing across Chromium, Firefox, and WebKit.
    10
    MIT

View all related MCP servers

Related MCP Connectors

  • AI QA tester — real browsers scan sites for bugs, SEO, perf, and accessibility issues via chat.

  • Browser-backed QA with evidence and fix-ready reports for coding agents.

  • AI-powered browser automation — navigate, click, fill forms, and extract data from any website.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pavanoltraining/POC_Playwright_MCP_orangehrm'

If you have feedback or need assistance with the MCP directory API, please join our Discord server