Bài Tập 3: Viết Test Tìm Kiếm¶
Yêu Cầu¶
Viết test case Playwright cho flow tìm kiếm sản phẩm.
Thông Tin¶
- URL: https://practice.automationtesting.in/shop/
- Từ khóa: Android
- Expected: Có kết quả tìm kiếm
Hướng Dẫn¶
Bước 1: Tạo file test¶
Tạo file tests/search.spec.ts
Bước 2: Viết code¶
import { test, expect } from '@playwright/test';
test('test search product', async ({ page }) => {
// Bước 1: Mở trang Shop
await page.goto('_______________');
// Bước 2: Nhập từ khóa tìm kiếm
await page.locator('_______________').fill('_______________');
// Bước 3: Nhấn Enter hoặc click nút Search
await page.locator('_______________').press('_______________');
// Bước 4: Kiểm tra kết quả
await expect(page.locator('_______________')).toBeVisible();
});
Bước 3: Tìm locator¶
Dùng DevTools tìm locator cho:
- Ô tìm kiếm: _____
- Nút Search (nếu có): _____
- Kết quả tìm kiếm: _____
Bước 4: Chạy test¶
Checklist¶
Gợi ݶ
Click để xem solution
import { test, expect } from '@playwright/test';
test('test search product', async ({ page }) => {
await page.goto('https://practice.automationtesting.in/shop/');
await page.locator('#s').fill('Android');
await page.locator('#s').press('Enter');
await expect(page.locator('.product')).toBeVisible();
});