AI-powered automated QA testing with Playwright and Model Context Protocol
npm install playwright-mcp-rashaideh93bash
git clone https://github.com/rashaideh93/Ultimate-QA-MCP-Server-AI-Driven-Automated-Testing.git
cd test
`
2. Install dependencies:
`bash
npm install
`
3. Configure environment:
`bash
cp .env.example .env
# Edit .env with your settings:
# LLM_PROVIDER=openai (or anthropic, custom)
# LLM_MODEL_NAME=gpt-4
# LLM_API_KEY=your-api-key
`
4. Build the project:
`bash
npm run build
`
5. Start the server:
`bash
npm start
`
---
š Usage
$3
Simply describe your test in plain English:
`
"Navigate to https://example.com/login,
fill email with admin@test.com,
fill password with Pass123!,
click the Login button,
wait 2 seconds for page load,
verify Welcome message appears,
take a screenshot"
`
The server will automatically:
1. ā
Parse the scenario into structured steps
2. ā
Launch a Playwright browser
3. ā
Execute each action in sequence
4. ā
Capture screenshots and logs
5. ā
Return detailed results
$3
`bash
Build the project
npm run build
Start the server
npm start
Run tests (in another terminal)
npm test
Watch mode for development
npm run dev
`
$3
#### Claude Desktop
Add to claude_desktop_config.json:
`json
{
"mcpServers": {
"ultimate-qa": {
"command": "node",
"args": ["/path/to/test/build/index.js"],
"env": {
"LLM_PROVIDER": "openai",
"LLM_MODEL_NAME": "gpt-4",
"LLM_API_KEY": "sk-..."
}
}
}
}
`
#### VS Code Copilot
1. Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux)
2. Select MCP: Add server...
3. Configure with node ./build/index.js
#### Other MCP Clients
Configure stdio transport connecting to node ./build/index.js
---
š Usage Examples
$3
Natural Language Input:
`
"Navigate to example.com/login,
fill email with test@example.com,
fill password with TestPass123,
click Login button,
verify Dashboard page appears"
`
Automatic Execution:
- ā
Parse scenario
- ā
Launch browser
- ā
Fill form fields
- ā
Click button
- ā
Verify page state
- ā
Generate report
$3
Scenario:
`
"Create user via POST /api/users with name: John, email: john@test.com
Extract userId from response
Navigate to /users/dashboard
Search for user by email
Verify user appears in list"
`
Result:
- ā
API call execution
- ā
Data extraction
- ā
UI navigation
- ā
Element verification
- ā
Test report
$3
Scenario:
`
"Add product to cart via UI
Complete purchase
Verify order status in database
Check inventory was updated"
`
Result:
- ā
UI actions
- ā
API calls
- ā
Database queries
- ā
Cross-layer validation
$3
See USAGE_EXAMPLES.md for:
- 7+ detailed real-world scenarios
- Multi-tab testing
- Data-driven testing
- Conditional flows
- Performance monitoring
- CI/CD integration examples
---
šļø Architecture
$3
`
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā MCP Server (7 Tools) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Application Layer ā
ā - Action Router ā
ā - Context Manager ā
ā - Error Handler ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Execution Layer (Multi-Executor) ā
ā - UI Executor (Playwright) ā
ā - API Executor (HTTP) ā
ā - DB Executor (MySQL/Postgres/MongoDB) ā
ā - Performance Monitor ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Intelligence Layer ā
ā - LLM Provider (OpenAI/Anthropic) ā
ā - Natural Language Parser ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Infrastructure ā
ā - Playwright ā
ā - Axios HTTP Client ā
ā - Database Drivers ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
`
$3
| Module | Lines | Purpose |
|--------|-------|---------|
| index.ts | 290 | MCP server entry point |
| config.ts | 140 | Environment configuration |
| types.ts | 320 | TypeScript type definitions |
| llm.ts | 290 | LLM provider abstraction |
| nlParser.ts | 365 | Natural language to JSON |
| contextManager.ts | 330 | Session & variable tracking |
| uiExecutor.ts | 415 | Playwright automation |
| apiExecutor.ts | 160 | HTTP testing |
| dbExecutor.ts | 230 | Database operations |
| actionRouter.ts | 275 | Orchestration |
| errorHandler.ts | 205 | Error recovery |
$3
- Exponential Backoff - Automatic retry with increasing delays
- Selector Heuristics - Multiple fallback strategies
- Error Recovery - Graceful degradation
- Comprehensive Logging - Full execution trace
$3
`bash
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # Coverage report
npm run build # Build TypeScript
`
For detailed testing guide, see the test files in src/__tests__/
---
š Project Structure
`
ultimate-qa-mcp-server/
āāā src/ # Source code
ā āāā index.ts # MCP server entry
ā āāā config.ts # Configuration
ā āāā types.ts # Type definitions
ā āāā llm.ts # LLM abstraction
ā āāā nlParser.ts # NL parser
ā āāā contextManager.ts # Session manager
ā āāā uiExecutor.ts # Playwright
ā āāā apiExecutor.ts # HTTP testing
ā āāā dbExecutor.ts # Database
ā āāā actionRouter.ts # Orchestration
ā āāā errorHandler.ts # Error handling
ā āāā __tests__/ # Test suites
ā
āāā build/ # Compiled JS (auto-generated)
ā
āāā š Documentation
ā āāā README.md # This file
ā āāā ULTIMATE_QA_GUIDE.md # Complete user guide (2000+ lines)
ā āāā USAGE_EXAMPLES.md # Real-world examples
ā āāā API_REFERENCE.md # MCP tool reference
ā
āāā āļø Configuration
ā āāā package.json # Dependencies
ā āāā tsconfig.json # TypeScript config
ā āāā jest.config.cjs # Test config
ā āāā .env.example # Environment template
ā āāā qodana.yaml # Code analysis
ā
āāā š Version Control
āāā .git/ # Git repository
āāā .gitignore # Git exclusions
āāā .npmignore # NPM exclusions
`
$3
`bash
npm run build # Compile TypeScript to JavaScript
npm run dev # Development mode with watch
npm start # Start the server
`
$3
`bash
Run all tests
npm test
Test specific files
npm test -- actionRouter
Use MCP Inspector for interactive testing
npx @modelcontextprotocol/inspector node ./build/index.js
`
The MCP Inspector provides:
- Interactive tool testing
- Schema inspection
- Output visualization
- Debugging interface
---
š¤ AI Integration
$3
Configure in claude_desktop_config.json:
`json
{
"mcpServers": {
"ultimate-qa": {
"command": "node",
"args": ["/path/to/test/build/index.js"],
"env": {
"LLM_PROVIDER": "openai",
"LLM_MODEL_NAME": "gpt-4",
"LLM_API_KEY": "sk-..."
}
}
}
}
`
$3
1. Install MCP extension for VS Code
2. Configure with node ./build/index.js
3. Use natural language for test scenarios
$3
Compatible with:
- LM Studio - Local LLM deployment
- Cursor - Code editor with AI
- Windsurf - AI-powered IDE
- Cline - Command-line interface
- Custom clients - Any MCP-compatible application
$3
OpenAI:
- GPT-4 (recommended)
- GPT-3.5-turbo
Anthropic:
- Claude 3 Opus
- Claude 3 Sonnet
- Claude 2
Custom:
- On-premise OpenAI-compatible API
- Self-hosted models
---
āļø Configuration
$3
Create .env file with:
`bash
LLM Configuration
LLM_PROVIDER=openai # openai | anthropic | custom
LLM_MODEL_NAME=gpt-4 # Model to use
LLM_API_KEY=sk-... # Your API key
LLM_BASE_URL= # For custom models
LLM_TIMEOUT=30000 # Request timeout (ms)
Database Configuration (Optional)
DB_TYPE=mysql # mysql | postgres | mongodb
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=user
DB_PASSWORD=password
DB_NAME=testdb
Server Configuration
SCREENSHOTS_ENABLED=true # Capture screenshots
SCREENSHOTS_PATH=./screenshots
REPORTS_ENABLED=true
REPORTS_PATH=./qa-reports
REPORT_FORMATS=json,markdown,html
Performance
PERFORMANCE_CHECKS=true
PAGE_LOAD_THRESHOLD_MS=3000
API_RESPONSE_THRESHOLD_MS=1000
Retries
MAX_RETRY_ATTEMPTS=3
RETRY_DELAY_MS=1000
RETRY_BACKOFF_MULTIPLIER=1.5
`
$3
- browserType - "chromium" (default), "firefox", "webkit"
- headless - true (default) or false for headed mode
- url - Initial URL to navigate to
$3
- MySQL - Version 5.7+, Driver: mysql2
- PostgreSQL - Version 10+, Driver: pg
- MongoDB - Version 4.0+, Driver: mongodb
---
š§ Troubleshooting
$3
- ā
Ensure Node.js 17+ installed: node --version
- ā
Check dependencies: npm install
- ā
Verify build: npm run build
- ā
Check .env file exists with LLM_API_KEY
$3
- ā
Verify absolute path in MCP config is correct
- ā
Confirm build/index.js exists
- ā
Check stderr output: npm start 2>&1
- ā
Test MCP connection: npx @modelcontextprotocol/inspector node ./build/index.js
$3
- ā
Verify element selectors are correct (CSS or XPath)
- ā
Check elements exist before interaction
- ā
Review Playwright docs for specific elements
- ā
Enable screenshots for debugging: SCREENSHOTS_ENABLED=true
- ā
Check logs in ./qa-reports directory
$3
- ā
Use headless mode (default): faster execution
- ā
Close browsers when done: close_browser
- ā
Use appropriate waits: avoid excessive delays
- ā
Enable connection pooling for databases
- ā
Monitor network requests in DevTools
$3
- ā
Verify DB connection string in .env
- ā
Check database is running and accessible
- ā
Ensure user has appropriate permissions
- ā
Test connection: mysql -u user -p -h host
For more help, see ULTIMATE_QA_GUIDE.md
---
š MCP Tools Reference
$3
Initialize LLM provider for natural language parsing
`json
{
"provider": "openai|anthropic|custom",
"modelName": "gpt-4|claude-3-opus|...",
"apiKey": "your-api-key",
"baseUrl": "optional-for-custom"
}
`
$3
Convert English QA scenario to structured steps
`json
{
"scenarioText": "Navigate to login, fill email with test@test.com, click Login",
"extractVariables": true
}
`
$3
Parse and execute complete scenario
`json
{
"browserId": "browser-1",
"scenarioText": "Your test scenario...",
"generateReport": true
}
`
$3
Start Playwright browser instance
`json
{
"browserType": "chromium|firefox|webkit",
"headless": true,
"url": "https://example.com"
}
`
$3
Clean up browser resources
`json
{
"browserId": "browser-1"
}
`
$3
Retrieve session variables and data
`json
{
"browserId": "browser-1"
}
`
$3
Server status and active browsers
`json
{}
`
For detailed tool documentation, see API_REFERENCE.md
---
š¦ Dependencies
$3
- @modelcontextprotocol/sdk (2.0+) - MCP protocol
- playwright (1.48+) - Browser automation
- axios (1.6+) - HTTP client
- zod (3.22+) - Type validation
- dotenv (16.3+) - Environment config
$3
- mysql2 (3.6+) - MySQL driver
- pg (8.11+) - PostgreSQL driver
- mongodb (6.3+) - MongoDB driver
$3
- typescript (5.3+) - Language support
- jest (29+) - Testing framework
- @types/node - Type definitions
---
š Project Statistics
| Metric | Value |
|--------|-------|
| Core Modules | 11 |
| MCP Tools | 7 |
| Total Lines | ~3,500 |
| Type Coverage | 100% |
| Compilation Errors | 0 |
| Test Coverage | Included |
---
š Documentation
Complete documentation available:
1. ULTIMATE_QA_GUIDE.md (2000+ lines)
- Complete user guide
- Detailed examples
- Best practices
- Advanced features
2. USAGE_EXAMPLES.md
- 7+ real-world scenarios
- Multi-system testing
- Performance monitoring
- CI/CD integration
3. API_REFERENCE.md
- MCP tool documentation
- Parameter details
- Response formats
---
š Security & Best Practices
ā
100% TypeScript - Full type safety
ā
Input Validation - Zod schema validation
ā
Error Handling - Comprehensive error recovery
ā
Secrets Management - Environment variable based
ā
Connection Pooling - Database optimization
ā
Retry Logic - Exponential backoff
---
š License
MIT License - See LICENSE file for details
---
š¤ Contributing
Contributions welcome! Please:
1. Fork the repository
2. Create a feature branch
3. Submit a pull request
4. Include test coverage
---
š Resources
- MCP Documentation
- Playwright Documentation
- OpenAI API
- Anthropic Claude
---
š¬ Support
For issues and questions:
1. Check Documentation - See guides above
2. Review Examples - See USAGE_EXAMPLES.md
3. Check Logs - Enable debug logging
4. Run Tests - npm test`