mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03: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') {
|
||||
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');
|
||||
|
@ -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: string
|
||||
if (!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');
|
||||
}
|
||||
|
||||
|
@ -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: string
|
||||
const 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user