28 lines
969 B
TypeScript
28 lines
969 B
TypeScript
import { test as base, expect, type Page } from '@playwright/test';
|
|
|
|
type Problems = { list: string[] };
|
|
|
|
/** هر خطای جاوااسکریپت یا پاسخ 5xx از API در طول تست، تست را رد میکند */
|
|
export const test = base.extend<{ problems: Problems }>({
|
|
problems: [
|
|
async ({ page }, use) => {
|
|
const problems: Problems = { list: [] };
|
|
page.on('pageerror', (err) => problems.list.push(`JS error: ${err.message}`));
|
|
page.on('response', (res) => {
|
|
if (res.url().includes('/api/') && res.status() >= 500) {
|
|
problems.list.push(`API ${res.status()}: ${res.request().method()} ${res.url()}`);
|
|
}
|
|
});
|
|
await use(problems);
|
|
expect(problems.list, 'خطا در صفحه').toEqual([]);
|
|
},
|
|
{ auto: true },
|
|
],
|
|
});
|
|
|
|
export { expect };
|
|
|
|
export async function waitForIdle(page: Page) {
|
|
await page.waitForLoadState('networkidle', { timeout: 20_000 }).catch(() => undefined);
|
|
}
|