Bài Tập 1: Viết Test Đăng Nhập¶
Yêu Cầu¶
Viết test case Playwright cho flow đăng nhập trên Practice Website.
Thông Tin¶
- URL: https://practice.automationtesting.in/my-account/
- Username: testuser123
- Password: Test@123456
- Expected: Thấy nội dung My Account sau khi đăng nhập
Hướng Dẫn¶
Bước 1: Tạo file test¶
Tạo file tests/login.spec.ts
Bước 2: Viết code¶
import { test, expect } from '@playwright/test';
test('test login success', async ({ page }) => {
// Bước 1: Mở trang đăng nhập
await page.goto('_______________');
// Bước 2: Nhập username
await page.locator('_______________').fill('_______________');
// Bước 3: Nhập password
await page.locator('_______________').fill('_______________');
// Bước 4: Click nút Login
await page.locator('_______________').click();
// Bước 5: Assertion - Kiểm tra đăng nhập thành công
await expect(page.locator('_______________')).toBeVisible();
});
Bước 3: Tìm locator¶
Dùng DevTools tìm locator cho:
- Ô Username: _____
- Ô Password: _____
- Nút Login: _____
- Nội dung My Account: _____
Bước 4: Chạy test¶
Checklist¶
Gợi ݶ
Click để xem solution
import { test, expect } from '@playwright/test';
test('test login success', async ({ page }) => {
await page.goto('https://practice.automationtesting.in/my-account/');
await page.locator('#username').fill('testuser123');
await page.locator('#password').fill('Test@123456');
await page.locator('[name="login"]').click();
await expect(page.locator('.woocommerce-MyAccount-content')).toBeVisible();
});