MCP Servers

A collection of Model Context Protocol servers, templates, tools and more.

P
Playwrightmcp Antigravity Python

Dự án automation testing cho hệ thống Book Management được xây dựng bởi Antigravity, sử dụng ngôn ngữ Python kết hợp với framework Playwright và mô hình thiết kế Page Object Model (POM) tối ưu.

Created 1/25/2026
Updated 2 days ago
Repository documentation and setup instructions

Playwright Python build by Antigravity - Book Management

Dự án automation testing cho hệ thống Book Management được xây dựng bởi Antigravity, sử dụng ngôn ngữ Python kết hợp với framework Playwright và mô hình thiết kế Page Object Model (POM) tối ưu.

🚀 Tính năng

  • Page Object Model - Architecture dễ maintain và scale
  • Python - Trình bày rõ ràng, dễ đọc
  • Pytest - Framework kiểm thử mạnh mẽ
  • Faker - Generate realistic test data
  • CI/CD Integration - GitHub Actions workflow tự động chạy test và xuất report
  • Allure Report - Báo cáo chuyên nghiệp với Step-by-Step logs và tự động đính kèm Screenshot.
  • HTML Report - Báo cáo HTML nhanh chóng với pytest-html.

📋 Prerequisites

  • Python (v3.8 hoặc cao hơn)
  • pip (thư viện quản lý package)

📦 Hướng dẫn cài đặt

# 1. Clone hoặc tải project về máy
# 2. Điều hướng vào thư mục dự án
cd PlaywrightMCP_Antigravity_Python

# 3. Cài đặt các thư viện cần thiết
pip install -r requirements.txt

# 4. Cài đặt đầy đủ các trình duyệt (Chromium, Firefox, Webkit)
playwright install

🏗️ Cấu trúc dự án

PlaywrightMCP_Antigravity_Python/
├── .github/workflows/         
│   └── playwright.yml             # Cấu hình GitHub Actions CI/CD
├── data/                      
│   ├── __init__.py
│   └── test_data_generator.py     # Sinh dữ liệu ngẫu nhiên (Faker)
├── pages/                     
│   ├── __init__.py
│   ├── base_page.py               # Các phương thức dùng chung
│   ├── login_page.py              # Page Object cho Login
│   ├── book_management_page.py    # Page Object cho Book List/Management
│   └── add_book_page.py           # Page Object cho Form thêm sách
├── test-data/                 
│   └── sample-book-cover.jpg      # Ảnh mẫu sử dụng cho test upload
├── tests/                     
│   ├── __init__.py
│   ├── conftest.py                # Fixtures, Hooks (Allure Screenshot, Maximize)
│   └── test_book_management.py    # Kịch bản kiểm thử chính (8 Test Cases)
├── .gitignore                     # Các tệp loại trừ khỏi Git
├── pytest.ini                     # Cấu hình Pytest mặc định
├── requirements.txt               # Danh sách thư viện Python
└── README.md                      # Hướng dẫn dự án

🧪 Các kịch bản chạy Test (Running Tests)

Dưới đây là các lệnh phổ biến để chạy test với pytest-playwright:

1. Chế độ chạy (Headless vs Headed)

Trong Playwright Python, chế độ chạy ngầm (Headless) là mặc định.

# Chạy mặc định (Headless - không mở trình duyệt)
pytest

# Chạy có giao diện trình duyệt (Headed) và tự động Maximize
pytest --headed

# Chạy chậm lại (cho dễ quan sát, ví dụ delay 500ms giữa các bước)
pytest --headed --slowmo 500

2. Chạy với các trình duyệt khác nhau

# Chạy trên Chromium (mặc định)
pytest --browser chromium

# Chạy trên Firefox
pytest --browser firefox

# Chạy trên Webkit (Safari engine)
pytest --browser webkit

3. Xuất Báo cáo (Reporting)

# Chạy và xuất kết quả Allure (Yêu cầu allure-pytest)
pytest --alluredir=allure-results

# Hiển thị báo cáo Allure (Yêu cầu Allure Command Line tool)
allure serve allure-results

4. Báo cáo HTML (Cơ bản)

# Xuất HTML Report (Yêu cầu pytest-html)
pytest --html=report.html --self-contained-html

4. Chạy File hoặc Test Case cụ thể

# Chạy một file cụ thể
pytest tests/test_book_management.py

# Chạy một Test Case cụ thể (theo tên hàm)
pytest tests/test_book_management.py -k "test_tc03_add_new_book_with_valid_data"

# Chạy test case bên trong một class
pytest tests/test_book_management.py::TestBookManagement::test_tc03_add_new_book_with_valid_data

5. Capture Screenshots & Videos

# Lưu screenshot khi test fail
pytest --screenshot=only-on-failure

# Lưu video khi test fail
pytest --video=retain-on-failure

# Lưu trace (để xem lại workflow chi tiết trong Playwright Trace Viewer)
pytest --tracing=retain-on-failure

📝 Test Cases (Tương đương bản JS/TS)

  1. TC01: Verify Login Successfully
  2. TC02: Navigate to Book Management
  3. TC03: Add New Book with Valid Data
  4. TC04: Add New Book - Missing Required Fields
  5. TC05: Add New Book - Invalid Price
  6. TC06: Verify Search Book Functionality
  7. TC07: Verify Reset Button Functionality
  8. TC08: Verify Form Validation on Empty Submit

🤖 CI/CD Pipeline

Dự án tích hợp GitHub Actions:

  • Artifacts: Báo cáo HTML được upload lên GitHub Artifacts với tên playwright-python-report.

🌐 Test URL

  • Base URL: https://book.anhtester.com/book-management
  • Login credentials:
    • Email: anhtester@example.com
    • Password: 123456