diff --git a/e2e/src/pages/ContactPage.ts b/e2e/src/pages/ContactPage.ts index 37d9314..4287be0 100644 --- a/e2e/src/pages/ContactPage.ts +++ b/e2e/src/pages/ContactPage.ts @@ -38,12 +38,12 @@ export class ContactPage extends BasePage { this.pageHeader = page.locator('h1'); this.contactForm = page.locator('form'); - this.nameInput = page.locator('input[name="name"]'); - this.phoneInput = page.locator('input[name="phone"]'); - this.emailInput = page.locator('input[name="email"]'); - this.subjectInput = page.locator('input[name="subject"]'); - this.messageInput = page.locator('textarea[name="message"]'); - this.submitButton = page.locator('button[type="submit"]'); + this.nameInput = page.locator('[data-testid="name-input"]'); + this.phoneInput = page.locator('[data-testid="phone-input"]'); + this.emailInput = page.locator('[data-testid="email-input"]'); + this.subjectInput = page.locator('[data-testid="subject-input"]'); + this.messageInput = page.locator('[data-testid="message-input"]'); + this.submitButton = page.locator('[data-testid="submit-button"]'); this.contactInfoCard = page.locator('[data-testid="contact-info"]'); this.workHoursCard = page.locator('[data-testid="work-hours-card"]'); @@ -58,10 +58,10 @@ export class ContactPage extends BasePage { this.successMessage = page.locator('text=消息已发送'); - this.nameError = page.locator('input[name="name"] + .error-message, input[name="name"] ~ .text-destructive').first(); - this.emailError = page.locator('input[name="email"] + .error-message, input[name="email"] ~ .text-destructive').first(); - this.phoneError = page.locator('input[name="phone"] + .error-message, input[name="phone"] ~ .text-destructive').first(); - this.messageError = page.locator('textarea[name="message"] + .error-message, textarea[name="message"] ~ .text-destructive').first(); + this.nameError = page.locator('[data-testid="name-input"] + .error-message, [data-testid="name-input"] ~ .text-destructive').first(); + this.emailError = page.locator('[data-testid="email-input"] + .error-message, [data-testid="email-input"] ~ .text-destructive').first(); + this.phoneError = page.locator('[data-testid="phone-input"] + .error-message, [data-testid="phone-input"] ~ .text-destructive').first(); + this.messageError = page.locator('[data-testid="message-input"] + .error-message, [data-testid="message-input"] ~ .text-destructive').first(); } get breadcrumb(): Locator { @@ -300,37 +300,37 @@ export class ContactPage extends BasePage { } async focusOnField(fieldName: string): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); await input.focus(); } async blurField(fieldName: string): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); await input.blur(); } async typeInField(fieldName: string, text: string, options?: { delay?: number }): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); await input.type(text, options); } async clearField(fieldName: string): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); await input.fill(''); } async isFieldVisible(fieldName: string): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); return await input.isVisible(); } async isFieldEnabled(fieldName: string): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); return await input.isEnabled(); } async getFieldAttribute(fieldName: string, attribute: string): Promise { - const input = this.page.locator(`[name="${fieldName}"]`); + const input = this.page.locator(`[data-testid="${fieldName}-input"]`); return await input.getAttribute(attribute); } diff --git a/src/app/(marketing)/contact/page.tsx b/src/app/(marketing)/contact/page.tsx index 192f527..40ed846 100644 --- a/src/app/(marketing)/contact/page.tsx +++ b/src/app/(marketing)/contact/page.tsx @@ -277,6 +277,8 @@ export default function ContactPage() {
handleChange('email', e.target.value)} - onBlur={(e) => handleBlur('email', e.target.value)} - error={errors.email} - /> + onBlur={(e) => handleBlur('email', e.target.value)} + error={errors.email} + /> handleChange('subject', e.target.value)} - onBlur={(e) => handleBlur('subject', e.target.value)} - error={errors.subject} - /> + onChange={(e) => handleChange('subject', e.target.value)} + onBlur={(e) => handleBlur('subject', e.target.value)} + error={errors.subject} + />