mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 13:45:36 +03:00
fix: update codegen to produce set* instead of with* (#5738)
This commit is contained in:
parent
70beef83d0
commit
976f35aaf7
@ -71,7 +71,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
||||
|
||||
if (signals.waitForNavigation) {
|
||||
code = `
|
||||
// ${pageAlias}.waitForNavigation(new Page.WaitForNavigationOptions().withUrl(${quote(signals.waitForNavigation.url)}), () ->
|
||||
// ${pageAlias}.waitForNavigation(new Page.WaitForNavigationOptions().setUrl(${quote(signals.waitForNavigation.url)}), () ->
|
||||
${pageAlias}.waitForNavigation(() -> {
|
||||
${code}
|
||||
});`;
|
||||
@ -131,7 +131,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
||||
}
|
||||
|
||||
generateFooter(saveStorage: string | undefined): string {
|
||||
const storageStateLine = saveStorage ? `\n context.storageState(new BrowserContext.StorageStateOptions().withPath(${quote(saveStorage)}));` : '';
|
||||
const storageStateLine = saveStorage ? `\n context.storageState(new BrowserContext.StorageStateOptions().setPath(${quote(saveStorage)}));` : '';
|
||||
return `\n // ---------------------${storageStateLine}
|
||||
}
|
||||
}
|
||||
@ -163,7 +163,7 @@ function formatLaunchOptions(options: any): string {
|
||||
return '';
|
||||
lines.push('new BrowserType.LaunchOptions()');
|
||||
if (typeof options.headless === 'boolean')
|
||||
lines.push(` .withHeadless(false)`);
|
||||
lines.push(` .setHeadless(false)`);
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
@ -175,27 +175,27 @@ function formatContextOptions(contextOptions: BrowserContextOptions, deviceName:
|
||||
const options: BrowserContextOptions = { ...device, ...contextOptions };
|
||||
lines.push('new Browser.NewContextOptions()');
|
||||
if (options.colorScheme)
|
||||
lines.push(` .withColorScheme(ColorScheme.${options.colorScheme.toUpperCase()})`);
|
||||
lines.push(` .setColorScheme(ColorScheme.${options.colorScheme.toUpperCase()})`);
|
||||
if (options.geolocation)
|
||||
lines.push(` .withGeolocation(${options.geolocation.latitude}, ${options.geolocation.longitude})`);
|
||||
lines.push(` .setGeolocation(${options.geolocation.latitude}, ${options.geolocation.longitude})`);
|
||||
if (options.locale)
|
||||
lines.push(` .withLocale("${options.locale}")`);
|
||||
lines.push(` .setLocale("${options.locale}")`);
|
||||
if (options.proxy)
|
||||
lines.push(` .withProxy(new Proxy("${options.proxy.server}"))`);
|
||||
lines.push(` .setProxy(new Proxy("${options.proxy.server}"))`);
|
||||
if (options.timezoneId)
|
||||
lines.push(` .withTimezoneId("${options.timezoneId}")`);
|
||||
lines.push(` .setTimezoneId("${options.timezoneId}")`);
|
||||
if (options.userAgent)
|
||||
lines.push(` .withUserAgent("${options.userAgent}")`);
|
||||
lines.push(` .setUserAgent("${options.userAgent}")`);
|
||||
if (options.viewport)
|
||||
lines.push(` .withViewportSize(${options.viewport.width}, ${options.viewport.height})`);
|
||||
lines.push(` .setViewportSize(${options.viewport.width}, ${options.viewport.height})`);
|
||||
if (options.deviceScaleFactor)
|
||||
lines.push(` .withDeviceScaleFactor(${options.deviceScaleFactor})`);
|
||||
lines.push(` .setDeviceScaleFactor(${options.deviceScaleFactor})`);
|
||||
if (options.isMobile)
|
||||
lines.push(` .withIsMobile(${options.isMobile})`);
|
||||
lines.push(` .setIsMobile(${options.isMobile})`);
|
||||
if (options.hasTouch)
|
||||
lines.push(` .withHasTouch(${options.hasTouch})`);
|
||||
lines.push(` .setHasTouch(${options.hasTouch})`);
|
||||
if (options.storageState)
|
||||
lines.push(` .withStorageStatePath(Paths.get(${quote(options.storageState as string)}))`);
|
||||
lines.push(` .setStorageStatePath(Paths.get(${quote(options.storageState as string)}))`);
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ export class JavaScriptFormatter {
|
||||
const extraSpaces = /^(for|while|if|try).*\(.*\)$/.test(previousLine) ? this._baseIndent : '';
|
||||
previousLine = line;
|
||||
|
||||
const callCarryOver = line.startsWith('.with');
|
||||
const callCarryOver = line.startsWith('.set');
|
||||
line = spaces + extraSpaces + (callCarryOver ? this._baseIndent : '') + line;
|
||||
if (line.endsWith('{') || line.endsWith('['))
|
||||
spaces += this._baseIndent;
|
||||
|
@ -552,7 +552,7 @@ await page.ClickAsync(\"text=link\");
|
||||
|
||||
expect(sources.get('<java>').text).toContain(`
|
||||
// Click text=link
|
||||
// page.waitForNavigation(new Page.WaitForNavigationOptions().withUrl("about:blank#foo"), () ->
|
||||
// page.waitForNavigation(new Page.WaitForNavigationOptions().setUrl("about:blank#foo"), () ->
|
||||
page.waitForNavigation(() -> {
|
||||
page.click("text=link");
|
||||
});`);
|
||||
|
@ -31,7 +31,7 @@ public class Example {
|
||||
public static void main(String[] args) {
|
||||
try (Playwright playwright = Playwright.create()) {
|
||||
Browser browser = playwright.${browserName}().launch(new BrowserType.LaunchOptions()
|
||||
.withHeadless(false));
|
||||
.setHeadless(false));
|
||||
BrowserContext context = browser.newContext();`;
|
||||
await cli.waitFor(expectedResult);
|
||||
expect(cli.text()).toContain(expectedResult);
|
||||
@ -40,7 +40,7 @@ public class Example {
|
||||
it('should print the correct context options for custom settings', async ({ runCLI, browserName }) => {
|
||||
const cli = runCLI(['codegen', '--color-scheme=light', '--target=java', emptyHTML]);
|
||||
const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withColorScheme(ColorScheme.LIGHT));`;
|
||||
.setColorScheme(ColorScheme.LIGHT));`;
|
||||
await cli.waitFor(expectedResult);
|
||||
expect(cli.text()).toContain(expectedResult);
|
||||
});
|
||||
@ -48,11 +48,11 @@ it('should print the correct context options for custom settings', async ({ runC
|
||||
it('should print the correct context options when using a device', async ({ runCLI }) => {
|
||||
const cli = runCLI(['codegen', '--device=Pixel 2', '--target=java', emptyHTML]);
|
||||
const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withUserAgent("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36")
|
||||
.withViewportSize(411, 731)
|
||||
.withDeviceScaleFactor(2.625)
|
||||
.withIsMobile(true)
|
||||
.withHasTouch(true));`;
|
||||
.setUserAgent("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36")
|
||||
.setViewportSize(411, 731)
|
||||
.setDeviceScaleFactor(2.625)
|
||||
.setIsMobile(true)
|
||||
.setHasTouch(true));`;
|
||||
await cli.waitFor(expectedResult);
|
||||
expect(cli.text()).toContain(expectedResult);
|
||||
});
|
||||
@ -60,12 +60,12 @@ it('should print the correct context options when using a device', async ({ runC
|
||||
it('should print the correct context options when using a device and additional options', async ({ runCLI }) => {
|
||||
const cli = runCLI(['codegen', '--color-scheme=light', '--device=iPhone 11', '--target=java', emptyHTML]);
|
||||
const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withColorScheme(ColorScheme.LIGHT)
|
||||
.withUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1")
|
||||
.withViewportSize(414, 896)
|
||||
.withDeviceScaleFactor(2)
|
||||
.withIsMobile(true)
|
||||
.withHasTouch(true));`;
|
||||
.setColorScheme(ColorScheme.LIGHT)
|
||||
.setUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1")
|
||||
.setViewportSize(414, 896)
|
||||
.setDeviceScaleFactor(2)
|
||||
.setIsMobile(true)
|
||||
.setHasTouch(true));`;
|
||||
await cli.waitFor(expectedResult);
|
||||
expect(cli.text()).toContain(expectedResult);
|
||||
});
|
||||
@ -76,11 +76,11 @@ it('should print load/save storage_state', async ({ runCLI, browserName, testInf
|
||||
await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');
|
||||
const cli = runCLI(['codegen', `--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=java', emptyHTML]);
|
||||
const expectedResult1 = `BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withStorageStatePath(Paths.get("${loadFileName}")));`;
|
||||
.setStorageStatePath(Paths.get("${loadFileName}")));`;
|
||||
await cli.waitFor(expectedResult1);
|
||||
|
||||
const expectedResult2 = `
|
||||
// ---------------------
|
||||
context.storageState(new BrowserContext.StorageStateOptions().withPath("${saveFileName}"))`;
|
||||
context.storageState(new BrowserContext.StorageStateOptions().setPath("${saveFileName}"))`;
|
||||
await cli.waitFor(expectedResult2);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user