mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(codegen): properly escape everything for windows (#8415)
This commit is contained in:
parent
b0a7843247
commit
c9718359f1
@ -36,7 +36,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
|||||||
if (action.name === 'openPage') {
|
if (action.name === 'openPage') {
|
||||||
formatter.add(`Page ${pageAlias} = context.newPage();`);
|
formatter.add(`Page ${pageAlias} = context.newPage();`);
|
||||||
if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/')
|
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();
|
return formatter.format();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ function formatLaunchOptions(options: any): string {
|
|||||||
if (typeof options.headless === 'boolean')
|
if (typeof options.headless === 'boolean')
|
||||||
lines.push(` .setHeadless(false)`);
|
lines.push(` .setHeadless(false)`);
|
||||||
if (options.channel)
|
if (options.channel)
|
||||||
lines.push(` .setChannel("${options.channel}")`);
|
lines.push(` .setChannel(${quote(options.channel)})`);
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,15 +200,15 @@ function formatContextOptions(contextOptions: BrowserContextOptions, deviceName:
|
|||||||
if (options.isMobile)
|
if (options.isMobile)
|
||||||
lines.push(` .setIsMobile(${options.isMobile})`);
|
lines.push(` .setIsMobile(${options.isMobile})`);
|
||||||
if (options.locale)
|
if (options.locale)
|
||||||
lines.push(` .setLocale("${options.locale}")`);
|
lines.push(` .setLocale(${quote(options.locale)})`);
|
||||||
if (options.proxy)
|
if (options.proxy)
|
||||||
lines.push(` .setProxy(new Proxy("${options.proxy.server}"))`);
|
lines.push(` .setProxy(new Proxy(${quote(options.proxy.server)}))`);
|
||||||
if (options.storageState)
|
if (options.storageState)
|
||||||
lines.push(` .setStorageStatePath(Paths.get(${quote(options.storageState as string)}))`);
|
lines.push(` .setStorageStatePath(Paths.get(${quote(options.storageState as string)}))`);
|
||||||
if (options.timezoneId)
|
if (options.timezoneId)
|
||||||
lines.push(` .setTimezoneId("${options.timezoneId}")`);
|
lines.push(` .setTimezoneId(${quote(options.timezoneId)})`);
|
||||||
if (options.userAgent)
|
if (options.userAgent)
|
||||||
lines.push(` .setUserAgent("${options.userAgent}")`);
|
lines.push(` .setUserAgent(${quote(options.userAgent)})`);
|
||||||
if (options.viewport)
|
if (options.viewport)
|
||||||
lines.push(` .setViewportSize(${options.viewport.width}, ${options.viewport.height})`);
|
lines.push(` .setViewportSize(${options.viewport.width}, ${options.viewport.height})`);
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
|
@ -181,7 +181,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateStandaloneFooter(saveStorage: string | undefined): string {
|
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}
|
return `\n // ---------------------${storageStateLine}
|
||||||
await context.close();
|
await context.close();
|
||||||
await browser.close();
|
await browser.close();
|
||||||
@ -228,7 +228,7 @@ function formatContextOptions(options: BrowserContextOptions, deviceName: string
|
|||||||
if (!serializedObject)
|
if (!serializedObject)
|
||||||
serializedObject = '{\n}';
|
serializedObject = '{\n}';
|
||||||
const lines = serializedObject.split('\n');
|
const lines = serializedObject.split('\n');
|
||||||
lines.splice(1, 0, `...devices['${deviceName}'],`);
|
lines.splice(1, 0, `...devices[${quote(deviceName!)}],`);
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ def run(playwright: Playwright) -> None {
|
|||||||
|
|
||||||
generateFooter(saveStorage: string | undefined): string {
|
generateFooter(saveStorage: string | undefined): string {
|
||||||
if (this._isAsync) {
|
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}
|
return `\n # ---------------------${storageStateLine}
|
||||||
await context.close()
|
await context.close()
|
||||||
await browser.close()
|
await browser.close()
|
||||||
@ -174,7 +174,7 @@ async def main() -> None:
|
|||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
const storageStateLine = saveStorage ? `\n context.storage_state(path="${saveStorage}")` : '';
|
const storageStateLine = saveStorage ? `\n context.storage_state(path=${quote(saveStorage)})` : '';
|
||||||
return `\n # ---------------------${storageStateLine}
|
return `\n # ---------------------${storageStateLine}
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
@ -217,7 +217,7 @@ function formatContextOptions(options: BrowserContextOptions, deviceName: string
|
|||||||
const device = deviceName && deviceDescriptors[deviceName];
|
const device = deviceName && deviceDescriptors[deviceName];
|
||||||
if (!device)
|
if (!device)
|
||||||
return formatOptions(options, false);
|
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 {
|
class PythonFormatter {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user