test: Add custom reporter for test metrics (#18960)

This commit is contained in:
shortstacked
2025-09-01 13:17:14 +01:00
committed by GitHub
parent ec7eddc364
commit 71b33277f8
8 changed files with 256 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import type { Page } from '@playwright/test';
import type { Page, TestInfo } from '@playwright/test';
export async function measurePerformance(
page: Page,
@@ -28,3 +28,21 @@ export async function getAllPerformanceMetrics(page: Page) {
return metrics;
});
}
/**
* Attach a performance metric for collection by the metrics reporter
* @param testInfo - The Playwright TestInfo object
* @param metricName - Name of the metric (will be prefixed with 'metric:')
* @param value - The numeric value to track
* @param unit - The unit of measurement (e.g., 'ms', 'bytes', 'count')
*/
export async function attachMetric(
testInfo: TestInfo,
metricName: string,
value: number,
unit?: string,
): Promise<void> {
await testInfo.attach(`metric:${metricName}`, {
body: JSON.stringify({ value, unit }),
});
}