| TC ID | Title | Steps | Expected Result |
|---|---|---|---|
| FUNC_001 | Login successfully | Enter valid account → Click Login | User login successfully |
-
Có cần gen 2 bộ test case không? (1 cho manual + 1 cho AI chạy Playwright) → Không. Dùng 1 bộ test case viết theo format có cấu trúc, dùng chung cho cả manual lẫn làm input để AI sinh script Playwright. Chỉ cần bổ sung thông tin selector cho phần auto, không phải viết lại 2 bộ khác nhau.
-
Bạn cần làm gì ở bước "cho AI dùng MCP Playwright chạy test"? → Đích đến nên là: dùng MCP Playwright cho AI khám phá trang + sinh ra file code
.spec.ts, rồi tự chạy lại bằngnpx playwright test. Không nên dừng ở việc để AI điều khiển browser trực tiếp (chậm, không ổn định). -
Với người làm manual, chưa có kinh nghiệm auto như bạn, cách này có hiệu quả không? → Có, nhưng AI chỉ rút ngắn đường học chứ không xóa bỏ việc học. Nó giúp bạn vượt rào cản khó nhất (viết selector), nhưng bạn vẫn cần học đọc và sửa lỗi test cơ bản để thật sự "biết auto".
| import { test, expect } from '@playwright/test'; | |
| test('truncate-text', async ({ page }) => { | |
| await page.goto('https://material.playwrightvn.com/pages/007-page-with-truncate.html'); | |
| page.on('console', msg => { | |
| console.log(`[browser ${msg.type()}]`, msg.text()); | |
| }); | |
| const isTruncated = await page.getByTestId('stat-label-zones').evaluate((el) => { |
| test("Test api create todo - multile validation", async ({ request }) => { | |
| const body = { | |
| "title": "Todo - Minh Phong [K22 - Multiple validation]", | |
| "description": "Write comprehensive docs for the API", | |
| "status": "pending", | |
| "priority": "high", | |
| "due_date": "2025-10-25T17:00:00", | |
| "user_id": 1 | |
| } |
| import { test, expect } from "@playwright/test"; | |
| test("Test playwright selector", async ({ page }) => { | |
| await test.step("Step 1: Goto user registration website", async () => { | |
| await page.goto("https://material.playwrightvn.com/01-xpath-register-page.html"); | |
| }); | |
| await test.step("Step 2: Get heading value", async () => { | |
| const textContent = await page.getByRole("heading").textContent(); | |
| console.log(textContent); |
| import { test, expect } from '@playwright/test'; | |
| import Tesseract from 'tesseract.js'; | |
| import fs from 'fs'; | |
| test('Giải mã Captcha bằng Tesseract OCR', async ({ page }) => { | |
| // Bước 1: Mở trang thực hành | |
| await page.goto('https://material.playwrightvn.com/036-captcha.html'); | |
| // Bước 2: Định vị (Locate) và Chụp ảnh (Screenshot) phần tử Captcha | |
| const anhCaptcha = page.locator('#captcha-canvas'); // Selector id chứa ảnh captcha |
Help me build a skill called "playwright-project-setup". This skill will be used to set up a new Playwright project.
This skill contains 6 steps:
- Check if project is initialized or not. If not, we should run
npm init -y playwright@latest - Ask user for module structure, this will be used when we create the folder structure. The module structure is as follows:
For example, user has two modules: storefront, dashboard
Ranh giới giữa Helper và Util (Utility) thường khá mong manh, và tùy vào quy định của từng dự án mà chúng có thể được dùng thay thế cho nhau.
Tuy nhiên, nếu xét về mặt thiết kế phần mềm "chuẩn bài", mình có thể phân biệt dựa trên mục đích và ngữ cảnh sử dụng như sau:
| Đặc điểm | Utility (Util) | Helper |
|---|
| import { test, expect } from '@playwright/test'; | |
| test.describe("Test suite: Material site", async () => { | |
| test.beforeAll(async () => { | |
| console.log("BeforeAll: Trước khi tất cả các test chạy"); | |
| }); | |
| test.afterAll(async () => { | |
| console.log("AfterAll: sau khi tất cả các test chạy"); | |
| }) |