fix: use waitForSelector for toast elements instead of timeouts

This commit is contained in:
张翔
2026-03-06 18:06:29 +08:00
parent 7cf888f09d
commit 9da7878695
+2 -6
View File
@@ -37,12 +37,10 @@ test.describe('表单验证测试', () => {
});
await contactPage.submitForm();
await page.waitForTimeout(1000);
await page.waitForSelector('[data-testid="toast-notification"]', { timeout: 5000 });
const toastMessage = await contactPage.getToastMessage();
expect(toastMessage.message).toContain('表单提交成功');
expect(toastMessage.type).toBe('success');
await page.waitForTimeout(4000);
});
test('联系表单 - 必填字段验证', async ({ page }) => {
@@ -114,11 +112,9 @@ test.describe('表单验证测试', () => {
});
await contactPage.submitForm();
await page.waitForTimeout(1000);
await page.waitForSelector('[data-testid="toast-notification"]', { timeout: 5000 });
const toastMessage = await contactPage.getToastMessage();
expect(toastMessage.message).toContain('服务器错误');
expect(toastMessage.type).toBe('error');
await page.waitForTimeout(4000);
});
});