From 318081a62ab52c14be307a5341ad1357a05b0d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 5 Mar 2026 21:49:12 +0800 Subject: [PATCH] fix: add data-testid attributes for contact page elements --- e2e/src/pages/ContactPage.ts | 45 +++++++++++++++------------- src/app/(marketing)/contact/page.tsx | 20 ++++++------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/e2e/src/pages/ContactPage.ts b/e2e/src/pages/ContactPage.ts index 6960a3c..37d9314 100644 --- a/e2e/src/pages/ContactPage.ts +++ b/e2e/src/pages/ContactPage.ts @@ -16,13 +16,17 @@ export class ContactPage extends BasePage { readonly contactInfoCard: Locator; readonly workHoursCard: Locator; + readonly emailInfo: Locator; + readonly phoneInfo: Locator; + readonly addressInfo: Locator; + readonly emailLink: Locator; + readonly phoneLink: Locator; + readonly addressText: Locator; + readonly pageBadge: Locator; + readonly pageDescription: Locator; readonly successMessage: Locator; - readonly addressInfo: Locator; - readonly phoneInfo: Locator; - readonly emailInfo: Locator; - readonly nameError: Locator; readonly emailError: Locator; readonly phoneError: Locator; @@ -32,7 +36,7 @@ export class ContactPage extends BasePage { super(page); this.url = '/contact'; - this.pageHeader = page.locator('h1:has-text("与我们取得联系")'); + this.pageHeader = page.locator('h1'); this.contactForm = page.locator('form'); this.nameInput = page.locator('input[name="name"]'); this.phoneInput = page.locator('input[name="phone"]'); @@ -41,15 +45,19 @@ export class ContactPage extends BasePage { this.messageInput = page.locator('textarea[name="message"]'); this.submitButton = page.locator('button[type="submit"]'); - this.contactInfoCard = page.locator('[data-slot="card"]').filter({ hasText: '联系方式' }).first(); - this.workHoursCard = page.locator('[data-slot="card"]').filter({ hasText: '工作时间' }).first(); + this.contactInfoCard = page.locator('[data-testid="contact-info"]'); + this.workHoursCard = page.locator('[data-testid="work-hours-card"]'); + this.emailInfo = page.locator('[data-testid="email-info"]'); + this.phoneInfo = page.locator('[data-testid="phone-info"]'); + this.addressInfo = page.locator('[data-testid="address-info"]'); + this.emailLink = page.locator('[data-testid="email-link"]'); + this.phoneLink = page.locator('[data-testid="phone-link"]'); + this.addressText = page.locator('[data-testid="address-text"]'); + this.pageBadge = page.locator('[data-testid="page-badge"]'); + this.pageDescription = page.locator('[data-testid="page-description"]'); this.successMessage = page.locator('text=消息已发送'); - this.addressInfo = this.contactInfoCard.locator('text=公司地址'); - this.phoneInfo = this.contactInfoCard.locator('text=联系电话'); - this.emailInfo = this.contactInfoCard.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(); @@ -202,18 +210,15 @@ export class ContactPage extends BasePage { } async getAddress(): Promise { - const addressElement = this.contactInfoCard.locator('div').nth(3).locator('div').nth(1); - return await addressElement.textContent() || ''; + return await this.addressText.textContent() || ''; } async getPhone(): Promise { - const phoneElement = this.contactInfoCard.locator('div').nth(6).locator('div').nth(1); - return await phoneElement.textContent() || ''; + return await this.phoneLink.textContent() || ''; } async getEmail(): Promise { - const emailElement = this.contactInfoCard.locator('div').nth(9).locator('div').nth(1); - return await emailElement.textContent() || ''; + return await this.emailLink.textContent() || ''; } async getPageTitle(): Promise { @@ -221,13 +226,11 @@ export class ContactPage extends BasePage { } async getPageDescription(): Promise { - const description = this.pageHeader.locator('..').locator('p'); - return await description.textContent() || ''; + return await this.pageDescription.textContent() || ''; } async getBadgeText(): Promise { - const badge = this.page.locator('[data-slot="badge"]').first(); - return await badge.textContent() || ''; + return await this.pageBadge.textContent() || ''; } async isRequiredFieldVisible(fieldName: string): Promise { diff --git a/src/app/(marketing)/contact/page.tsx b/src/app/(marketing)/contact/page.tsx index dcc3708..192f527 100644 --- a/src/app/(marketing)/contact/page.tsx +++ b/src/app/(marketing)/contact/page.tsx @@ -164,12 +164,12 @@ export default function ContactPage() { >
- 联系我们 + 联系我们

开启 合作

-

+

无论您有任何问题或合作意向,我们都很乐意与您交流

@@ -184,42 +184,42 @@ export default function ContactPage() { >

联系方式

-
-
+
+ -
+ -
+

地址

-

{COMPANY_INFO.address}

+

{COMPANY_INFO.address}

-
+

工作时间