Playwright MCP
README.md
# ๐ญ Playwright MCP - AI-Powered Test Automation (OrangeHRM)
[](https://playwright.dev)
[](https://www.typescriptlang.org/)
[](https://modelcontextprotocol.io)
[](https://opensource-demo.orangehrmlive.com)
A **Proof of Concept** project demonstrating **AI-powered browser test automation** using **Playwright** integrated with the **Model Context Protocol (MCP)**. Tests are written in **TypeScript** using the **Page Object Model (POM)** design pattern, targeting the [OrangeHRM demo application](https://opensource-demo.orangehrmlive.com).
---
## ๐ Table of Contents
- [Overview](#-overview)
- [Architecture](#-architecture)
- [Tech Stack](#-tech-stack)
- [Project Structure](#-project-structure)
- [Test Scenarios](#-test-scenarios)
- [Getting Started](#-getting-started)
- [Running Tests](#-running-tests)
- [Page Object Model](#-page-object-model)
- [Data-Driven Testing](#-data-driven-testing)
- [Playwright MCP vs Playwright CLI](#-playwright-mcp-vs-playwright-cli)
- [Resources](#-resources)
---
## ๐ฏ Overview
This project showcases how **AI + Playwright** can automate browser testing using **plain English prompts** via the **Model Context Protocol (MCP)**. Instead of writing every line of automation code manually, you describe what you want to test in natural language, and AI helps generate and execute the automation.
### Key Concepts
| Component | Role | Analogy |
| -------------------------------- | -------------------------------------------------- | ------------- |
| **LLM** (Large Language Model) | Understands requests & generates instructions | ๐ง Brain |
| **Agent** | Executes tasks automatically | โก Doer |
| **MCP** (Model Context Protocol) | Connects AI with real tools (browsers, APIs, etc.) | ๐ Translator |
---
## ๐ Architecture
```text
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
```
---
## ๐ป Tech Stack
| Technology | Purpose |
| -------------------------------------------------------- | --------------------------------- |
| **[Playwright](https://playwright.dev)** ^1.60 | Browser automation framework |
| **[TypeScript](https://www.typescriptlang.org/)** | Programming language |
| **[MCP](https://modelcontextprotocol.io)** | AI-to-tool communication protocol |
| **[csv-parse](https://www.npmjs.com/package/csv-parse)** | CSV parsing for data-driven tests |
| **Node.js** | Runtime environment |
---
## ๐ Project Structure
```
โโโ ๐ 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
```
---
## ๐งช Test Scenarios
| Test File | Description | Pattern |
| ----------------------------------------- | --------------------------------------------------------------- | ----------------- |
| `orangehrm-login-data-driven.spec.ts` | Login validation with inline data (valid + invalid credentials) | Data-Driven |
| `orangehrm-login-data-driven-csv.spec.ts` | Login validation using CSV data source | Data-Driven (CSV) |
| `orangehrm-logout.spec.ts` | Login, logout, and verify redirect to login page | Linear |
| `orangehrm-admin-system-users.spec.ts` | Navigate to Admin โ verify System Users page | Linear |
| `orangehrm-buzz-post.spec.ts` | Post a message on Buzz feed and verify it appears | Linear |
| `pim-search.spec.ts` | Search employees by name in PIM module | Linear |
| `add-employee.spec.ts` | Add a new employee using Page Object Model | POM |
| `example.spec.ts` | Default Playwright sample test | Linear |
---
## ๐ Getting Started
### Prerequisites
- [Node.js](https://nodejs.org/) (v18 or later)
- [npm](https://www.npmjs.com/)
### Installation
```bash
# 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
```
---
## โถ๏ธ Running Tests
### Run all tests
```bash
npx playwright test
```
### Run a specific test file
```bash
npx playwright test tests/orangehrm-login-data-driven.spec.ts
```
### Run tests in UI mode
```bash
npx playwright test --ui
```
### View HTML report
```bash
npx playwright show-report
```
### Run with debug mode
```bash
npx playwright test --debug
```
---
## ๐งฉ Page Object Model
The project uses the **Page Object Model (POM)** design pattern for maintainable and reusable test code.
### Example: `LoginPage.ts`
```typescript
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();
}
}
```
### Example: `PimPage.ts`
```typescript
export class PimPage {
async navigateToPim() {
/* ... */
}
async openAddEmployee() {
/* ... */
}
async addEmployee(firstName: string, lastName: string) {
/* ... */
}
}
```
---
## ๐ Data-Driven Testing
### Inline Data-Driven
Tests login with multiple credentials defined inline:
| Username | Password | Expected Result |
| -------- | -------- | ------------------- |
| Admin | admin123 | Dashboard |
| fakeuser | fakepass | Invalid credentials |
| ESSUser1 | ess123 | Invalid credentials |
### CSV Data-Driven
Tests read test cases from `test_data/loginData.csv`:
```csv
Username,Password,Expected
Admin,admin123,Dashboard
fakeuser,fakepass,Invalid credentials
ESSUser1,ess123,Invalid credentials
```
---
## ๐ค Playwright MCP vs Playwright CLI
| Feature | Playwright CLI | Playwright MCP |
| ----------------------- | ----------------------------------- | ------------------------------------ |
| Purpose | Command-line tool for Playwright | AI bridge between LLM and Playwright |
| Used By | Developers & Testers | AI Agents |
| Input | Terminal commands | Natural language prompts |
| Browser Control | Directly through Playwright scripts | Through AI + MCP Server |
| Requires Coding | Yes | Minimal coding |
| Generates Code | No | Yes (AI-generated) |
| Executes Tests | Yes | Yes |
| Uses Accessibility Tree | No | Yes |
| Supports AI Automation | No | Yes |
| Best For | Traditional automation | AI-powered automation |
---
## ๐ Resources
- [Playwright Documentation](https://playwright.dev/docs/intro)
- [Model Context Protocol](https://modelcontextprotocol.io)
- [OrangeHRM Demo](https://opensource-demo.orangehrmlive.com)
- [GitHub Repository](https://github.com/pavanoltraining/POC_Playwright_MCP_orangehrm)
---
## ๐ License
This project is for **educational and demonstration purposes** only.
---
_Built with โค๏ธ using Playwright + MCP + AI_
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues