diff --git a/dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-lcp/test.ts b/dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-lcp/test.ts index 2cfcbe58806e..5ba55ca224a2 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-lcp/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-lcp/test.ts @@ -9,7 +9,6 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN if (shouldSkipTracingTest() || browserName !== 'chromium') { sentryTest.skip(); } - page.route('**', route => route.continue()); page.route('**/path/to/image.png', async (route: Route) => { return route.fulfill({ path: `${__dirname}/assets/sentry-logo-600x179.png` }); @@ -19,9 +18,16 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN const [eventData] = await Promise.all([ getFirstSentryEnvelopeRequest(page), page.goto(url), - page.locator('button').click(), + page.waitForLoadState('networkidle'), ]); + // Clicking the button before image loads will result in the button being the LCP + await page.waitForFunction(() => { + const images = Array.from(document.querySelectorAll('img')); + return images.every(img => img.naturalWidth > 0); + }), + await page.locator('button').click(); + expect(eventData.measurements).toBeDefined(); expect(eventData.measurements?.lcp?.value).toBeDefined();