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
test: use http endpoint instead of local file for codegen tests (#36498)
Max Schmittffa4618d2f02
diff --git a/tests/library/inspector/cli-codegen-csharp.spec.ts b/tests/library/inspector/cli-codegen-csharp.spec.tsindex 8b79f23b2a..d4f97b9f68 100644--- a/tests/library/inspector/cli-codegen-csharp.spec.ts+++ b/tests/library/inspector/cli-codegen-csharp.spec.ts@@ -14,11 +14,9 @@* limitations under the License.*/-import path from 'path';import fs from 'fs';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();const launchOptions = (channel: string) => {return channel ? `Channel = "${channel}",\n Headless = false,` : `Headless = false,`;};@@ -27,8 +25,8 @@ function capitalize(browserName: string): string {return browserName[0].toUpperCase() + browserName.slice(1);}-test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => {- const cli = runCLI(['--target=csharp', emptyHTML]);+test('should print the correct imports and context options', async ({ browserName, channel, runCLI, server }) => {+ const cli = runCLI(['--target=csharp', server.EMPTY_PAGE]);const expectedResult = `using Microsoft.Playwright;using System;using System.Threading.Tasks;@@ -42,7 +40,7 @@ var context = await browser.NewContextAsync();`;await cli.waitFor(expectedResult);});-test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI, server }) => {const cli = runCLI(['--color-scheme=dark','--geolocation=37.819722,-122.478611',@@ -52,7 +50,7 @@ test('should print the correct context options for custom settings', async ({ br'--user-agent=hardkodemium','--viewport-size=1280,720','--target=csharp',- emptyHTML]);+ server.EMPTY_PAGE]);const expectedResult = `using var playwright = await Playwright.CreateAsync();await using var browser = await playwright.${capitalize(browserName)}.LaunchAsync(new BrowserTypeLaunchOptions@@ -84,10 +82,10 @@ var context = await browser.NewContextAsync(new BrowserNewContextOptionsawait cli.waitFor(expectedResult);});-test('should print the correct context options when using a device', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'chromium');- const cli = runCLI(['--device=Pixel 2', '--target=csharp', emptyHTML]);+ const cli = runCLI(['--device=Pixel 2', '--target=csharp', server.EMPTY_PAGE]);const expectedResult = `using var playwright = await Playwright.CreateAsync();await using var browser = await playwright.${capitalize(browserName)}.LaunchAsync(new BrowserTypeLaunchOptions@@ -98,7 +96,7 @@ var context = await browser.NewContextAsync(playwright.Devices["Pixel 2"]);`;await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'webkit');const cli = runCLI([@@ -111,7 +109,7 @@ test('should print the correct context options when using a device and additiona'--user-agent=hardkodemium','--viewport-size=1280,720','--target=csharp',- emptyHTML]);+ server.EMPTY_PAGE]);const expectedResult = `using var playwright = await Playwright.CreateAsync();await using var browser = await playwright.${capitalize(browserName)}.LaunchAsync(new BrowserTypeLaunchOptions@@ -143,11 +141,11 @@ var context = await browser.NewContextAsync(new BrowserNewContextOptions(playwriawait cli.waitFor(expectedResult);});-test('should print load/save storageState', async ({ browserName, channel, runCLI }, testInfo) => {+test('should print load/save storageState', async ({ browserName, channel, runCLI, server }, testInfo) => {const loadFileName = testInfo.outputPath('load.json');const saveFileName = testInfo.outputPath('save.json');await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');- const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=csharp', emptyHTML]);+ const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=csharp', server.EMPTY_PAGE]);const expectedResult1 = `using var playwright = await Playwright.CreateAsync();await using var browser = await playwright.${capitalize(browserName)}.LaunchAsync(new BrowserTypeLaunchOptions@@ -194,15 +192,15 @@ test('should work with --save-har and --save-har-glob', async ({ runCLI }, testI});for (const testFramework of ['nunit', 'mstest'] as const) {- test(`should not print context options method override in ${testFramework} if no options were passed`, async ({ runCLI }) => {- const cli = runCLI([`--target=csharp-${testFramework}`, emptyHTML]);- await cli.waitFor(`Page.GotoAsync("${emptyHTML}")`);+ test(`should not print context options method override in ${testFramework} if no options were passed`, async ({ runCLI, server }) => {+ const cli = runCLI([`--target=csharp-${testFramework}`, server.EMPTY_PAGE]);+ await cli.waitFor(`Page.GotoAsync("${server.EMPTY_PAGE}")`);expect(cli.text()).not.toContain('public override BrowserNewContextOptions ContextOptions()');});- test(`should print context options method override in ${testFramework} if options were passed`, async ({ runCLI }) => {- const cli = runCLI([`--target=csharp-${testFramework}`, '--color-scheme=dark', emptyHTML]);- await cli.waitFor(`Page.GotoAsync("${emptyHTML}")`);+ test(`should print context options method override in ${testFramework} if options were passed`, async ({ runCLI, server }) => {+ const cli = runCLI([`--target=csharp-${testFramework}`, '--color-scheme=dark', server.EMPTY_PAGE]);+ await cli.waitFor(`Page.GotoAsync("${server.EMPTY_PAGE}")`);expect(cli.text()).toContain(` public override BrowserNewContextOptions ContextOptions(){return new BrowserNewContextOptions@@ -239,9 +237,9 @@ for (const testFramework of ['nunit', 'mstest'] as const) {});}-test(`should print a valid basic program in mstest`, async ({ runCLI }) => {- const cli = runCLI([`--target=csharp-mstest`, '--color-scheme=dark', emptyHTML]);- await cli.waitFor(`Page.GotoAsync("${emptyHTML}")`);+test(`should print a valid basic program in mstest`, async ({ runCLI, server }) => {+ const cli = runCLI([`--target=csharp-mstest`, '--color-scheme=dark', server.EMPTY_PAGE]);+ await cli.waitFor(`Page.GotoAsync("${server.EMPTY_PAGE}")`);const expected = `using Microsoft.Playwright.MSTest;using Microsoft.Playwright;@@ -259,15 +257,15 @@ public class Tests : PageTest[TestMethod]public async Task MyTest(){- await Page.GotoAsync("${emptyHTML}");+ await Page.GotoAsync("${server.EMPTY_PAGE}");}}`;expect(cli.text()).toContain(expected);});-test(`should print a valid basic program in nunit`, async ({ runCLI }) => {- const cli = runCLI([`--target=csharp-nunit`, '--color-scheme=dark', emptyHTML]);- await cli.waitFor(`Page.GotoAsync("${emptyHTML}")`);+test(`should print a valid basic program in nunit`, async ({ runCLI, server }) => {+ const cli = runCLI([`--target=csharp-nunit`, '--color-scheme=dark', server.EMPTY_PAGE]);+ await cli.waitFor(`Page.GotoAsync("${server.EMPTY_PAGE}")`);const expected = `using Microsoft.Playwright.NUnit;using Microsoft.Playwright;@@ -286,7 +284,7 @@ public class Tests : PageTest[Test]public async Task MyTest(){- await Page.GotoAsync("${emptyHTML}");+ await Page.GotoAsync("${server.EMPTY_PAGE}");}}`;expect(cli.text()).toContain(expected);diff --git a/tests/library/inspector/cli-codegen-java.spec.ts b/tests/library/inspector/cli-codegen-java.spec.tsindex 2fd4a8fd42..a20281c80d 100644--- a/tests/library/inspector/cli-codegen-java.spec.ts+++ b/tests/library/inspector/cli-codegen-java.spec.ts@@ -15,16 +15,14 @@*/import fs from 'fs';-import path from 'path';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();const launchOptions = (channel: string) => {return channel ? `.setChannel("${channel}")\n .setHeadless(false)` : '.setHeadless(false)';};-test('should print the correct imports and context options', async ({ runCLI, channel, browserName }) => {- const cli = runCLI(['--target=java', emptyHTML]);+test('should print the correct imports and context options', async ({ runCLI, channel, browserName, server }) => {+ const cli = runCLI(['--target=java', server.EMPTY_PAGE]);const expectedResult = `import com.microsoft.playwright.*;import com.microsoft.playwright.options.*;import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;@@ -39,17 +37,17 @@ public class Example {await cli.waitFor(expectedResult);});-test('should print the correct context options for custom settings', async ({ runCLI, browserName }) => {- const cli = runCLI(['--color-scheme=light', '--target=java', emptyHTML]);+test('should print the correct context options for custom settings', async ({ runCLI, server }) => {+ const cli = runCLI(['--color-scheme=light', '--target=java', server.EMPTY_PAGE]);const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions().setColorScheme(ColorScheme.LIGHT));`;await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device', async ({ browserName, runCLI }) => {+test('should print the correct context options when using a device', async ({ browserName, runCLI, server }) => {test.skip(browserName !== 'chromium');- const cli = runCLI(['--device=Pixel 2', '--target=java', emptyHTML]);+ const cli = runCLI(['--device=Pixel 2', '--target=java', server.EMPTY_PAGE]);await cli.waitFor(`.setViewportSize(411, 731));`);const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions().setDeviceScaleFactor(2.625)@@ -60,10 +58,10 @@ test('should print the correct context options when using a device', async ({ brexpect(cli.text().replace(/(.*Chrome\/)(.*?)( .*)/m, '$1XXXX$3')).toContain(expectedResult);});-test('should print the correct context options when using a device and additional options', async ({ browserName, runCLI }) => {+test('should print the correct context options when using a device and additional options', async ({ browserName, runCLI, server }) => {test.skip(browserName !== 'webkit');- const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=java', emptyHTML]);+ const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=java', server.EMPTY_PAGE]);await cli.waitFor(`.setViewportSize(414, 715));`);const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions().setColorScheme(ColorScheme.LIGHT)@@ -75,11 +73,11 @@ test('should print the correct context options when using a device and additionaexpect(cli.text().replace(/(.*Version\/)(.*?)( .*)/m, '$1XXXX$3')).toContain(expectedResult);});-test('should print load/save storage_state', async ({ runCLI, browserName }, testInfo) => {+test('should print load/save storage_state', async ({ runCLI, server }, testInfo) => {const loadFileName = testInfo.outputPath('load.json');const saveFileName = testInfo.outputPath('save.json');await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');- const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=java', emptyHTML]);+ const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=java', server.EMPTY_PAGE]);const expectedResult1 = `BrowserContext context = browser.newContext(new Browser.NewContextOptions().setStorageStatePath(Paths.get(${JSON.stringify(loadFileName)})));`;await cli.waitFor(expectedResult1);@@ -115,8 +113,8 @@ test('should work with --save-har and --save-har-glob as java-junit', async ({ rexpect(json.log.creator.name).toBe('Playwright');});-test('should print the correct imports in junit', async ({ runCLI, channel, browserName }) => {- const cli = runCLI(['--target=java-junit', emptyHTML]);+test('should print the correct imports in junit', async ({ runCLI, server }) => {+ const cli = runCLI(['--target=java-junit', server.EMPTY_PAGE]);const expectedImportResult = `import com.microsoft.playwright.junit.UsePlaywright;import com.microsoft.playwright.Page;import com.microsoft.playwright.options.*;@@ -126,8 +124,8 @@ import static com.microsoft.playwright.assertions.PlaywrightAssertions.*;`;await cli.waitFor(expectedImportResult);});-test('should print a valid basic program in junit', async ({ runCLI, channel, browserName }) => {- const cli = runCLI(['--target=java-junit', emptyHTML]);+test('should print a valid basic program in junit', async ({ runCLI, server }) => {+ const cli = runCLI(['--target=java-junit', server.EMPTY_PAGE]);const expectedResult = `import com.microsoft.playwright.junit.UsePlaywright;import com.microsoft.playwright.Page;import com.microsoft.playwright.options.*;@@ -139,7 +137,7 @@ import static com.microsoft.playwright.assertions.PlaywrightAssertions.*;public class TestExample {@Testvoid test(Page page) {- page.navigate("${emptyHTML}");+ page.navigate("${server.EMPTY_PAGE}");}}`;await cli.waitFor(expectedResult);diff --git a/tests/library/inspector/cli-codegen-javascript.spec.ts b/tests/library/inspector/cli-codegen-javascript.spec.tsindex f2c34899d8..3d13fc2d14 100644--- a/tests/library/inspector/cli-codegen-javascript.spec.ts+++ b/tests/library/inspector/cli-codegen-javascript.spec.ts@@ -15,17 +15,14 @@*/import fs from 'fs';-import path from 'path';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();-const launchOptions = (channel: string) => {return channel ? `channel: '${channel}',\n headless: false` : 'headless: false';};-test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => {- const cli = runCLI(['--target=javascript', emptyHTML]);+test('should print the correct imports and context options', async ({ browserName, channel, runCLI, server }) => {+ const cli = runCLI(['--target=javascript', server.EMPTY_PAGE]);const expectedResult = `const { ${browserName} } = require('playwright');(async () => {@@ -36,8 +33,8 @@ test('should print the correct imports and context options', async ({ browserNamawait cli.waitFor(expectedResult);});-test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => {- const cli = runCLI(['--color-scheme=light', '--target=javascript', emptyHTML]);+test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI, server }) => {+ const cli = runCLI(['--color-scheme=light', '--target=javascript', server.EMPTY_PAGE]);const expectedResult = `const { ${browserName} } = require('playwright');(async () => {@@ -51,10 +48,10 @@ test('should print the correct context options for custom settings', async ({ br});-test('should print the correct context options when using a device', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'chromium');- const cli = runCLI(['--device=Pixel 2', '--target=javascript', emptyHTML]);+ const cli = runCLI(['--device=Pixel 2', '--target=javascript', server.EMPTY_PAGE]);const expectedResult = `const { chromium, devices } = require('playwright');(async () => {@@ -67,10 +64,10 @@ test('should print the correct context options when using a device', async ({ brawait cli.waitFor(expectedResult);});-test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'webkit');- const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=javascript', emptyHTML]);+ const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=javascript', server.EMPTY_PAGE]);const expectedResult = `const { webkit, devices } = require('playwright');(async () => {@@ -84,9 +81,9 @@ test('should print the correct context options when using a device and additionaawait cli.waitFor(expectedResult);});-test('should save the codegen output to a file if specified', async ({ browserName, channel, runCLI }, testInfo) => {+test('should save the codegen output to a file if specified', async ({ browserName, channel, runCLI, server }, testInfo) => {const tmpFile = testInfo.outputPath('script.js');- const cli = runCLI(['--output', tmpFile, '--target=javascript', emptyHTML], {+ const cli = runCLI(['--output', tmpFile, '--target=javascript', server.EMPTY_PAGE], {autoExitWhen: 'await page.goto', // We have to wait for the initial navigation to be recorded.});await cli.waitForCleanExit();@@ -99,7 +96,7 @@ test('should save the codegen output to a file if specified', async ({ browserNa});const context = await browser.newContext();const page = await context.newPage();- await page.goto('${emptyHTML}');+ await page.goto('${server.EMPTY_PAGE}');await page.close();// ---------------------@@ -108,11 +105,11 @@ test('should save the codegen output to a file if specified', async ({ browserNa})();`);});-test('should print load/save storageState', async ({ browserName, channel, runCLI }, testInfo) => {+test('should print load/save storageState', async ({ browserName, channel, runCLI, server }, testInfo) => {const loadFileName = testInfo.outputPath('load.json');const saveFileName = testInfo.outputPath('save.json');await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');- const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=javascript', emptyHTML]);+ const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=javascript', server.EMPTY_PAGE]);const expectedResult1 = `const { ${browserName} } = require('playwright');(async () => {diff --git a/tests/library/inspector/cli-codegen-pytest.spec.ts b/tests/library/inspector/cli-codegen-pytest.spec.tsindex ce9cd97ee0..6dde41d1ec 100644--- a/tests/library/inspector/cli-codegen-pytest.spec.ts+++ b/tests/library/inspector/cli-codegen-pytest.spec.ts@@ -15,13 +15,10 @@*/import fs from 'fs';-import path from 'path';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();--test('should print the correct imports and context options', async ({ runCLI }) => {- const cli = runCLI(['--target=python-pytest', emptyHTML]);+test('should print the correct imports and context options', async ({ runCLI, server }) => {+ const cli = runCLI(['--target=python-pytest', server.EMPTY_PAGE]);const expectedResult = `import refrom playwright.sync_api import Page, expect@@ -30,11 +27,11 @@ def test_example(page: Page) -> None:`;await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device and lang', async ({ browserName, runCLI }, testInfo) => {+test('should print the correct context options when using a device and lang', async ({ browserName, runCLI, server }, testInfo) => {test.skip(browserName !== 'webkit');const tmpFile = testInfo.outputPath('script.js');- const cli = runCLI(['--target=python-pytest', '--device=iPhone 11', '--lang=en-US', '--output', tmpFile, emptyHTML], {+ const cli = runCLI(['--target=python-pytest', '--device=iPhone 11', '--lang=en-US', '--output', tmpFile, server.EMPTY_PAGE], {autoExitWhen: 'page.goto',});await cli.waitForCleanExit();@@ -50,13 +47,13 @@ def browser_context_args(browser_context_args, playwright):def test_example(page: Page) -> None:- page.goto("${emptyHTML}")+ page.goto("${server.EMPTY_PAGE}")`);});-test('should save the codegen output to a file if specified', async ({ runCLI }, testInfo) => {+test('should save the codegen output to a file if specified', async ({ runCLI, server }, testInfo) => {const tmpFile = testInfo.outputPath('test_example.py');- const cli = runCLI(['--target=python-pytest', '--output', tmpFile, emptyHTML], {+ const cli = runCLI(['--target=python-pytest', '--output', tmpFile, server.EMPTY_PAGE], {autoExitWhen: 'page.goto',});await cli.waitForCleanExit();@@ -66,7 +63,7 @@ from playwright.sync_api import Page, expectdef test_example(page: Page) -> None:- page.goto("${emptyHTML}")+ page.goto("${server.EMPTY_PAGE}")`);});diff --git a/tests/library/inspector/cli-codegen-python-async.spec.ts b/tests/library/inspector/cli-codegen-python-async.spec.tsindex 94cc947ae4..2fb5e0ba65 100644--- a/tests/library/inspector/cli-codegen-python-async.spec.ts+++ b/tests/library/inspector/cli-codegen-python-async.spec.ts@@ -15,16 +15,14 @@*/import fs from 'fs';-import path from 'path';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();const launchOptions = (channel: string) => {return channel ? `channel="${channel}", headless=False` : 'headless=False';};-test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => {- const cli = runCLI(['--target=python-async', emptyHTML]);+test('should print the correct imports and context options', async ({ browserName, channel, runCLI, server }) => {+ const cli = runCLI(['--target=python-async', server.EMPTY_PAGE]);const expectedResult = `import asyncioimport refrom playwright.async_api import Playwright, async_playwright, expect@@ -36,8 +34,8 @@ async def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => {- const cli = runCLI(['--color-scheme=light', '--target=python-async', emptyHTML]);+test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI, server }) => {+ const cli = runCLI(['--color-scheme=light', '--target=python-async', server.EMPTY_PAGE]);const expectedResult = `import asyncioimport refrom playwright.async_api import Playwright, async_playwright, expect@@ -49,10 +47,10 @@ async def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'chromium');- const cli = runCLI(['--device=Pixel 2', '--target=python-async', emptyHTML]);+ const cli = runCLI(['--device=Pixel 2', '--target=python-async', server.EMPTY_PAGE]);const expectedResult = `import asyncioimport refrom playwright.async_api import Playwright, async_playwright, expect@@ -64,10 +62,10 @@ async def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'webkit');- const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=python-async', emptyHTML]);+ const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=python-async', server.EMPTY_PAGE]);const expectedResult = `import asyncioimport refrom playwright.async_api import Playwright, async_playwright, expect@@ -79,9 +77,9 @@ async def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should save the codegen output to a file if specified', async ({ browserName, channel, runCLI }, testInfo) => {+test('should save the codegen output to a file if specified', async ({ browserName, channel, runCLI, server }, testInfo) => {const tmpFile = testInfo.outputPath('example.py');- const cli = runCLI(['--target=python-async', '--output', tmpFile, emptyHTML], {+ const cli = runCLI(['--target=python-async', '--output', tmpFile, server.EMPTY_PAGE], {autoExitWhen: 'page.goto',});await cli.waitForCleanExit();@@ -95,7 +93,7 @@ async def run(playwright: Playwright) -> None:browser = await playwright.${browserName}.launch(${launchOptions(channel)})context = await browser.new_context()page = await context.new_page()- await page.goto("${emptyHTML}")+ await page.goto("${server.EMPTY_PAGE}")await page.close()# ---------------------@@ -112,11 +110,11 @@ asyncio.run(main())`);});-test('should print load/save storage_state', async ({ browserName, channel, runCLI }, testInfo) => {+test('should print load/save storage_state', async ({ browserName, channel, runCLI, server }, testInfo) => {const loadFileName = testInfo.outputPath('load.json');const saveFileName = testInfo.outputPath('save.json');await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');- const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=python-async', emptyHTML]);+ const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=python-async', server.EMPTY_PAGE]);const expectedResult1 = `import asyncioimport refrom playwright.async_api import Playwright, async_playwright, expectdiff --git a/tests/library/inspector/cli-codegen-python.spec.ts b/tests/library/inspector/cli-codegen-python.spec.tsindex 13898efb5f..50cd2a1552 100644--- a/tests/library/inspector/cli-codegen-python.spec.ts+++ b/tests/library/inspector/cli-codegen-python.spec.ts@@ -15,16 +15,14 @@*/import fs from 'fs';-import path from 'path';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();const launchOptions = (channel: string) => {return channel ? `channel="${channel}", headless=False` : 'headless=False';};-test('should print the correct imports and context options', async ({ runCLI, channel, browserName }) => {- const cli = runCLI(['--target=python', emptyHTML]);+test('should print the correct imports and context options', async ({ runCLI, channel, browserName, server }) => {+ const cli = runCLI(['--target=python', server.EMPTY_PAGE]);const expectedResult = `import refrom playwright.sync_api import Playwright, sync_playwright, expect@@ -35,8 +33,8 @@ def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should print the correct context options for custom settings', async ({ runCLI, channel, browserName }) => {- const cli = runCLI(['--color-scheme=light', '--target=python', emptyHTML]);+test('should print the correct context options for custom settings', async ({ runCLI, channel, browserName, server }) => {+ const cli = runCLI(['--color-scheme=light', '--target=python', server.EMPTY_PAGE]);const expectedResult = `import refrom playwright.sync_api import Playwright, sync_playwright, expect@@ -47,10 +45,10 @@ def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'chromium');- const cli = runCLI(['--device=Pixel 2', '--target=python', emptyHTML]);+ const cli = runCLI(['--device=Pixel 2', '--target=python', server.EMPTY_PAGE]);const expectedResult = `import refrom playwright.sync_api import Playwright, sync_playwright, expect@@ -61,10 +59,10 @@ def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI, server }) => {test.skip(browserName !== 'webkit');- const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=python', emptyHTML]);+ const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=python', server.EMPTY_PAGE]);const expectedResult = `import refrom playwright.sync_api import Playwright, sync_playwright, expect@@ -75,9 +73,9 @@ def run(playwright: Playwright) -> None:await cli.waitFor(expectedResult);});-test('should save the codegen output to a file if specified', async ({ runCLI, channel, browserName }, testInfo) => {+test('should save the codegen output to a file if specified', async ({ runCLI, channel, browserName, server }, testInfo) => {const tmpFile = testInfo.outputPath('example.py');- const cli = runCLI(['--target=python', '--output', tmpFile, emptyHTML], {+ const cli = runCLI(['--target=python', '--output', tmpFile, server.EMPTY_PAGE], {autoExitWhen: 'page.goto',});await cli.waitForCleanExit();@@ -90,7 +88,7 @@ def run(playwright: Playwright) -> None:browser = playwright.${browserName}.launch(${launchOptions(channel)})context = browser.new_context()page = context.new_page()- page.goto("${emptyHTML}")+ page.goto("${server.EMPTY_PAGE}")page.close()# ---------------------@@ -103,11 +101,11 @@ with sync_playwright() as playwright:`);});-test('should print load/save storage_state', async ({ runCLI, channel, browserName }, testInfo) => {+test('should print load/save storage_state', async ({ runCLI, channel, browserName, server }, testInfo) => {const loadFileName = testInfo.outputPath('load.json');const saveFileName = testInfo.outputPath('save.json');await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');- const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=python', emptyHTML]);+ const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=python', server.EMPTY_PAGE]);const expectedResult1 = `import refrom playwright.sync_api import Playwright, sync_playwright, expectdiff --git a/tests/library/inspector/cli-codegen-test.spec.ts b/tests/library/inspector/cli-codegen-test.spec.tsindex b24871877f..3e01755cf0 100644--- a/tests/library/inspector/cli-codegen-test.spec.ts+++ b/tests/library/inspector/cli-codegen-test.spec.ts@@ -15,13 +15,10 @@*/import fs from 'fs';-import path from 'path';import { test, expect } from './inspectorTest';-const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'assets', 'empty.html')).toString();--test('should print the correct imports and context options', async ({ runCLI }) => {- const cli = runCLI([emptyHTML]);+test('should print the correct imports and context options', async ({ runCLI, server }) => {+ const cli = runCLI([server.EMPTY_PAGE]);const expectedResult = `import { test, expect } from '@playwright/test';test('test', async ({ page }) => {@@ -29,8 +26,8 @@ test('test', async ({ page }) => {await cli.waitFor(expectedResult);});-test('should print the correct context options for custom settings', async ({ browserName, channel, runCLI }) => {- const cli = runCLI(['--color-scheme=light', emptyHTML]);+test('should print the correct context options for custom settings', async ({ runCLI, server }) => {+ const cli = runCLI(['--color-scheme=light', server.EMPTY_PAGE]);const expectedResult = `import { test, expect } from '@playwright/test';test.use({@@ -42,10 +39,10 @@ test('test', async ({ page }) => {`;});-test('should print the correct context options when using a device', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device', async ({ browserName, runCLI, server }) => {test.skip(browserName !== 'chromium');- const cli = runCLI(['--device=Pixel 2', emptyHTML]);+ const cli = runCLI(['--device=Pixel 2', server.EMPTY_PAGE]);const expectedResult = `import { test, expect, devices } from '@playwright/test';test.use({@@ -56,10 +53,10 @@ test('test', async ({ page }) => {`;await cli.waitFor(expectedResult);});-test('should print the correct context options when using a device and additional options', async ({ browserName, channel, runCLI }) => {+test('should print the correct context options when using a device and additional options', async ({ browserName, server, runCLI }) => {test.skip(browserName !== 'webkit');- const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', emptyHTML]);+ const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', server.EMPTY_PAGE]);const expectedResult = `import { test, expect, devices } from '@playwright/test';test.use({@@ -71,10 +68,10 @@ test('test', async ({ page }) => {`;await cli.waitFor(expectedResult);});-test('should print load storageState', async ({ browserName, channel, runCLI }, testInfo) => {+test('should print load storageState', async ({ runCLI, server }, testInfo) => {const loadFileName = testInfo.outputPath('load.json');await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');- const cli = runCLI([`--load-storage=${loadFileName}`, emptyHTML]);+ const cli = runCLI([`--load-storage=${loadFileName}`, server.EMPTY_PAGE]);const expectedResult = `import { test, expect } from '@playwright/test';test.use({