Skip to content

Instantly share code, notes, and snippets.

@MarcusFelling
Created April 26, 2023 15:18
Show Gist options
  • Save MarcusFelling/c2d084fc07166e8b1349963125581e95 to your computer and use it in GitHub Desktop.
Save MarcusFelling/c2d084fc07166e8b1349963125581e95 to your computer and use it in GitHub Desktop.
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