Created
April 27, 2023 13:45
-
-
Save MarcusFelling/88f8ddde9941ec1cef19667892dbe2d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test, expect, Page, TestInfo } from '@playwright/test'; | |
test('performance test example', async ({ page }, TestInfo) => { | |
// Perform actions | |
await page.goto(`/`); | |
// Measure performance | |
await measurePerformance(page, TestInfo); | |
}); | |
async function measurePerformance(page: Page, TestInfo: TestInfo) { | |
// Use Performance API to measure performance | |
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntriesByType | |
const [performanceTiming] = await page.evaluate(() => { | |
const [timing] = performance.getEntriesByType('navigation'); | |
return [timing]; | |
}); | |
// Get the start to load event end time | |
const startToLoadEventEnd = performanceTiming.loadEventEnd - performanceTiming.startTime; | |
// Add the performance annotation to the HTML report | |
test.info().annotations.push({ type: 'Performance', description: `"${TestInfo.project.name}" - Navigation start to load event end: ${startToLoadEventEnd}ms` }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment