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
fix(codegen): properly escape everything for windows (#8415)
Joel Einbinderc9718359f11b
diff --git a/src/server/supplements/recorder/java.ts b/src/server/supplements/recorder/java.tsindex 38eebd4b06..935677f5f8 100644--- a/src/server/supplements/recorder/java.ts+++ b/src/server/supplements/recorder/java.ts@@ -36,7 +36,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {if (action.name === 'openPage') {formatter.add(`Page ${pageAlias} = context.newPage();`);if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/')- formatter.add(`${pageAlias}.navigate("${action.url}");`);+ formatter.add(`${pageAlias}.navigate(${quote(action.url)});`);return formatter.format();}@@ -174,7 +174,7 @@ function formatLaunchOptions(options: any): string {if (typeof options.headless === 'boolean')lines.push(` .setHeadless(false)`);if (options.channel)- lines.push(` .setChannel("${options.channel}")`);+ lines.push(` .setChannel(${quote(options.channel)})`);return lines.join('\n');}@@ -200,15 +200,15 @@ function formatContextOptions(contextOptions: BrowserContextOptions, deviceName:if (options.isMobile)lines.push(` .setIsMobile(${options.isMobile})`);if (options.locale)- lines.push(` .setLocale("${options.locale}")`);+ lines.push(` .setLocale(${quote(options.locale)})`);if (options.proxy)- lines.push(` .setProxy(new Proxy("${options.proxy.server}"))`);+ lines.push(` .setProxy(new Proxy(${quote(options.proxy.server)}))`);if (options.storageState)lines.push(` .setStorageStatePath(Paths.get(${quote(options.storageState as string)}))`);if (options.timezoneId)- lines.push(` .setTimezoneId("${options.timezoneId}")`);+ lines.push(` .setTimezoneId(${quote(options.timezoneId)})`);if (options.userAgent)- lines.push(` .setUserAgent("${options.userAgent}")`);+ lines.push(` .setUserAgent(${quote(options.userAgent)})`);if (options.viewport)lines.push(` .setViewportSize(${options.viewport.width}, ${options.viewport.height})`);return lines.join('\n');diff --git a/src/server/supplements/recorder/javascript.ts b/src/server/supplements/recorder/javascript.tsindex 1f735bef5b..60bad55ff7 100644--- a/src/server/supplements/recorder/javascript.ts+++ b/src/server/supplements/recorder/javascript.ts@@ -181,7 +181,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}}generateStandaloneFooter(saveStorage: string | undefined): string {- const storageStateLine = saveStorage ? `\n await context.storageState({ path: '${saveStorage}' });` : '';+ const storageStateLine = saveStorage ? `\n await context.storageState({ path: ${quote(saveStorage)} });` : '';return `\n // ---------------------${storageStateLine}await context.close();await browser.close();@@ -228,7 +228,7 @@ function formatContextOptions(options: BrowserContextOptions, deviceName: stringif (!serializedObject)serializedObject = '{\n}';const lines = serializedObject.split('\n');- lines.splice(1, 0, `...devices['${deviceName}'],`);+ lines.splice(1, 0, `...devices[${quote(deviceName!)}],`);return lines.join('\n');}diff --git a/src/server/supplements/recorder/python.ts b/src/server/supplements/recorder/python.tsindex acf4abedcb..863b6dc125 100644--- a/src/server/supplements/recorder/python.ts+++ b/src/server/supplements/recorder/python.ts@@ -160,7 +160,7 @@ def run(playwright: Playwright) -> None {generateFooter(saveStorage: string | undefined): string {if (this._isAsync) {- const storageStateLine = saveStorage ? `\n await context.storage_state(path="${saveStorage}")` : '';+ const storageStateLine = saveStorage ? `\n await context.storage_state(path=${quote(saveStorage)})` : '';return `\n # ---------------------${storageStateLine}await context.close()await browser.close()@@ -174,7 +174,7 @@ async def main() -> None:asyncio.run(main())`;} else {- const storageStateLine = saveStorage ? `\n context.storage_state(path="${saveStorage}")` : '';+ const storageStateLine = saveStorage ? `\n context.storage_state(path=${quote(saveStorage)})` : '';return `\n # ---------------------${storageStateLine}context.close()browser.close()@@ -217,7 +217,7 @@ function formatContextOptions(options: BrowserContextOptions, deviceName: stringconst device = deviceName && deviceDescriptors[deviceName];if (!device)return formatOptions(options, false);- return `**playwright.devices["${deviceName}"]` + formatOptions(sanitizeDeviceOptions(device, options), true);+ return `**playwright.devices[${quote(deviceName!)}]` + formatOptions(sanitizeDeviceOptions(device, options), true);}class PythonFormatter {