fix: correct CSS selectors and add toast handling methods in ContactPage
This commit is contained in:
@@ -23,16 +23,44 @@ export class ContactPage extends BasePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFormErrorMessage(): Promise<string> {
|
async getFormErrorMessage(): Promise<string> {
|
||||||
const errorElement = await this.page.locator('p.mt-1.text-sm.text-\\[\\#C41E3A\\]').first();
|
const errorElement = await this.page.locator('[data-testid="error-message"]').first();
|
||||||
return await errorElement.textContent() || '';
|
return await errorElement.textContent() || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFormSuccessMessage(): Promise<string> {
|
async getFormSuccessMessage(): Promise<string> {
|
||||||
await this.page.waitForTimeout(1000);
|
await this.page.waitForTimeout(1000);
|
||||||
const successElement = await this.page.locator('text=消息已发送').first();
|
const successElement = await this.page.locator('[data-testid="success-message"]');
|
||||||
if (await successElement.count() > 0) {
|
if (await successElement.count() > 0) {
|
||||||
return await successElement.textContent() || '';
|
return await successElement.textContent() || '';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getToastMessage(): Promise<{ message: string; type: 'success' | 'error' }> {
|
||||||
|
const toastElement = await this.page.locator('[data-testid="toast-notification"]');
|
||||||
|
if (await toastElement.count() > 0) {
|
||||||
|
const message = await toastElement.textContent() || '';
|
||||||
|
const type = await toastElement.getAttribute('data-type') as 'success' | 'error';
|
||||||
|
return { message, type };
|
||||||
|
}
|
||||||
|
return { message: '', type: 'success' };
|
||||||
|
}
|
||||||
|
|
||||||
|
async waitForToast(timeout: number = 5000): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await this.page.waitForSelector('[data-testid="toast-notification"]', { timeout });
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async waitForToastHidden(timeout: number = 5000): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await this.page.waitForSelector('[data-testid="toast-notification"]', { state: 'hidden', timeout });
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user