diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java index 0b9ec521..9d7d6b6f 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Page.java +++ b/playwright/src/main/java/com/microsoft/playwright/Page.java @@ -92,11 +92,11 @@ public interface Page extends AutoCloseable { * page.evaluate("() => console.log('hello', 5, {foo: 'bar'})"); * } */ - void onConsole(Consumer handler); + void onConsoleMessage(Consumer handler); /** - * Removes handler that was previously added with {@link #onConsole onConsole(handler)}. + * Removes handler that was previously added with {@link #onConsoleMessage onConsoleMessage(handler)}. */ - void offConsole(Consumer handler); + void offConsoleMessage(Consumer handler); /** * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes, diff --git a/playwright/src/main/java/com/microsoft/playwright/Playwright.java b/playwright/src/main/java/com/microsoft/playwright/Playwright.java index 9a6b16c0..a3166375 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Playwright.java +++ b/playwright/src/main/java/com/microsoft/playwright/Playwright.java @@ -61,7 +61,17 @@ public interface Playwright extends AutoCloseable { * Terminates this instance of Playwright, will also close all created browsers if they are still running. */ void close(); - + /** + * Launches new Playwright driver process and connects to it. {@link Playwright#close Playwright.close()} should be called + * when the instance is no longer needed. + *
{@code
+   * Playwright playwright = Playwright.create()) {
+   * Browser browser = playwright.webkit().launch();
+   * Page page = browser.newPage();
+   * page.navigate("https://www.w3.org/");
+   * playwright.close();
+   * }
+ */ static Playwright create() { return PlaywrightImpl.create(); } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java index d647753b..c2b1fed8 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java @@ -262,12 +262,12 @@ public class PageImpl extends ChannelOwner implements Page { } @Override - public void onConsole(Consumer handler) { + public void onConsoleMessage(Consumer handler) { listeners.add(EventType.CONSOLE, handler); } @Override - public void offConsole(Consumer handler) { + public void offConsoleMessage(Consumer handler) { listeners.remove(EventType.CONSOLE, handler); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestClick.java b/playwright/src/test/java/com/microsoft/playwright/TestClick.java index 137b4be0..b6cadf52 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestClick.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestClick.java @@ -140,7 +140,7 @@ public class TestClick extends TestBase { void shouldClickOffscreenButtons() { page.navigate(server.PREFIX + "/offscreenbuttons.html"); List messages = new ArrayList<>(); - page.onConsole(message -> messages.add(message.text())); + page.onConsoleMessage(message -> messages.add(message.text())); for (int i = 0; i < 11; ++i) { // We might've scrolled to click a button - reset to (0, 0). page.evaluate("() => window.scrollTo(0, 0)"); diff --git a/playwright/src/test/java/com/microsoft/playwright/TestGeolocation.java b/playwright/src/test/java/com/microsoft/playwright/TestGeolocation.java index c15de764..24ee706f 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestGeolocation.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestGeolocation.java @@ -110,7 +110,7 @@ public class TestGeolocation extends TestBase { context.grantPermissions(asList("geolocation")); page.navigate(server.EMPTY_PAGE); List messages = new ArrayList<>(); - page.onConsole(message -> messages.add(message.text())); + page.onConsoleMessage(message -> messages.add(message.text())); context.setGeolocation(new Geolocation(0, 0)); page.evaluate("() => {\n" + " navigator.geolocation.watchPosition(pos => {\n" + diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java b/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java index 32a71c3a..85ea374e 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java @@ -264,7 +264,7 @@ public class TestPageBasic extends TestBase { void pagePressShouldWorkForEnter() { page.setContent(""); List messages = new ArrayList<>(); - page.onConsole(message -> messages.add(message)); + page.onConsoleMessage(message -> messages.add(message)); page.press("input", "Enter"); assertEquals("press", messages.get(0).text()); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestWaitForFunction.java b/playwright/src/test/java/com/microsoft/playwright/TestWaitForFunction.java index d6298ee9..a5941daa 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestWaitForFunction.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestWaitForFunction.java @@ -72,7 +72,7 @@ public class TestWaitForFunction extends TestBase { @Test void shouldAvoidSideEffectsAfterTimeout() { int[] counter = { 0 }; - page.onConsole(message -> ++counter[0]); + page.onConsoleMessage(message -> ++counter[0]); try { JSHandle result = page.waitForFunction("() => {\n" + @@ -238,7 +238,7 @@ public class TestWaitForFunction extends TestBase { void shouldNotBeCalledAfterFinishingSuccessfully() { page.navigate(server.EMPTY_PAGE); List messages = new ArrayList<>(); - page.onConsole(msg -> { + page.onConsoleMessage(msg -> { if (msg.text().startsWith("waitForFunction")) { messages.add(msg.text()); } @@ -264,7 +264,7 @@ public class TestWaitForFunction extends TestBase { void shouldNotBeCalledAfterFinishingUnsuccessfully() { page.navigate(server.EMPTY_PAGE); List messages = new ArrayList<>(); - page.onConsole(msg -> { + page.onConsoleMessage(msg -> { if (msg.text().startsWith("waitForFunction")) { messages.add(msg.text()); } diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION index 94d8561e..2c34c074 100644 --- a/scripts/CLI_VERSION +++ b/scripts/CLI_VERSION @@ -1 +1 @@ -1.9.1-1614633211000 +1.9.1-1614654987000 diff --git a/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java b/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java index 83460799..e9b501c6 100644 --- a/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java +++ b/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java @@ -586,7 +586,6 @@ class Method extends Element { private static Map customSignature = new HashMap<>(); static { - customSignature.put("Page.setViewportSize", new String[]{"void setViewportSize(int width, int height);"}); customSignature.put("Playwright.create", new String[]{ "static Playwright create() {", " return PlaywrightImpl.create();", @@ -610,11 +609,11 @@ class Method extends Element { } void writeTo(List output, String offset) { - if (customSignature.containsKey(jsonPath)) { + if ("Playwright.create".equals(jsonPath)) { writeJavadoc(params, output, offset); - for (String line : customSignature.get(jsonPath)) { - output.add(offset + line); - } + output.add(offset + "static Playwright create() {"); + output.add(offset + " return PlaywrightImpl.create();"); + output.add(offset + "}"); return; } int numOverloads = 1; @@ -900,12 +899,6 @@ class Interface extends TypeDefinition { for (Method m : methods) { m.writeTo(output, offset); } - if ("Playwright".equals(jsonName)) { - output.add(""); - output.add(offset + "static Playwright create() {"); - output.add(offset + " return PlaywrightImpl.create();"); - output.add(offset + "}"); - } output.add("}"); output.add("\n"); }