@@ -2,7 +2,7 @@ import type { Page, Route } from '@playwright/test';
22import { expect } from '@playwright/test' ;
33import type { SerializedMetric } from '@sentry/core' ;
44import { sentryTest } from '../../../../utils/fixtures' ;
5- import { shouldSkipMetricsTest , shouldSkipTracingTest , waitForMetricRequest } from '../../../../utils/helpers' ;
5+ import { shouldSkipMetricsTest , shouldSkipTracingTest , waitForMetrics } from '../../../../utils/helpers' ;
66
77function getIdentifier ( m : SerializedMetric ) : unknown {
88 return m . attributes ?. [ 'ui.element.identifier' ] ?. value ;
@@ -27,7 +27,7 @@ sentryTest(
2727
2828 // Wait for all expected element identifiers to arrive as metrics
2929 const [ allMetrics ] = await Promise . all ( [
30- waitForMetricRequest ( page , metrics => {
30+ waitForMetrics ( page , metrics => {
3131 const seen = new Set ( metrics . filter ( m => m . name === 'ui.element.render_time' ) . map ( getIdentifier ) ) ;
3232 return expectedIdentifiers . every ( id => seen . has ( id ) ) ;
3333 } ) ,
@@ -83,21 +83,27 @@ sentryTest('emits element timing metrics after navigation', async ({ getLocalTes
8383
8484 const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
8585
86+ // Start listening before navigation to avoid missing metrics
87+ const pageloadMetricsPromise = waitForMetrics ( page , metrics =>
88+ metrics . some ( m => m . name === 'ui.element.render_time' && getIdentifier ( m ) === 'image-fast' ) ,
89+ ) ;
90+
8691 await page . goto ( url ) ;
8792
8893 // Wait for pageload element timing metrics to arrive before navigating
89- await waitForMetricRequest ( page , metrics =>
90- metrics . some ( m => m . name === 'ui.element.render_time' && getIdentifier ( m ) === 'image-fast' ) ,
91- ) ;
94+ await pageloadMetricsPromise ;
95+
96+ // Start listening before click to avoid missing metrics
97+ const navigationMetricsPromise = waitForMetrics ( page , metrics => {
98+ const seen = new Set ( metrics . filter ( m => m . name === 'ui.element.render_time' ) . map ( getIdentifier ) ) ;
99+ return seen . has ( 'navigation-image' ) && seen . has ( 'navigation-text' ) ;
100+ } ) ;
92101
93102 // Trigger navigation
94103 await page . locator ( '#button1' ) . click ( ) ;
95104
96105 // Wait for navigation element timing metrics
97- const navigationMetrics = await waitForMetricRequest ( page , metrics => {
98- const seen = new Set ( metrics . filter ( m => m . name === 'ui.element.render_time' ) . map ( getIdentifier ) ) ;
99- return seen . has ( 'navigation-image' ) && seen . has ( 'navigation-text' ) ;
100- } ) ;
106+ const navigationMetrics = await navigationMetricsPromise ;
101107
102108 const renderTimeMetrics = navigationMetrics . filter ( m => m . name === 'ui.element.render_time' ) ;
103109 const renderIdentifiers = renderTimeMetrics . map ( getIdentifier ) ;
0 commit comments