Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/chromium/mock-binary-response.png
rename to test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/chromium/mock-binary-response.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/firefox/mock-binary-response.png
rename to test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/firefox/mock-binary-response.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-allow-mocking-binary-responses/webkit/mock-binary-response.png
rename to test/__snapshots__/page-request-fulfill/should-allow-mocking-binary-responses/webkit/mock-binary-response.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/chromium/mock-svg.png
rename to test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/chromium/mock-svg.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/firefox/mock-svg.png
rename to test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/firefox/mock-svg.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-allow-mocking-svg-with-charset/webkit/mock-svg.png
rename to test/__snapshots__/page-request-fulfill/should-allow-mocking-svg-with-charset/webkit/mock-svg.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-work-with-file-path/chromium/mock-binary-response.png
rename to test/__snapshots__/page-request-fulfill/should-work-with-file-path/chromium/mock-binary-response.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-work-with-file-path/firefox/mock-binary-response.png
rename to test/__snapshots__/page-request-fulfill/should-work-with-file-path/firefox/mock-binary-response.png
diff --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.png
similarity index 100%
rename from test/__snapshots__/request-fulfill/should-work-with-file-path/webkit/mock-binary-response.png
rename to test/__snapshots__/page-request-fulfill/should-work-with-file-path/webkit/mock-binary-response.png
diff --git a/test/accessibility.spec.ts b/test/page-accessibility.spec.ts
similarity index 100%
rename from test/accessibility.spec.ts
rename to test/page-accessibility.spec.ts
diff --git a/test/autowaiting-basic.spec.ts b/test/page-autowaiting-basic.spec.ts
similarity index 100%
rename from test/autowaiting-basic.spec.ts
rename to test/page-autowaiting-basic.spec.ts
diff --git a/test/autowaiting-no-hang.spec.ts b/test/page-autowaiting-no-hang.spec.ts
similarity index 100%
rename from test/autowaiting-no-hang.spec.ts
rename to test/page-autowaiting-no-hang.spec.ts
diff --git a/test/check.spec.ts b/test/page-check.spec.ts
similarity index 100%
rename from test/check.spec.ts
rename to test/page-check.spec.ts
diff --git a/test/click-react.spec.ts b/test/page-click-react.spec.ts
similarity index 100%
rename from test/click-react.spec.ts
rename to test/page-click-react.spec.ts
diff --git a/test/click-scroll.spec.ts b/test/page-click-scroll.spec.ts
similarity index 100%
rename from test/click-scroll.spec.ts
rename to test/page-click-scroll.spec.ts
diff --git a/test/click-timeout-1.spec.ts b/test/page-click-timeout-1.spec.ts
similarity index 100%
rename from test/click-timeout-1.spec.ts
rename to test/page-click-timeout-1.spec.ts
diff --git a/test/click-timeout-2.spec.ts b/test/page-click-timeout-2.spec.ts
similarity index 100%
rename from test/click-timeout-2.spec.ts
rename to test/page-click-timeout-2.spec.ts
diff --git a/test/click-timeout-3.spec.ts b/test/page-click-timeout-3.spec.ts
similarity index 100%
rename from test/click-timeout-3.spec.ts
rename to test/page-click-timeout-3.spec.ts
diff --git a/test/click-timeout-4.spec.ts b/test/page-click-timeout-4.spec.ts
similarity index 100%
rename from test/click-timeout-4.spec.ts
rename to test/page-click-timeout-4.spec.ts
diff --git a/test/click.spec.ts b/test/page-click.spec.ts
similarity index 100%
rename from test/click.spec.ts
rename to test/page-click.spec.ts
diff --git a/test/dialog.spec.ts b/test/page-dialog.spec.ts
similarity index 97%
rename from test/dialog.spec.ts
rename to test/page-dialog.spec.ts
index 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.ts
similarity index 100%
rename from test/dispatchevent.spec.ts
rename to test/page-dispatchevent.spec.ts
diff --git a/test/drag.spec.ts b/test/page-drag.spec.ts
similarity index 100%
rename from test/drag.spec.ts
rename to test/page-drag.spec.ts
diff --git a/test/page-event-popup.spec.ts b/test/page-event-popup.spec.ts
index 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.ts
index 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.ts
similarity index 100%
rename from test/focus.spec.ts
rename to test/page-focus.spec.ts
diff --git a/test/keyboard.spec.ts b/test/page-keyboard.spec.ts
similarity index 100%
rename from test/keyboard.spec.ts
rename to test/page-keyboard.spec.ts
diff --git a/test/mouse.spec.ts b/test/page-mouse.spec.ts
similarity index 100%
rename from test/mouse.spec.ts
rename to test/page-mouse.spec.ts
diff --git a/test/navigation.spec.ts b/test/page-navigation.spec.ts
similarity index 100%
rename from test/navigation.spec.ts
rename to test/page-navigation.spec.ts
diff --git a/test/network-request.spec.ts b/test/page-network-request.spec.ts
similarity index 100%
rename from test/network-request.spec.ts
rename to test/page-network-request.spec.ts
diff --git a/test/network-response.spec.ts b/test/page-network-response.spec.ts
similarity index 100%
rename from test/network-response.spec.ts
rename to test/page-network-response.spec.ts
diff --git a/test/request-continue.spec.ts b/test/page-request-continue.spec.ts
similarity index 100%
rename from test/request-continue.spec.ts
rename to test/page-request-continue.spec.ts
diff --git a/test/request-fulfill.spec.ts b/test/page-request-fulfill.spec.ts
similarity index 100%
rename from test/request-fulfill.spec.ts
rename to test/page-request-fulfill.spec.ts
diff --git a/test/wait-for-function.spec.ts b/test/page-wait-for-function.spec.ts
similarity index 100%
rename from test/wait-for-function.spec.ts
rename to test/page-wait-for-function.spec.ts
diff --git a/test/page-wait-for-load-state.spec.ts b/test/page-wait-for-load-state.spec.ts
index 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, serv
expect(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.ts
similarity index 100%
rename from test/wait-for-selector-1.spec.ts
rename to test/page-wait-for-selector-1.spec.ts
diff --git a/test/wait-for-selector-2.spec.ts b/test/page-wait-for-selector-2.spec.ts
similarity index 100%
rename from test/wait-for-selector-2.spec.ts
rename to test/page-wait-for-selector-2.spec.ts