Skip to content

Commit 05159af

Browse files
Update project structure, add pytest.ini & main.py, refresh README
1 parent d7e7f65 commit 05159af

File tree

5 files changed

+190
-45
lines changed

5 files changed

+190
-45
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,40 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v4
20-
21-
- name: Set up Python
22-
uses: actions/setup-python@v4
23-
with:
24-
python-version: '3.11'
25-
26-
- name: Upgrade pip
27-
run: python -m pip install --upgrade pip
28-
29-
- name: Cache pip
30-
uses: actions/cache@v4
31-
with:
32-
path: ~/.cache/pip
33-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
34-
restore-keys: |
35-
${{ runner.os }}-pip-
36-
37-
38-
- name: Install dependencies
39-
run: |
40-
python -m pip install -r requirements.txt
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.11'
25+
26+
- name: Upgrade pip
27+
run: python -m pip install --upgrade pip
28+
29+
- name: Cache pip
30+
uses: actions/cache@v4
31+
with:
32+
path: ~/.cache/pip
33+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
34+
restore-keys: |
35+
${{ runner.os }}-pip-
36+
37+
- name: Install dependencies
38+
run: |
39+
python -m venv venv
4140
# If mcp is private, uncomment below:
4241
# python -m pip install git+https://github.com/your-org/mcp.git
43-
playwright install
44-
45-
46-
- name: Run tests
47-
run: |
48-
source venv/bin/activate || .\venv\Scripts\Activate.ps1
49-
pytest -v --maxfail=1 --disable-warnings --html=report.html --self-contained-html
50-
51-
- name: Upload HTML Report
52-
uses: actions/upload-artifact@v4
53-
with:
54-
name: pytest-report
55-
path: report.html
42+
./venv/bin/python -m pip install -r requirements.txt || .\venv\Scripts\python.exe -m pip install -r requirements.txt
43+
./venv/bin/python -m playwright install || .\venv\Scripts\python.exe -m playwright install
44+
45+
- name: Run tests
46+
run: |
47+
./venv/bin/python -m pytest -v --maxfail=1 --disable-warnings --html=report.html --self-contained-html \
48+
|| .\venv\Scripts\python.exe -m pytest -v --maxfail=1 --disable-warnings --html=report.html --self-contained-html
49+
50+
- name: Upload HTML Report
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: pytest-report
54+
path: report.html

README.md

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
## 🔗 Playwright + MCP Integration
1+
# 🔗 Playwright + MCP Integration
22

33
This repository demonstrates how to connect **Playwright-based Python UI tests** to **MCP (Model Context Protocol)** for intelligent testing flows.
44

5-
### Features
5+
## Features
66
- ✅ Browser automation with Playwright
77
- 🤖 AI-aware testing using MCP SDK
88
- 🧩 Configurable YAML for connecting to custom MCP servers
99
- 💡 Extendable design for adaptive and self-healing test logic
1010

1111
*NOTE: pom.xml is for local-use only*
1212

13-
#### Legacy Java Artifacts (pom.xml)
13+
### Legacy Java Artifacts (pom.xml)
1414
This project is primarily a **Python / Playwright / MCP** framework. The file `pom.xml` was retained for local reference/legacy compatibility, but **is not committed** to this repository.
1515
To keep it locally without committing:
1616
1. Add `pom.xml` to `.gitignore` (already included).
@@ -19,9 +19,99 @@ To keep it locally without committing:
1919
git rm --cached pom.xml
2020
git commit -m "Remove pom.xml from Git and ignore it"
2121

22-
Run locally:
23-
```powershell
24-
python -m venv venv
25-
.\venv\Scripts\Activate.ps1
26-
pip install -r requirements.txt
27-
pytest -v
22+
23+
---
24+
25+
## ⚙️ Environment Setup
26+
27+
### 🪟 Local (Windows)
28+
1. **Create and activate virtual environment**
29+
```bash
30+
python -m venv .venv
31+
.\.venv\Scripts\Activate.ps1
32+
33+
2. **Install dependencies**
34+
```bash
35+
python -m pip install --upgrade pip
36+
python -m pip install -r requirements.txt
37+
playwright install
38+
39+
3. **Run tests manually**
40+
```bash
41+
pytest -v --maxfail=1 --disable-warnings --html=report.html --self-contained-html
42+
43+
### Optional: Run manual test flow
44+
Instead of `pytest`, you can execute the main integration manually:
45+
```bash
46+
python main.py
47+
```
48+
*This runs the MCP + Playwright flow directly and prints progress to the console.*
49+
50+
## GitHub Actions (Ubuntu CI)
51+
This project includes a cross-platform GitHub Actions workflow at:
52+
```bash
53+
.github/workflows/python-ci.yml
54+
```
55+
## 💡Highlights:
56+
57+
1. Auto-runs on push and pull_request to main
58+
59+
2. Sets up Python 3.11 and caches dependencies
60+
61+
3. Creates a virtual environment automatically
62+
63+
4. Runs Playwright tests and uploads the HTML test report as an artifact
64+
65+
5. Compatible with both Linux (CI) and Windows (local)
66+
67+
## 🤖 MCP Server Integration
68+
69+
The framework uses the following environment variable:
70+
```bash
71+
MCP_SERVER_URL=wss://mcp.openai.com/v1
72+
```
73+
*This enables bidirectional WebSocket communication with the MCP server for AI-assisted actions and validations.*
74+
75+
## 🧪 Test Execution Flow
76+
77+
```mermaid
78+
graph TD
79+
A[Git Commit / Push] --> B[GitHub Actions Trigger]
80+
B --> C[Setup Python & Install Dependencies]
81+
C --> D[Run Playwright + Pytest]
82+
D --> E[Generate HTML Report]
83+
E --> F[Upload Artifact to GitHub]
84+
```
85+
86+
## 📊 HTML Report
87+
88+
After each CI run:
89+
90+
1. Report artifact name: pytest-report
91+
92+
2. Accessible in the Actions tab → Artifacts section
93+
94+
3. Local report: report.html created in project root
95+
96+
97+
## 🚀 Future Enhancements
98+
99+
* Matrix build for Ubuntu + Windows
100+
101+
* CodeQL security scan workflow
102+
103+
* AI-based test case suggestion integration via MCP
104+
105+
* Playwright parallel execution configuration
106+
107+
* Automatic GitHub Pages publishing of HTML report
108+
109+
## 💡Summary
110+
111+
This framework demonstrates:
112+
113+
* Seamless Playwright + MCP integration
114+
115+
* Unified test setup for both local and CI environments
116+
117+
* Intelligent, maintainable, and extensible Python automation architecture

docs/PROJECT_STRUCTURE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 📁 Project Directory Structure
2+
3+
```plaintext
4+
playwright-python-mcp/
5+
6+
├── .github/
7+
│ └── workflows/
8+
│ └── python-ci.yml # GitHub Actions CI workflow
9+
10+
├── tests/ # All test cases (Pytest format)
11+
│ ├── test_sample.py # Example test file
12+
│ └── conftest.py # Common pytest fixtures/hooks
13+
14+
├── pages/ # ⚙️ TODO: Add Page Object Model (POM) classes
15+
│ ├── base_page.py # TODO: Create shared page methods
16+
│ ├── login_page.py # TODO: Define login locators/actions
17+
│ └── dashboard_page.py # TODO: Implement dashboard interactions
18+
19+
├── utils/ # ⚙️ TODO: Add reusable helper utilities
20+
│ ├── config_reader.py # TODO: For reading test configs
21+
│ ├── logger.py # TODO: Centralized logging setup
22+
│ └── playwright_helpers.py # TODO: Shared Playwright operations
23+
24+
├── requirements.txt # Project dependencies
25+
├── pytest.ini # Pytest configuration
26+
├── README.md # Project overview and usage guide
27+
├── report.html # Generated test report (artifact)
28+
├── venv/ or .venv/ # Local virtual environment (ignored in CI)
29+
└── main.py # Optional entry point for manual run

main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
main.py
3+
Optional entry point for manual local execution of MCP + Playwright flow.
4+
"""
5+
6+
import asyncio
7+
from playwright_mcp.mcp_adapter import run_mcp_test_flow
8+
9+
def main():
10+
"""Run the MCP + Playwright integration flow manually."""
11+
print("[INFO] Starting manual MCP + Playwright test flow...")
12+
asyncio.run(run_mcp_test_flow())
13+
print("[INFO] Test flow completed.")
14+
15+
if __name__ == "__main__":
16+
main()

pytest.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[pytest]
2+
# Specify test directories
3+
testpaths = tests
4+
5+
# Add options for verbose output, HTML report generation
6+
addopts = -v --maxfail=1 --disable-warnings --html=report.html --self-contained-html
7+
8+
# Recognize pytest fixtures in tests/conftest.py
9+
python_files = test_*.py
10+
python_classes = Test*
11+
python_functions = test_*

0 commit comments

Comments
 (0)