diff --git a/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java b/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java index f18c9381..f14a1689 100644 --- a/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java +++ b/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java @@ -60,6 +60,11 @@ public interface ElementHandle extends JSHandle { * inaccessible pages. Defaults to {@code false}. */ public Boolean noWaitAfter; + /** + * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the + * element. + */ + public Position position; /** * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout @@ -75,6 +80,13 @@ public interface ElementHandle extends JSHandle { this.noWaitAfter = noWaitAfter; return this; } + public CheckOptions setPosition(double x, double y) { + return setPosition(new Position(x, y)); + } + public CheckOptions setPosition(Position position) { + this.position = position; + return this; + } public CheckOptions setTimeout(double timeout) { this.timeout = timeout; return this; @@ -539,6 +551,11 @@ public interface ElementHandle extends JSHandle { * inaccessible pages. Defaults to {@code false}. */ public Boolean noWaitAfter; + /** + * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the + * element. + */ + public Position position; /** * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout @@ -554,6 +571,13 @@ public interface ElementHandle extends JSHandle { this.noWaitAfter = noWaitAfter; return this; } + public UncheckOptions setPosition(double x, double y) { + return setPosition(new Position(x, y)); + } + public UncheckOptions setPosition(Position position) { + this.position = position; + return this; + } public UncheckOptions setTimeout(double timeout) { this.timeout = timeout; return this; diff --git a/playwright/src/main/java/com/microsoft/playwright/Frame.java b/playwright/src/main/java/com/microsoft/playwright/Frame.java index 555367db..1f6446cf 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Frame.java +++ b/playwright/src/main/java/com/microsoft/playwright/Frame.java @@ -137,6 +137,11 @@ public interface Frame { * inaccessible pages. Defaults to {@code false}. */ public Boolean noWaitAfter; + /** + * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the + * element. + */ + public Position position; /** * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout @@ -152,6 +157,13 @@ public interface Frame { this.noWaitAfter = noWaitAfter; return this; } + public CheckOptions setPosition(double x, double y) { + return setPosition(new Position(x, y)); + } + public CheckOptions setPosition(Position position) { + this.position = position; + return this; + } public CheckOptions setTimeout(double timeout) { this.timeout = timeout; return this; @@ -761,6 +773,11 @@ public interface Frame { * inaccessible pages. Defaults to {@code false}. */ public Boolean noWaitAfter; + /** + * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the + * element. + */ + public Position position; /** * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout @@ -776,6 +793,13 @@ public interface Frame { this.noWaitAfter = noWaitAfter; return this; } + public UncheckOptions setPosition(double x, double y) { + return setPosition(new Position(x, y)); + } + public UncheckOptions setPosition(Position position) { + this.position = position; + return this; + } public UncheckOptions setTimeout(double timeout) { this.timeout = timeout; return this; diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java index d20e17ee..0bbddfaf 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Page.java +++ b/playwright/src/main/java/com/microsoft/playwright/Page.java @@ -382,6 +382,11 @@ public interface Page extends AutoCloseable { * inaccessible pages. Defaults to {@code false}. */ public Boolean noWaitAfter; + /** + * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the + * element. + */ + public Position position; /** * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout @@ -397,6 +402,13 @@ public interface Page extends AutoCloseable { this.noWaitAfter = noWaitAfter; return this; } + public CheckOptions setPosition(double x, double y) { + return setPosition(new Position(x, y)); + } + public CheckOptions setPosition(Position position) { + this.position = position; + return this; + } public CheckOptions setTimeout(double timeout) { this.timeout = timeout; return this; @@ -1317,6 +1329,11 @@ public interface Page extends AutoCloseable { * inaccessible pages. Defaults to {@code false}. */ public Boolean noWaitAfter; + /** + * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the + * element. + */ + public Position position; /** * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout @@ -1332,6 +1349,13 @@ public interface Page extends AutoCloseable { this.noWaitAfter = noWaitAfter; return this; } + public UncheckOptions setPosition(double x, double y) { + return setPosition(new Position(x, y)); + } + public UncheckOptions setPosition(Position position) { + this.position = position; + return this; + } public UncheckOptions setTimeout(double timeout) { this.timeout = timeout; return this; @@ -3895,7 +3919,7 @@ public interface Page extends AutoCloseable { */ Page waitForClose(WaitForCloseOptions options, Runnable callback); /** - * Performs action and waits for a [ConoleMessage] to be logged by in the page. If predicate is provided, it passes + * Performs action and waits for a {@code ConsoleMessage} to be logged by in the page. If predicate is provided, it passes * {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code predicate(message)} to return a truthy value. Will * throw an error if the page is closed before the console event is fired. * @@ -3905,7 +3929,7 @@ public interface Page extends AutoCloseable { return waitForConsoleMessage(null, callback); } /** - * Performs action and waits for a [ConoleMessage] to be logged by in the page. If predicate is provided, it passes + * Performs action and waits for a {@code ConsoleMessage} to be logged by in the page. If predicate is provided, it passes * {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code predicate(message)} to return a truthy value. Will * throw an error if the page is closed before the console event is fired. * diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserTypeImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserTypeImpl.java index b8d6da3f..5da9be86 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserTypeImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserTypeImpl.java @@ -63,17 +63,23 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType { } WebSocketTransport transport = new WebSocketTransport(new URI(wsEndpoint), timeout); Connection connection = new Connection(transport); - RemoteBrowser remoteBrowser = (RemoteBrowser) connection.waitForObjectWithKnownName("remoteBrowser"); - PlaywrightImpl playwright = this.connection.getExistingObject("Playwright"); - SelectorsImpl selectors = remoteBrowser.selectors(); - playwright.sharedSelectors.addChannel(selectors); - BrowserImpl browser = remoteBrowser.browser(); + PlaywrightImpl playwright = (PlaywrightImpl) connection.waitForObjectWithKnownName("Playwright"); + if (!playwright.initializer.has("preLaunchedBrowser")) { + try { + connection.close(); + } catch (IOException e) { + e.printStackTrace(System.err); + } + throw new PlaywrightException("Malformed endpoint. Did you use launchServer method?"); + } + playwright.initSharedSelectors(this.connection.getExistingObject("Playwright")); + BrowserImpl browser = connection.getExistingObject(playwright.initializer.getAsJsonObject("preLaunchedBrowser").get("guid").getAsString()); browser.isRemote = true; browser.isConnectedOverWebSocket = true; Consumer connectionCloseListener = t -> browser.notifyRemoteClosed(); transport.onClose(connectionCloseListener); browser.onDisconnected(b -> { - playwright.sharedSelectors.removeChannel(selectors); + playwright.unregisterSelectors(); transport.offClose(connectionCloseListener); try { connection.close(); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java b/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java index 105b1a14..e1990a34 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java @@ -297,9 +297,6 @@ public class Connection { case "Request": result = new RequestImpl(parent, type, guid, initializer); break; - case "RemoteBrowser": - result = new RemoteBrowser(parent, type, guid, initializer); - break; case "Response": result = new ResponseImpl(parent, type, guid, initializer); break; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java index 30552d55..ecb19da5 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java @@ -38,6 +38,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright { Connection connection = new Connection(new PipeTransport(p.getInputStream(), p.getOutputStream())); PlaywrightImpl result = (PlaywrightImpl) connection.waitForObjectWithKnownName("Playwright"); result.driverProcess = p; + result.initSharedSelectors(null); return result; } catch (IOException e) { throw new PlaywrightException("Failed to launch driver", e); @@ -47,15 +48,30 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright { private final BrowserTypeImpl chromium; private final BrowserTypeImpl firefox; private final BrowserTypeImpl webkit; - final SharedSelectors sharedSelectors = new SharedSelectors();; + private final SelectorsImpl selectors; + private SharedSelectors sharedSelectors;; PlaywrightImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) { super(parent, type, guid, initializer); chromium = parent.connection.getExistingObject(initializer.getAsJsonObject("chromium").get("guid").getAsString()); firefox = parent.connection.getExistingObject(initializer.getAsJsonObject("firefox").get("guid").getAsString()); webkit = parent.connection.getExistingObject(initializer.getAsJsonObject("webkit").get("guid").getAsString()); - SelectorsImpl channel = parent.connection.getExistingObject(initializer.getAsJsonObject("selectors").get("guid").getAsString()); - sharedSelectors.addChannel(channel); + + selectors = connection.getExistingObject(initializer.getAsJsonObject("selectors").get("guid").getAsString()); + } + + void initSharedSelectors(PlaywrightImpl parent) { + assert sharedSelectors == null; + if (parent == null) { + sharedSelectors = new SharedSelectors();; + } else { + sharedSelectors = parent.sharedSelectors; + } + sharedSelectors.addChannel(selectors); + } + + void unregisterSelectors() { + sharedSelectors.removeChannel(selectors); } @Override diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION index 63d91aa2..4662e4ef 100644 --- a/scripts/CLI_VERSION +++ b/scripts/CLI_VERSION @@ -1 +1 @@ -1.11.0-next-1617925365000 +1.11.0-next-1618618076000