Created
April 26, 2023 15:18
-
-
Save MarcusFelling/c2d084fc07166e8b1349963125581e95 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
async function measureCartPerformance(page: Page, TestInfo: TestInfo) { | |
// Navigate to shopping cart | |
await page.goto(`/Carts`); | |
// Use Performance API to measure performance | |
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntriesByType | |
const performance = await page.evaluate(() => performance.getEntriesByType('navigation')); | |
// Get the first entry | |
const performanceTiming = performance[0]; | |
// 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.use.baseURL}" - Navigation start to load event end: ${startToLoadEventEnd}ms` }); | |
// Also output to console for debugging | |
console.log(`${TestInfo.project.use.baseURL} - 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