From a00b111db76863dba48bb74d743acea2bb83a7a2 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 19 Jun 2023 13:55:53 +0200 Subject: [PATCH] ref: fix test --- .../suites/replay/slowClick/template.html | 2 +- .../suites/replay/slowClick/windowOpen/test.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/browser-integration-tests/suites/replay/slowClick/template.html b/packages/browser-integration-tests/suites/replay/slowClick/template.html index 83bda10053d1..19bd283db90e 100644 --- a/packages/browser-integration-tests/suites/replay/slowClick/template.html +++ b/packages/browser-integration-tests/suites/replay/slowClick/template.html @@ -75,7 +75,7 @@

Bottom

document.getElementById('out').innerHTML += 'mutationButton clicked
'; }); document.getElementById('windowOpenButton').addEventListener('click', () => { - window.open('https://example.com/', '_self'); + window.open('https://example.com/', '_blank'); }); // Do nothing on these elements diff --git a/packages/browser-integration-tests/suites/replay/slowClick/windowOpen/test.ts b/packages/browser-integration-tests/suites/replay/slowClick/windowOpen/test.ts index 04dc4bb745e7..ee160820c769 100644 --- a/packages/browser-integration-tests/suites/replay/slowClick/windowOpen/test.ts +++ b/packages/browser-integration-tests/suites/replay/slowClick/windowOpen/test.ts @@ -3,7 +3,7 @@ import { expect } from '@playwright/test'; import { sentryTest } from '../../../../utils/fixtures'; import { getCustomRecordingEvents, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers'; -sentryTest('window.open() is considered for slow click', async ({ getLocalTestUrl, page }) => { +sentryTest('window.open() is considered for slow click', async ({ getLocalTestUrl, page, browser }) => { if (shouldSkipReplayTest()) { sentryTest.skip(); } @@ -29,8 +29,11 @@ sentryTest('window.open() is considered for slow click', async ({ getLocalTestUr return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click'); }); + // Ensure window.open() still works as expected + const context = browser.contexts()[0]; + const waitForNewPage = context.waitForEvent('page'); + await page.click('#windowOpenButton'); - const navPromise = page.waitForURL('https://example.com/'); const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); @@ -54,8 +57,10 @@ sentryTest('window.open() is considered for slow click', async ({ getLocalTestUr }, ]); - await navPromise; + await waitForNewPage; - // Ensure window.open() still works as expected - expect(await page.url()).toBe('https://example.com/'); + const pages = context.pages(); + + expect(pages.length).toBe(2); + expect(pages[1].url()).toBe('https://example.com/'); });