1
0
mirror of synced 2026-08-06 15:36:54 +00:00

fix: generate helper builder methods for nested types (#294)

This commit is contained in:
Yury Semikhatsky
2021-02-19 14:34:01 -08:00
committed by GitHub
parent ab5cd1c511
commit 99890b57bc
8 changed files with 123 additions and 96 deletions
@@ -158,6 +158,9 @@ public interface Browser extends AutoCloseable {
this.extraHTTPHeaders = extraHTTPHeaders;
return this;
}
public NewContextOptions withGeolocation(double latitude, double longitude) {
return withGeolocation(new Geolocation(latitude, longitude));
}
public NewContextOptions withGeolocation(Geolocation geolocation) {
this.geolocation = geolocation;
return this;
@@ -167,7 +170,10 @@ public interface Browser extends AutoCloseable {
return this;
}
public NewContextOptions withHttpCredentials(String username, String password) {
this.httpCredentials = new HttpCredentials(username, password);
return withHttpCredentials(new HttpCredentials(username, password));
}
public NewContextOptions withHttpCredentials(HttpCredentials httpCredentials) {
this.httpCredentials = httpCredentials;
return this;
}
public NewContextOptions withIgnoreHTTPSErrors(boolean ignoreHTTPSErrors) {
@@ -194,6 +200,9 @@ public interface Browser extends AutoCloseable {
this.permissions = permissions;
return this;
}
public NewContextOptions withProxy(String server) {
return withProxy(new Proxy(server));
}
public NewContextOptions withProxy(Proxy proxy) {
this.proxy = proxy;
return this;
@@ -210,6 +219,9 @@ public interface Browser extends AutoCloseable {
this.recordVideoDir = recordVideoDir;
return this;
}
public NewContextOptions withRecordVideoSize(int width, int height) {
return withRecordVideoSize(new RecordVideoSize(width, height));
}
public NewContextOptions withRecordVideoSize(RecordVideoSize recordVideoSize) {
this.recordVideoSize = recordVideoSize;
return this;
@@ -365,6 +377,9 @@ public interface Browser extends AutoCloseable {
this.extraHTTPHeaders = extraHTTPHeaders;
return this;
}
public NewPageOptions withGeolocation(double latitude, double longitude) {
return withGeolocation(new Geolocation(latitude, longitude));
}
public NewPageOptions withGeolocation(Geolocation geolocation) {
this.geolocation = geolocation;
return this;
@@ -374,7 +389,10 @@ public interface Browser extends AutoCloseable {
return this;
}
public NewPageOptions withHttpCredentials(String username, String password) {
this.httpCredentials = new HttpCredentials(username, password);
return withHttpCredentials(new HttpCredentials(username, password));
}
public NewPageOptions withHttpCredentials(HttpCredentials httpCredentials) {
this.httpCredentials = httpCredentials;
return this;
}
public NewPageOptions withIgnoreHTTPSErrors(boolean ignoreHTTPSErrors) {
@@ -401,6 +419,9 @@ public interface Browser extends AutoCloseable {
this.permissions = permissions;
return this;
}
public NewPageOptions withProxy(String server) {
return withProxy(new Proxy(server));
}
public NewPageOptions withProxy(Proxy proxy) {
this.proxy = proxy;
return this;
@@ -417,6 +438,9 @@ public interface Browser extends AutoCloseable {
this.recordVideoDir = recordVideoDir;
return this;
}
public NewPageOptions withRecordVideoSize(int width, int height) {
return withRecordVideoSize(new RecordVideoSize(width, height));
}
public NewPageOptions withRecordVideoSize(RecordVideoSize recordVideoSize) {
this.recordVideoSize = recordVideoSize;
return this;
@@ -155,6 +155,9 @@ public interface BrowserType {
this.ignoreDefaultArgs = ignoreDefaultArgs;
return this;
}
public LaunchOptions withProxy(String server) {
return withProxy(new Proxy(server));
}
public LaunchOptions withProxy(Proxy proxy) {
this.proxy = proxy;
return this;
@@ -375,6 +378,9 @@ public interface BrowserType {
this.extraHTTPHeaders = extraHTTPHeaders;
return this;
}
public LaunchPersistentContextOptions withGeolocation(double latitude, double longitude) {
return withGeolocation(new Geolocation(latitude, longitude));
}
public LaunchPersistentContextOptions withGeolocation(Geolocation geolocation) {
this.geolocation = geolocation;
return this;
@@ -400,7 +406,10 @@ public interface BrowserType {
return this;
}
public LaunchPersistentContextOptions withHttpCredentials(String username, String password) {
this.httpCredentials = new HttpCredentials(username, password);
return withHttpCredentials(new HttpCredentials(username, password));
}
public LaunchPersistentContextOptions withHttpCredentials(HttpCredentials httpCredentials) {
this.httpCredentials = httpCredentials;
return this;
}
public LaunchPersistentContextOptions withIgnoreAllDefaultArgs(boolean ignoreAllDefaultArgs) {
@@ -435,6 +444,9 @@ public interface BrowserType {
this.permissions = permissions;
return this;
}
public LaunchPersistentContextOptions withProxy(String server) {
return withProxy(new Proxy(server));
}
public LaunchPersistentContextOptions withProxy(Proxy proxy) {
this.proxy = proxy;
return this;
@@ -451,6 +463,9 @@ public interface BrowserType {
this.recordVideoDir = recordVideoDir;
return this;
}
public LaunchPersistentContextOptions withRecordVideoSize(int width, int height) {
return withRecordVideoSize(new RecordVideoSize(width, height));
}
public LaunchPersistentContextOptions withRecordVideoSize(RecordVideoSize recordVideoSize) {
this.recordVideoSize = recordVideoSize;
return this;
@@ -145,13 +145,13 @@ public interface ElementHandle extends JSHandle {
this.noWaitAfter = noWaitAfter;
return this;
}
public ClickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public ClickOptions withPosition(Position position) {
this.position = position;
return this;
}
public ClickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public ClickOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -212,13 +212,13 @@ public interface ElementHandle extends JSHandle {
this.noWaitAfter = noWaitAfter;
return this;
}
public DblclickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public DblclickOptions withPosition(Position position) {
this.position = position;
return this;
}
public DblclickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public DblclickOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -275,13 +275,13 @@ public interface ElementHandle extends JSHandle {
this.modifiers = modifiers;
return this;
}
public HoverOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public HoverOptions withPosition(Position position) {
this.position = position;
return this;
}
public HoverOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public HoverOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -471,6 +471,9 @@ public interface ElementHandle extends JSHandle {
this.noWaitAfter = noWaitAfter;
return this;
}
public TapOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public TapOptions withPosition(Position position) {
this.position = position;
return this;
@@ -192,13 +192,13 @@ public interface Frame {
this.noWaitAfter = noWaitAfter;
return this;
}
public ClickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public ClickOptions withPosition(Position position) {
this.position = position;
return this;
}
public ClickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public ClickOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -259,13 +259,13 @@ public interface Frame {
this.noWaitAfter = noWaitAfter;
return this;
}
public DblclickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public DblclickOptions withPosition(Position position) {
this.position = position;
return this;
}
public DblclickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public DblclickOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -392,13 +392,13 @@ public interface Frame {
this.modifiers = modifiers;
return this;
}
public HoverOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public HoverOptions withPosition(Position position) {
this.position = position;
return this;
}
public HoverOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public HoverOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -638,6 +638,9 @@ public interface Frame {
this.noWaitAfter = noWaitAfter;
return this;
}
public TapOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public TapOptions withPosition(Position position) {
this.position = position;
return this;
@@ -253,13 +253,13 @@ public interface Page extends AutoCloseable {
this.noWaitAfter = noWaitAfter;
return this;
}
public ClickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public ClickOptions withPosition(Position position) {
this.position = position;
return this;
}
public ClickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public ClickOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -332,13 +332,13 @@ public interface Page extends AutoCloseable {
this.noWaitAfter = noWaitAfter;
return this;
}
public DblclickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public DblclickOptions withPosition(Position position) {
this.position = position;
return this;
}
public DblclickOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public DblclickOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -548,13 +548,13 @@ public interface Page extends AutoCloseable {
this.modifiers = modifiers;
return this;
}
public HoverOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public HoverOptions withPosition(Position position) {
this.position = position;
return this;
}
public HoverOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public HoverOptions withTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -861,6 +861,9 @@ public interface Page extends AutoCloseable {
*/
public ScreenshotType type;
public ScreenshotOptions withClip(double x, double y, double width, double height) {
return withClip(new Clip(x, y, width, height));
}
public ScreenshotOptions withClip(Clip clip) {
this.clip = clip;
return this;
@@ -998,6 +1001,9 @@ public interface Page extends AutoCloseable {
this.noWaitAfter = noWaitAfter;
return this;
}
public TapOptions withPosition(double x, double y) {
return withPosition(new Position(x, y));
}
public TapOptions withPosition(Position position) {
this.position = position;
return this;
@@ -41,7 +41,7 @@ public class TestBrowserContextProxy extends TestBase {
void shouldThrowForMissingGlobalProxy() {
Browser browser = browserType.launch(createLaunchOptions());
try {
browser.newContext(new Browser.NewContextOptions().withProxy(new Proxy("localhost:" + server.PORT)));
browser.newContext(new Browser.NewContextOptions().withProxy("localhost:" + server.PORT));
fail("did not throw");
} catch (PlaywrightException e) {
assertTrue(e.getMessage().contains("Browser needs to be launched with the global proxy"));
@@ -62,8 +62,7 @@ public class TestBrowserContextProxy extends TestBase {
writer.write("<html><title>Served by the proxy</title></html>");
}
});
BrowserContext context = browser.newContext(new Browser.NewContextOptions().withProxy(
new Proxy("localhost:" + server.PORT)));
BrowserContext context = browser.newContext(new Browser.NewContextOptions().withProxy("localhost:" + server.PORT));
Page page = context.newPage();
page.navigate("http://non-existent.com/target.html");
assertEquals("Served by the proxy", page.title());
@@ -16,8 +16,6 @@
package com.microsoft.playwright;
import com.microsoft.playwright.options.RecordVideoSize;
import com.microsoft.playwright.options.ViewportSize;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -30,8 +28,8 @@ public class TestScreencast extends TestBase {
@Test
void shouldExposeVideoPath(@TempDir Path videosDir) {
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.withRecordVideoDir(videosDir).withRecordVideoSize(new RecordVideoSize(320, 240))
.withViewportSize(new ViewportSize(320, 240)));
.withRecordVideoDir(videosDir).withRecordVideoSize(320, 240)
.withViewportSize(320, 240));
Page page = context.newPage();
page.evaluate("() => document.body.style.backgroundColor = 'red'");
Path path = page.video().path();