From e9c0b01bd091624170e7b8d270427e661a0135bb Mon Sep 17 00:00:00 2001 From: techfg Date: Sat, 4 Nov 2023 18:49:51 -0700 Subject: [PATCH] multiple page tests for #492 --- tests/index.html | 1 + .../event-forwarding/event-forwarding.spec.ts | 37 +++++++- .../integrations/event-forwarding/index.html | 10 +- .../facebook-pixel/facebook-pixel.spec.ts | 65 ++++++++++++- tests/integrations/gtm/gtm.spec.ts | 65 ++++++++++++- tests/integrations/gtm/index.html | 16 ++-- tests/platform/event/event.spec.ts | 34 +++++-- tests/platform/multiple-pages/index.html | 95 +++++++++++++++++++ .../multiple-pages/multiple-pages.spec.ts | 27 ++++++ tests/platform/window/window.spec.ts | 34 +++++-- 10 files changed, 346 insertions(+), 38 deletions(-) create mode 100644 tests/platform/multiple-pages/index.html create mode 100644 tests/platform/multiple-pages/multiple-pages.spec.ts diff --git a/tests/index.html b/tests/index.html index 37f5f1a6..595a92ec 100644 --- a/tests/index.html +++ b/tests/index.html @@ -95,6 +95,7 @@

Platform Tests

  • IFrame
  • Image
  • IntersectionObserver
  • +
  • Multiple Pages
  • MutationObserver
  • Navigator
  • Node
  • diff --git a/tests/integrations/event-forwarding/event-forwarding.spec.ts b/tests/integrations/event-forwarding/event-forwarding.spec.ts index aaad4c78..b94797ec 100644 --- a/tests/integrations/event-forwarding/event-forwarding.spec.ts +++ b/tests/integrations/event-forwarding/event-forwarding.spec.ts @@ -1,15 +1,21 @@ -import { test, expect } from '@playwright/test'; - -test('integration event forwarding', async ({ page }) => { - await page.goto('/tests/integrations/event-forwarding/'); - await page.waitForSelector('.completed'); +import { test, expect, Page } from '@playwright/test'; +const testPage = async (page: Page) => { const testFn = page.locator('#testFn'); await expect(testFn).toHaveText('fnReady'); + const testFnInner = page.locator('#testFnInner'); + await expect(testFnInner).toHaveText('fnReady'); + const testArray = page.locator('#testArray'); await expect(testArray).toHaveText('arrayReady'); + const testArrayInner = page.locator('#testArrayInner'); + await expect(testArrayInner).toHaveText('arrayReady'); + + const kiwiSizing = page.locator('#kiwisizing'); + await expect(kiwiSizing).toHaveText('211448987800'); + const buttonForwardEvent = page.locator('#buttonForwardEvent'); await buttonForwardEvent.click(); await expect(testFn).toHaveText('click1'); @@ -21,4 +27,25 @@ test('integration event forwarding', async ({ page }) => { await expect(testArray).toHaveText(JSON.stringify({ mph: 88 })); await buttonArrayPush.click(); await expect(testArray).toHaveText(JSON.stringify({ mph: 89 })); +}; + +test('integration event forwarding', async ({ page }) => { + await page.goto('/tests/integrations/event-forwarding/'); + await page.waitForSelector('.completed'); + await testPage(page); +}); + +test('integration event forwarding multiple tabs', async ({ page, context }) => { + await page.goto('/tests/integrations/event-forwarding/'); + await page.waitForSelector('.completed'); + + const page2 = await context.newPage(); + await page2.goto('/tests/integrations/event-forwarding/'); + await page2.waitForSelector('.completed'); + + await page.bringToFront(); + await testPage(page); + + await page2.bringToFront(); + await testPage(page2); }); diff --git a/tests/integrations/event-forwarding/index.html b/tests/integrations/event-forwarding/index.html index fdb65ad7..be514fc4 100644 --- a/tests/integrations/event-forwarding/index.html +++ b/tests/integrations/event-forwarding/index.html @@ -30,13 +30,16 @@ const testFn = document.getElementById('testFn'); superDuperFunction = function() { + const testFnInner = document.getElementById('testFnInner'); switch (arguments[0]) { case 'fnReady': { testFn.textContent = arguments[0]; + testFnInner.textContent = arguments[0]; break; } case 'testForwardEvent': { testFn.textContent = arguments[1] + (++inc); + testFnInner.textContent = arguments[1] + (inc); break; } } @@ -50,13 +53,16 @@ superArray = []; superArray.push = function() { + const testArrayInner = document.getElementById('testArrayInner'); switch (arguments[0]) { case 'arrayReady': { testArray.textContent = arguments[0]; + testArrayInner.textContent = arguments[0]; break; } default: { testArray.textContent = JSON.stringify(arguments[0]); + testArrayInner.textContent = JSON.stringify(arguments[0]); break; } } @@ -78,7 +84,7 @@ + + + + +

    Multiple Pages

    + + + + +
    +

    All Tests

    + + diff --git a/tests/platform/multiple-pages/multiple-pages.spec.ts b/tests/platform/multiple-pages/multiple-pages.spec.ts new file mode 100644 index 00000000..c4363f38 --- /dev/null +++ b/tests/platform/multiple-pages/multiple-pages.spec.ts @@ -0,0 +1,27 @@ +import { test, expect } from '@playwright/test'; + +test('multiple pages', async ({ page }) => { + await page.goto('/tests/platform/multiple-pages/'); + + await page.waitForSelector('.completed'); + + const testAnchorOpenNewPage = page.locator('#testAnchorOpenNewPage'); + const anchorOpenNewPage = page.locator('#anchorOpenNewPage'); + + await expect(testAnchorOpenNewPage).toHaveText('0'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('1'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('2'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('3'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('4'); + + await anchorOpenNewPage.click(); + await expect(testAnchorOpenNewPage).toHaveText('5'); +}); \ No newline at end of file diff --git a/tests/platform/window/window.spec.ts b/tests/platform/window/window.spec.ts index 2753d945..3ec3d913 100644 --- a/tests/platform/window/window.spec.ts +++ b/tests/platform/window/window.spec.ts @@ -1,10 +1,6 @@ -import { test, expect } from '@playwright/test'; - -test('window', async ({ page }) => { - await page.goto('/tests/platform/window/'); - - await page.waitForSelector('.completed'); +import { test, expect, Page } from '@playwright/test'; +const testPage = async (page: Page) => { const testWindowName = page.locator('#testWindowName'); await expect(testWindowName).toHaveText('Window'); @@ -113,7 +109,7 @@ test('window', async ({ page }) => { await expect(testDevicePixelRatio).not.toHaveText(''); const testOrigin = page.locator('#testOrigin'); - const origin = new URL(await testOrigin.textContent()); + const origin = new URL((await testOrigin.textContent()) || ''); expect(origin.pathname).toBe('/'); expect(origin.hostname).toBe('localhost'); @@ -154,4 +150,28 @@ test('window', async ({ page }) => { const testVisualViewport = page.locator('#testVisualViewport'); await expect(testVisualViewport).toHaveText('scale:1 VisualViewport'); +}; + +test('window', async ({ page }) => { + await page.goto('/tests/platform/window/'); + + await page.waitForSelector('.completed'); + + await testPage(page); +}); + +test('window multiple tabs', async ({ page, context }) => { + await page.goto('/tests/platform/window/'); + + await page.waitForSelector('.completed'); + + const page2 = await context.newPage(); + + await page2.goto('/tests/platform/window/'); + + await page2.waitForSelector('.completed'); + + await testPage(page); + + await testPage(page2); });