import { test, expect, type Page, type Locator } from '@playwright/test'; const BASE_URL = process.env.E2E_BASE_URL ?? 'http://localhost:3000'; async function waitAppSettled(page: Page) { await page.waitForLoadState('domcontentloaded'); await page.waitForLoadState('networkidle').catch(() => {}); await page.waitForTimeout(250); } // ===== Anchors / Scope ===== function headingRegister(page: Page) { return page.getByRole('heading', { name: 'สร้างบัญชีผู้ใช้งาน' }); } // ===== Inputs (ตาม snapshot ที่คุณส่งมา) ===== function usernameInput(page: Page): Locator { // snapshot: textbox "username" return page.getByRole('textbox', { name: 'username' }).first(); } function emailInput(page: Page): Locator { // snapshot: textbox "student@example.com" return page.getByRole('textbox', { name: 'student@example.com' }).first(); } function prefixCombobox(page: Page): Locator { // snapshot: combobox มี option นาย/นาง/นางสาว return page.getByRole('combobox').first(); } function firstNameInput(page: Page): Locator { // snapshot: label "ชื่อ *" + textbox return page.getByText(/^ชื่อ\s*\*$/).locator('..').getByRole('textbox').first(); } function lastNameInput(page: Page): Locator { return page.getByText(/^นามสกุล\s*\*$/).locator('..').getByRole('textbox').first(); } function phoneInput(page: Page): Locator { return page.getByText(/^เบอร์โทรศัพท์\s*\*$/).locator('..').getByRole('textbox').first(); } function passwordInput(page: Page): Locator { // snapshot: label "รหัสผ่าน *" + textbox (มีปุ่ม visibility อยู่ข้างๆ) return page.getByText(/^รหัสผ่าน\s*\*$/).locator('..').getByRole('textbox').first(); } function confirmPasswordInput(page: Page): Locator { return page.getByText(/^ยืนยันรหัสผ่าน\s*\*$/).locator('..').getByRole('textbox').first(); } function submitButton(page: Page): Locator { return page.getByRole('button', { name: 'สร้างบัญชี' }); } function loginLink(page: Page): Locator { return page.getByRole('link', { name: 'เข้าสู่ระบบ' }); } function errorBox(page: Page): Locator { // ทั้ง field message และ notification/toast/alert return page.locator( ['.q-field__messages', '.q-field__bottom', '.text-negative', '.q-notification', '.q-banner', '[role="alert"]'].join( ', ' ) ); } async function pickPrefix(page: Page, value: 'นาย' | 'นาง' | 'นางสาว' = 'นาย') { const combo = prefixCombobox(page); // ถ้าเป็น