diff --git a/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java b/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java
index 1fdae6de..f9742a69 100644
--- a/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java
+++ b/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java
@@ -26,17 +26,17 @@ import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
-abstract class Element
{
+abstract class Element {
final String jsonName;
final String jsonPath;
final JsonElement jsonElement;
- final P parent;
+ final Element parent;
- Element(P parent, JsonElement jsonElement) {
+ Element(Element parent, JsonElement jsonElement) {
this(parent, false, jsonElement);
}
- Element(P parent, boolean useParentJsonPath, JsonElement jsonElement) {
+ Element(Element parent, boolean useParentJsonPath, JsonElement jsonElement) {
this.parent = parent;
if (jsonElement != null && jsonElement.isJsonObject()) {
this.jsonName = jsonElement.getAsJsonObject().get("name").getAsString();;
@@ -55,11 +55,16 @@ abstract class Element
{
TypeDefinition typeScope() {
return parent.typeScope();
}
+
+ static String toTitle(String name) {
+ return Character.toUpperCase(name.charAt(0)) + name.substring(1);
+ }
}
// Represents return type of a method, type of a method param or type of a field.
class TypeRef extends Element {
String customType;
+ boolean isNestedClass;
TypeRef(Element parent, JsonElement jsonElement) {
super(parent, true, jsonElement);
@@ -100,6 +105,7 @@ class TypeRef extends Element {
typeScope().createEnum(customType, jsonName);
} else if (isClass) {
typeScope().createNestedClass(customType, this, jsonElement.getAsJsonObject());
+ isNestedClass = true;
}
}
@@ -146,14 +152,9 @@ class TypeRef extends Element {
.replace("number", "int")
.replace("null|", "");
}
-
- private static String toTitle(String name) {
- return Character.toUpperCase(name.charAt(0)) + name.substring(1);
- }
}
-abstract class TypeDefinition extends Element {
- final List methods = new ArrayList<>();
+abstract class TypeDefinition extends Element {
final List enums = new ArrayList<>();
final List classes = new ArrayList<>();
@@ -201,13 +202,10 @@ abstract class TypeDefinition extends Element {
for (NestedClass c : classes) {
c.writeTo(output, offset);
}
- for (Method m : methods) {
- m.writeTo(output, offset);
- }
}
}
-class Method extends Element {
+class Method extends Element {
final TypeRef returnType;
final List params = new ArrayList<>();
@@ -252,7 +250,7 @@ class Method extends Element {
}
}
-class Param extends Element {
+class Param extends Element {
final TypeRef type;
Param(Method method, JsonObject jsonElement) {
@@ -265,7 +263,7 @@ class Param extends Element {
}
}
-class Field extends Element {
+class Field extends Element {
final String name;
final TypeRef type;
@@ -275,12 +273,17 @@ class Field extends Element {
this.type = new TypeRef(this, jsonElement.getAsJsonObject().get("type"));
}
+ String toJava() {
+ return type.toJava() + " " + name;
+ }
+
void writeTo(List output, String offset) {
- output.add(offset + type.toJava() + " " + name + ";");
+ output.add(offset + toJava() + ";");
}
}
class Interface extends TypeDefinition {
+ private final List methods = new ArrayList<>();
private static String header = "/**\n" +
" * Copyright (c) Microsoft Corporation.\n" +
" *\n" +
@@ -319,8 +322,11 @@ class Interface extends TypeDefinition {
output.add("import java.util.*;");
output.add("import java.util.function.BiConsumer;");
output.add("");
- output.add("interface " + jsonName + " {");
+ output.add("public interface " + jsonName + " {");
super.writeTo(output, offset + " ");
+ for (Method m : methods) {
+ m.writeTo(output, offset + " ");
+ }
output.add("}");
output.add("\n");
}
@@ -341,13 +347,41 @@ class NestedClass extends TypeDefinition {
}
void writeTo(List output, String offset) {
- output.add(offset + "class " + name + " {");
- super.writeTo(output, offset + " ");
+ String access = parent.typeScope() instanceof NestedClass ? "public " : "";
+ output.add(offset + access + "class " + name + " {");
+ String bodyOffset = offset + " ";
+ super.writeTo(output, bodyOffset);
for (Field f : fields) {
- f.writeTo(output, offset + " ");
+ f.writeTo(output, bodyOffset);
}
+ output.add("");
+ writeBuilderMethods(output, bodyOffset);
output.add(offset + "}");
}
+
+ private void writeBuilderMethods(List output, String bodyOffset) {
+ if (parent.typeScope() instanceof NestedClass) {
+ NestedClass outer = (NestedClass) parent.typeScope();
+ output.add(bodyOffset + name + "() {");
+ output.add(bodyOffset + "}");
+ output.add(bodyOffset + "public " + outer.name + " done() {");
+ output.add(bodyOffset + " return " + outer.name + ".this;");
+ output.add(bodyOffset + "}");
+ output.add("");
+ }
+ for (Field f : fields) {
+ if (f.type.isNestedClass) {
+ output.add(bodyOffset + "public " + f.type.toJava() + " set" + toTitle(f.name) + "() {");
+ output.add(bodyOffset + " this." + f.name + " = new " + f.type.toJava() + "();");
+ output.add(bodyOffset + " return this." + f.name + ";");
+ } else {
+ output.add(bodyOffset + "public " + name + " with" + toTitle(f.name) + "(" + f.toJava() + ") {");
+ output.add(bodyOffset + " this." + f.name + " = " + f.name + ";");
+ output.add(bodyOffset + " return this;");
+ }
+ output.add(bodyOffset + "}");
+ }
+ }
}
class Enum extends TypeDefinition {
diff --git a/lib/src/main/java/com/microsoft/playwright/Accessibility.java b/lib/src/main/java/com/microsoft/playwright/Accessibility.java
index 87cd4910..ac6ed7c5 100644
--- a/lib/src/main/java/com/microsoft/playwright/Accessibility.java
+++ b/lib/src/main/java/com/microsoft/playwright/Accessibility.java
@@ -19,10 +19,19 @@ package com.microsoft.playwright;
import java.util.*;
import java.util.function.BiConsumer;
-interface Accessibility {
+public interface Accessibility {
class SnapshotOptions {
Boolean interestingOnly;
ElementHandle root;
+
+ public SnapshotOptions withInterestingOnly(Boolean interestingOnly) {
+ this.interestingOnly = interestingOnly;
+ return this;
+ }
+ public SnapshotOptions withRoot(ElementHandle root) {
+ this.root = root;
+ return this;
+ }
}
Object snapshot(SnapshotOptions options);
}
diff --git a/lib/src/main/java/com/microsoft/playwright/Browser.java b/lib/src/main/java/com/microsoft/playwright/Browser.java
index 38de336b..c9e6c9ba 100644
--- a/lib/src/main/java/com/microsoft/playwright/Browser.java
+++ b/lib/src/main/java/com/microsoft/playwright/Browser.java
@@ -19,21 +19,70 @@ package com.microsoft.playwright;
import java.util.*;
import java.util.function.BiConsumer;
-interface Browser {
+public interface Browser {
class NewContextOptions {
enum ColorScheme { DARK, LIGHT, NO_PREFERENCE}
- class Geolocation {
+ public class Geolocation {
double latitude;
double longitude;
double accuracy;
+
+ Geolocation() {
+ }
+ public NewContextOptions done() {
+ return NewContextOptions.this;
+ }
+
+ public Geolocation withLatitude(double latitude) {
+ this.latitude = latitude;
+ return this;
+ }
+ public Geolocation withLongitude(double longitude) {
+ this.longitude = longitude;
+ return this;
+ }
+ public Geolocation withAccuracy(double accuracy) {
+ this.accuracy = accuracy;
+ return this;
+ }
}
- class HttpCredentials {
+ public class HttpCredentials {
String username;
String password;
+
+ HttpCredentials() {
+ }
+ public NewContextOptions done() {
+ return NewContextOptions.this;
+ }
+
+ public HttpCredentials withUsername(String username) {
+ this.username = username;
+ return this;
+ }
+ public HttpCredentials withPassword(String password) {
+ this.password = password;
+ return this;
+ }
}
- class VideoSize {
+ public class VideoSize {
int width;
int height;
+
+ VideoSize() {
+ }
+ public NewContextOptions done() {
+ return NewContextOptions.this;
+ }
+
+ public VideoSize withWidth(int width) {
+ this.width = width;
+ return this;
+ }
+ public VideoSize withHeight(int height) {
+ this.height = height;
+ return this;
+ }
}
Boolean acceptDownloads;
Boolean ignoreHTTPSErrors;
@@ -57,21 +106,159 @@ interface Browser {
Boolean recordVideos;
VideoSize videoSize;
Boolean recordTrace;
+
+ public NewContextOptions withAcceptDownloads(Boolean acceptDownloads) {
+ this.acceptDownloads = acceptDownloads;
+ return this;
+ }
+ public NewContextOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
+ this.ignoreHTTPSErrors = ignoreHTTPSErrors;
+ return this;
+ }
+ public NewContextOptions withBypassCSP(Boolean bypassCSP) {
+ this.bypassCSP = bypassCSP;
+ return this;
+ }
+ public NewContextOptions withViewport(Object viewport) {
+ this.viewport = viewport;
+ return this;
+ }
+ public NewContextOptions withUserAgent(String userAgent) {
+ this.userAgent = userAgent;
+ return this;
+ }
+ public NewContextOptions withDeviceScaleFactor(Integer deviceScaleFactor) {
+ this.deviceScaleFactor = deviceScaleFactor;
+ return this;
+ }
+ public NewContextOptions withIsMobile(Boolean isMobile) {
+ this.isMobile = isMobile;
+ return this;
+ }
+ public NewContextOptions withHasTouch(Boolean hasTouch) {
+ this.hasTouch = hasTouch;
+ return this;
+ }
+ public NewContextOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
+ this.javaScriptEnabled = javaScriptEnabled;
+ return this;
+ }
+ public NewContextOptions withTimezoneId(String timezoneId) {
+ this.timezoneId = timezoneId;
+ return this;
+ }
+ public Geolocation setGeolocation() {
+ this.geolocation = new Geolocation();
+ return this.geolocation;
+ }
+ public NewContextOptions withLocale(String locale) {
+ this.locale = locale;
+ return this;
+ }
+ public NewContextOptions withPermissions(List permissions) {
+ this.permissions = permissions;
+ return this;
+ }
+ public NewContextOptions withExtraHTTPHeaders(Map extraHTTPHeaders) {
+ this.extraHTTPHeaders = extraHTTPHeaders;
+ return this;
+ }
+ public NewContextOptions withOffline(Boolean offline) {
+ this.offline = offline;
+ return this;
+ }
+ public HttpCredentials setHttpCredentials() {
+ this.httpCredentials = new HttpCredentials();
+ return this.httpCredentials;
+ }
+ public NewContextOptions withColorScheme(ColorScheme colorScheme) {
+ this.colorScheme = colorScheme;
+ return this;
+ }
+ public NewContextOptions withLogger(Logger logger) {
+ this.logger = logger;
+ return this;
+ }
+ public NewContextOptions withRelativeArtifactsPath(String relativeArtifactsPath) {
+ this.relativeArtifactsPath = relativeArtifactsPath;
+ return this;
+ }
+ public NewContextOptions withRecordVideos(Boolean recordVideos) {
+ this.recordVideos = recordVideos;
+ return this;
+ }
+ public VideoSize setVideoSize() {
+ this.videoSize = new VideoSize();
+ return this.videoSize;
+ }
+ public NewContextOptions withRecordTrace(Boolean recordTrace) {
+ this.recordTrace = recordTrace;
+ return this;
+ }
}
class NewPageOptions {
enum ColorScheme { DARK, LIGHT, NO_PREFERENCE}
- class Geolocation {
+ public class Geolocation {
double latitude;
double longitude;
double accuracy;
+
+ Geolocation() {
+ }
+ public NewPageOptions done() {
+ return NewPageOptions.this;
+ }
+
+ public Geolocation withLatitude(double latitude) {
+ this.latitude = latitude;
+ return this;
+ }
+ public Geolocation withLongitude(double longitude) {
+ this.longitude = longitude;
+ return this;
+ }
+ public Geolocation withAccuracy(double accuracy) {
+ this.accuracy = accuracy;
+ return this;
+ }
}
- class HttpCredentials {
+ public class HttpCredentials {
String username;
String password;
+
+ HttpCredentials() {
+ }
+ public NewPageOptions done() {
+ return NewPageOptions.this;
+ }
+
+ public HttpCredentials withUsername(String username) {
+ this.username = username;
+ return this;
+ }
+ public HttpCredentials withPassword(String password) {
+ this.password = password;
+ return this;
+ }
}
- class VideoSize {
+ public class VideoSize {
int width;
int height;
+
+ VideoSize() {
+ }
+ public NewPageOptions done() {
+ return NewPageOptions.this;
+ }
+
+ public VideoSize withWidth(int width) {
+ this.width = width;
+ return this;
+ }
+ public VideoSize withHeight(int height) {
+ this.height = height;
+ return this;
+ }
}
Boolean acceptDownloads;
Boolean ignoreHTTPSErrors;
@@ -95,6 +282,95 @@ interface Browser {
Boolean recordVideos;
VideoSize videoSize;
Boolean recordTrace;
+
+ public NewPageOptions withAcceptDownloads(Boolean acceptDownloads) {
+ this.acceptDownloads = acceptDownloads;
+ return this;
+ }
+ public NewPageOptions withIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
+ this.ignoreHTTPSErrors = ignoreHTTPSErrors;
+ return this;
+ }
+ public NewPageOptions withBypassCSP(Boolean bypassCSP) {
+ this.bypassCSP = bypassCSP;
+ return this;
+ }
+ public NewPageOptions withViewport(Object viewport) {
+ this.viewport = viewport;
+ return this;
+ }
+ public NewPageOptions withUserAgent(String userAgent) {
+ this.userAgent = userAgent;
+ return this;
+ }
+ public NewPageOptions withDeviceScaleFactor(Integer deviceScaleFactor) {
+ this.deviceScaleFactor = deviceScaleFactor;
+ return this;
+ }
+ public NewPageOptions withIsMobile(Boolean isMobile) {
+ this.isMobile = isMobile;
+ return this;
+ }
+ public NewPageOptions withHasTouch(Boolean hasTouch) {
+ this.hasTouch = hasTouch;
+ return this;
+ }
+ public NewPageOptions withJavaScriptEnabled(Boolean javaScriptEnabled) {
+ this.javaScriptEnabled = javaScriptEnabled;
+ return this;
+ }
+ public NewPageOptions withTimezoneId(String timezoneId) {
+ this.timezoneId = timezoneId;
+ return this;
+ }
+ public Geolocation setGeolocation() {
+ this.geolocation = new Geolocation();
+ return this.geolocation;
+ }
+ public NewPageOptions withLocale(String locale) {
+ this.locale = locale;
+ return this;
+ }
+ public NewPageOptions withPermissions(List permissions) {
+ this.permissions = permissions;
+ return this;
+ }
+ public NewPageOptions withExtraHTTPHeaders(Map extraHTTPHeaders) {
+ this.extraHTTPHeaders = extraHTTPHeaders;
+ return this;
+ }
+ public NewPageOptions withOffline(Boolean offline) {
+ this.offline = offline;
+ return this;
+ }
+ public HttpCredentials setHttpCredentials() {
+ this.httpCredentials = new HttpCredentials();
+ return this.httpCredentials;
+ }
+ public NewPageOptions withColorScheme(ColorScheme colorScheme) {
+ this.colorScheme = colorScheme;
+ return this;
+ }
+ public NewPageOptions withLogger(Logger logger) {
+ this.logger = logger;
+ return this;
+ }
+ public NewPageOptions withRelativeArtifactsPath(String relativeArtifactsPath) {
+ this.relativeArtifactsPath = relativeArtifactsPath;
+ return this;
+ }
+ public NewPageOptions withRecordVideos(Boolean recordVideos) {
+ this.recordVideos = recordVideos;
+ return this;
+ }
+ public VideoSize setVideoSize() {
+ this.videoSize = new VideoSize();
+ return this.videoSize;
+ }
+ public NewPageOptions withRecordTrace(Boolean recordTrace) {
+ this.recordTrace = recordTrace;
+ return this;
+ }
}
void close();
List contexts();
diff --git a/lib/src/main/java/com/microsoft/playwright/BrowserContext.java b/lib/src/main/java/com/microsoft/playwright/BrowserContext.java
index edf795c0..90560dc9 100644
--- a/lib/src/main/java/com/microsoft/playwright/BrowserContext.java
+++ b/lib/src/main/java/com/microsoft/playwright/BrowserContext.java
@@ -19,9 +19,14 @@ package com.microsoft.playwright;
import java.util.*;
import java.util.function.BiConsumer;
-interface BrowserContext {
+public interface BrowserContext {
class GrantPermissionsOptions {
String origin;
+
+ public GrantPermissionsOptions withOrigin(String origin) {
+ this.origin = origin;
+ return this;
+ }
}
void close();
void addCookies(List