Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: restructure and optimise test files (#4736)
Max Schmitt23a6e4dfe9b8
diff --git a/test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/chromium/mock-binary-response.png b/test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/chromium/mock-binary-response.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/chromium/mock-binary-response.pngrename to test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/chromium/mock-binary-response.pngdiff --git a/test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/firefox/mock-binary-response.png b/test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/firefox/mock-binary-response.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/firefox/mock-binary-response.pngrename to test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/firefox/mock-binary-response.pngdiff --git a/test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/webkit/mock-binary-response.png b/test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/webkit/mock-binary-response.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/webkit/mock-binary-response.pngrename to test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/webkit/mock-binary-response.pngdiff --git a/test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/chromium/mock-svg.png b/test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/chromium/mock-svg.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/chromium/mock-svg.pngrename to test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/chromium/mock-svg.pngdiff --git a/test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/firefox/mock-svg.png b/test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/firefox/mock-svg.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/firefox/mock-svg.pngrename to test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/firefox/mock-svg.pngdiff --git a/test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/webkit/mock-svg.png b/test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/webkit/mock-svg.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/webkit/mock-svg.pngrename to test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/webkit/mock-svg.pngdiff --git a/test/__snapshots__/request-fulfill/should-work-with-file-path/chromium/mock-binary-response.png b/test/__snapshots__/page-request-fulfill/should-work-with-file-path/chromium/mock-binary-response.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-work-with-file-path/chromium/mock-binary-response.pngrename to test/__snapshots__/page-request-fulfill/should-work-with-file-path/chromium/mock-binary-response.pngdiff --git a/test/__snapshots__/request-fulfill/should-work-with-file-path/firefox/mock-binary-response.png b/test/__snapshots__/page-request-fulfill/should-work-with-file-path/firefox/mock-binary-response.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-work-with-file-path/firefox/mock-binary-response.pngrename to test/__snapshots__/page-request-fulfill/should-work-with-file-path/firefox/mock-binary-response.pngdiff --git a/test/__snapshots__/request-fulfill/should-work-with-file-path/webkit/mock-binary-response.png b/test/__snapshots__/page-request-fulfill/should-work-with-file-path/webkit/mock-binary-response.pngsimilarity index 100%rename from test/__snapshots__/request-fulfill/should-work-with-file-path/webkit/mock-binary-response.pngrename to test/__snapshots__/page-request-fulfill/should-work-with-file-path/webkit/mock-binary-response.pngdiff --git a/test/accessibility.spec.ts b/test/page-accessibility.spec.tssimilarity index 100%rename from test/accessibility.spec.tsrename to test/page-accessibility.spec.tsdiff --git a/test/autowaiting-basic.spec.ts b/test/page-autowaiting-basic.spec.tssimilarity index 100%rename from test/autowaiting-basic.spec.tsrename to test/page-autowaiting-basic.spec.tsdiff --git a/test/autowaiting-no-hang.spec.ts b/test/page-autowaiting-no-hang.spec.tssimilarity index 100%rename from test/autowaiting-no-hang.spec.tsrename to test/page-autowaiting-no-hang.spec.tsdiff --git a/test/check.spec.ts b/test/page-check.spec.tssimilarity index 100%rename from test/check.spec.tsrename to test/page-check.spec.tsdiff --git a/test/click-react.spec.ts b/test/page-click-react.spec.tssimilarity index 100%rename from test/click-react.spec.tsrename to test/page-click-react.spec.tsdiff --git a/test/click-scroll.spec.ts b/test/page-click-scroll.spec.tssimilarity index 100%rename from test/click-scroll.spec.tsrename to test/page-click-scroll.spec.tsdiff --git a/test/click-timeout-1.spec.ts b/test/page-click-timeout-1.spec.tssimilarity index 100%rename from test/click-timeout-1.spec.tsrename to test/page-click-timeout-1.spec.tsdiff --git a/test/click-timeout-2.spec.ts b/test/page-click-timeout-2.spec.tssimilarity index 100%rename from test/click-timeout-2.spec.tsrename to test/page-click-timeout-2.spec.tsdiff --git a/test/click-timeout-3.spec.ts b/test/page-click-timeout-3.spec.tssimilarity index 100%rename from test/click-timeout-3.spec.tsrename to test/page-click-timeout-3.spec.tsdiff --git a/test/click-timeout-4.spec.ts b/test/page-click-timeout-4.spec.tssimilarity index 100%rename from test/click-timeout-4.spec.tsrename to test/page-click-timeout-4.spec.tsdiff --git a/test/click.spec.ts b/test/page-click.spec.tssimilarity index 100%rename from test/click.spec.tsrename to test/page-click.spec.tsdiff --git a/test/dialog.spec.ts b/test/page-dialog.spec.tssimilarity index 97%rename from test/dialog.spec.tsrename to test/page-dialog.spec.tsindex 885017cd9c..666386621b 100644--- a/test/dialog.spec.ts+++ b/test/page-dialog.spec.ts@@ -64,15 +64,13 @@ it('should dismiss the confirm prompt', async ({page}) => {it('should be able to close context with open alert', (test, { browserName, platform }) => {test.fixme(browserName === 'webkit' && platform === 'darwin');-}, async ({browser}) => {- const context = await browser.newContext();+}, async ({context}) => {const page = await context.newPage();const alertPromise = page.waitForEvent('dialog');await page.evaluate(() => {setTimeout(() => alert('hello'), 0);});await alertPromise;- await context.close();});it('should handle multiple alerts', async ({page}) => {diff --git a/test/dispatchevent.spec.ts b/test/page-dispatchevent.spec.tssimilarity index 100%rename from test/dispatchevent.spec.tsrename to test/page-dispatchevent.spec.tsdiff --git a/test/drag.spec.ts b/test/page-drag.spec.tssimilarity index 100%rename from test/drag.spec.tsrename to test/page-drag.spec.tsdiff --git a/test/page-event-popup.spec.ts b/test/page-event-popup.spec.tsindex a07607fb7e..eff82f3568 100644--- a/test/page-event-popup.spec.ts+++ b/test/page-event-popup.spec.ts@@ -16,21 +16,16 @@import { it, expect } from './fixtures';-it('should work', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work', async ({page}) => {const [popup] = await Promise.all([page.waitForEvent('popup'),page.evaluate(() => window['__popup'] = window.open('about:blank')),]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(true);- await context.close();});-it('should work with window features', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with window features', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);const [popup] = await Promise.all([page.waitForEvent('popup'),@@ -38,12 +33,9 @@ it('should work with window features', async ({browser, server}) => {]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(true);- await context.close();});-it('should emit for immediately closed popups', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should emit for immediately closed popups', async ({page}) => {const [popup] = await Promise.all([page.waitForEvent('popup'),page.evaluate(() => {@@ -52,12 +44,9 @@ it('should emit for immediately closed popups', async ({browser}) => {}),]);expect(popup).toBeTruthy();- await context.close();});-it('should emit for immediately closed popups 2', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should emit for immediately closed popups 2', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);const [popup] = await Promise.all([page.waitForEvent('popup'),@@ -67,12 +56,9 @@ it('should emit for immediately closed popups 2', async ({browser, server}) => {}),]);expect(popup).toBeTruthy();- await context.close();});-it('should be able to capture alert', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should be able to capture alert', async ({page}) => {const evaluatePromise = page.evaluate(() => {const win = window.open('');win.alert('hello');@@ -82,24 +68,18 @@ it('should be able to capture alert', async ({browser}) => {expect(dialog.message()).toBe('hello');await dialog.dismiss();await evaluatePromise;- await context.close();});-it('should work with empty url', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with empty url', async ({page}) => {const [popup] = await Promise.all([page.waitForEvent('popup'),page.evaluate(() => window['__popup'] = window.open('')),]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(true);- await context.close();});-it('should work with noopener and no url', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with noopener and no url', async ({page}) => {const [popup] = await Promise.all([page.waitForEvent('popup'),page.evaluate(() => window['__popup'] = window.open(undefined, null, 'noopener')),@@ -108,24 +88,18 @@ it('should work with noopener and no url', async ({browser}) => {expect(popup.url().split('#')[0]).toBe('about:blank');expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(false);- await context.close();});-it('should work with noopener and about:blank', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with noopener and about:blank', async ({page}) => {const [popup] = await Promise.all([page.waitForEvent('popup'),page.evaluate(() => window['__popup'] = window.open('about:blank', null, 'noopener')),]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(false);- await context.close();});-it('should work with noopener and url', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with noopener and url', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);const [popup] = await Promise.all([page.waitForEvent('popup'),@@ -133,12 +107,9 @@ it('should work with noopener and url', async ({browser, server}) => {]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(false);- await context.close();});-it('should work with clicking target=_blank', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with clicking target=_blank', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<a target=_blank rel="opener" href="/one-style.html">yo</a>');const [popup] = await Promise.all([@@ -147,12 +118,9 @@ it('should work with clicking target=_blank', async ({browser, server}) => {]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(true);- await context.close();});-it('should work with fake-clicking target=_blank and rel=noopener', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with fake-clicking target=_blank and rel=noopener', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');const [popup] = await Promise.all([@@ -161,12 +129,9 @@ it('should work with fake-clicking target=_blank and rel=noopener', async ({brow]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(false);- await context.close();});-it('should work with clicking target=_blank and rel=noopener', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should work with clicking target=_blank and rel=noopener', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');const [popup] = await Promise.all([@@ -175,12 +140,9 @@ it('should work with clicking target=_blank and rel=noopener', async ({browser,]);expect(await page.evaluate(() => !!window.opener)).toBe(false);expect(await popup.evaluate(() => !!window.opener)).toBe(false);- await context.close();});-it('should not treat navigations as new popups', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should not treat navigations as new popups', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<a target=_blank rel=noopener href="/one-style.html">yo</a>');const [popup] = await Promise.all([@@ -190,7 +152,6 @@ it('should not treat navigations as new popups', async ({browser, server}) => {let badSecondPopup = false;page.on('popup', () => badSecondPopup = true);await popup.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');- await context.close();expect(badSecondPopup).toBe(false);});diff --git a/test/page-expose-function.spec.ts b/test/page-expose-function.spec.tsindex 4a28ac9251..f0244b9524 100644--- a/test/page-expose-function.spec.ts+++ b/test/page-expose-function.spec.ts@@ -18,9 +18,7 @@import { it, expect } from './fixtures';import { attachFrame } from './utils';-it('exposeBinding should work', async ({browser}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('exposeBinding should work', async ({page}) => {let bindingSource;await page.exposeBinding('add', (source, a, b) => {bindingSource = source;@@ -29,11 +27,10 @@ it('exposeBinding should work', async ({browser}) => {const result = await page.evaluate(async function() {return window['add'](5, 6);});- expect(bindingSource.context).toBe(context);+ expect(bindingSource.context).toBe(page.context());expect(bindingSource.page).toBe(page);expect(bindingSource.frame).toBe(page.mainFrame());expect(result).toEqual(11);- await context.close();});it('should work', async ({page, server}) => {diff --git a/test/focus.spec.ts b/test/page-focus.spec.tssimilarity index 100%rename from test/focus.spec.tsrename to test/page-focus.spec.tsdiff --git a/test/keyboard.spec.ts b/test/page-keyboard.spec.tssimilarity index 100%rename from test/keyboard.spec.tsrename to test/page-keyboard.spec.tsdiff --git a/test/mouse.spec.ts b/test/page-mouse.spec.tssimilarity index 100%rename from test/mouse.spec.tsrename to test/page-mouse.spec.tsdiff --git a/test/navigation.spec.ts b/test/page-navigation.spec.tssimilarity index 100%rename from test/navigation.spec.tsrename to test/page-navigation.spec.tsdiff --git a/test/network-request.spec.ts b/test/page-network-request.spec.tssimilarity index 100%rename from test/network-request.spec.tsrename to test/page-network-request.spec.tsdiff --git a/test/network-response.spec.ts b/test/page-network-response.spec.tssimilarity index 100%rename from test/network-response.spec.tsrename to test/page-network-response.spec.tsdiff --git a/test/request-continue.spec.ts b/test/page-request-continue.spec.tssimilarity index 100%rename from test/request-continue.spec.tsrename to test/page-request-continue.spec.tsdiff --git a/test/request-fulfill.spec.ts b/test/page-request-fulfill.spec.tssimilarity index 100%rename from test/request-fulfill.spec.tsrename to test/page-request-fulfill.spec.tsdiff --git a/test/wait-for-function.spec.ts b/test/page-wait-for-function.spec.tssimilarity index 100%rename from test/wait-for-function.spec.tsrename to test/page-wait-for-function.spec.tsdiff --git a/test/page-wait-for-load-state.spec.ts b/test/page-wait-for-load-state.spec.tsindex 10fb28fa92..4c834da6da 100644--- a/test/page-wait-for-load-state.spec.ts+++ b/test/page-wait-for-load-state.spec.ts@@ -140,9 +140,7 @@ it('should wait for load state of newPage', async ({browser, context, page, servexpect(await newPage.evaluate(() => document.readyState)).toBe('complete');});-it('should resolve after popup load', async ({browser, server}) => {- const context = await browser.newContext();- const page = await context.newPage();+it('should resolve after popup load', async ({page, server}) => {await page.goto(server.EMPTY_PAGE);// Stall the 'load' by delaying css.let cssResponse;@@ -162,7 +160,6 @@ it('should resolve after popup load', async ({browser, server}) => {await loadSatePromise;expect(resolved).toBe(true);expect(popup.url()).toBe(server.PREFIX + '/one-style.html');- await context.close();});it('should work for frame', async ({page, server}) => {diff --git a/test/wait-for-selector-1.spec.ts b/test/page-wait-for-selector-1.spec.tssimilarity index 100%rename from test/wait-for-selector-1.spec.tsrename to test/page-wait-for-selector-1.spec.tsdiff --git a/test/wait-for-selector-2.spec.ts b/test/page-wait-for-selector-2.spec.tssimilarity index 100%rename from test/wait-for-selector-2.spec.tsrename to test/page-wait-for-selector-2.spec.ts