fix: add name and data-testid attributes for form input fields

This commit is contained in:
张翔
2026-03-05 21:51:50 +08:00
parent 318081a62a
commit 2d6cd79067
2 changed files with 39 additions and 28 deletions
+17 -17
View File
@@ -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<void> {
const input = this.page.locator(`[name="${fieldName}"]`);
const input = this.page.locator(`[data-testid="${fieldName}-input"]`);
await input.focus();
}
async blurField(fieldName: string): Promise<void> {
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<void> {
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<void> {
const input = this.page.locator(`[name="${fieldName}"]`);
const input = this.page.locator(`[data-testid="${fieldName}-input"]`);
await input.fill('');
}
async isFieldVisible(fieldName: string): Promise<boolean> {
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<boolean> {
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<string | null> {
const input = this.page.locator(`[name="${fieldName}"]`);
const input = this.page.locator(`[data-testid="${fieldName}-input"]`);
return await input.getAttribute(attribute);
}