From 399de8e899222140990af8212c2155c6cdf8c87c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 12 Jul 2021 09:35:17 -0700 Subject: [PATCH] feat: roll driver to 07/12, implement new features (#514) --- .../com/microsoft/playwright/Browser.java | 30 +++ .../microsoft/playwright/BrowserContext.java | 12 +- .../com/microsoft/playwright/BrowserType.java | 15 ++ .../com/microsoft/playwright/Download.java | 11 +- .../microsoft/playwright/ElementHandle.java | 50 +++++ .../java/com/microsoft/playwright/Frame.java | 98 +++++----- .../java/com/microsoft/playwright/Page.java | 178 +++++++++++------- .../com/microsoft/playwright/Response.java | 9 + .../playwright/impl/ArtifactImpl.java | 4 + .../playwright/impl/DownloadImpl.java | 4 +- .../playwright/impl/ElementHandleImpl.java | 14 ++ .../microsoft/playwright/impl/FrameImpl.java | 38 ++-- .../microsoft/playwright/impl/PageImpl.java | 14 +- .../playwright/impl/ResponseImpl.java | 28 ++- .../playwright/options/SecurityDetails.java | 43 +++++ .../playwright/options/ServerAddr.java | 26 +++ .../playwright/TestBrowserContextBaseUrl.java | 22 +++ .../microsoft/playwright/TestDownload.java | 39 ++++ .../TestElementHandleConvenience.java | 27 +++ .../com/microsoft/playwright/TestHar.java | 4 + .../playwright/TestNetworkResponse.java | 11 ++ .../microsoft/playwright/TestPageFill.java | 9 + playwright/src/test/resources/dom.html | 2 + scripts/CLI_VERSION | 2 +- .../playwright/tools/ApiGenerator.java | 2 +- 25 files changed, 540 insertions(+), 152 deletions(-) create mode 100644 playwright/src/main/java/com/microsoft/playwright/options/SecurityDetails.java create mode 100644 playwright/src/main/java/com/microsoft/playwright/options/ServerAddr.java create mode 100644 playwright/src/test/java/com/microsoft/playwright/TestBrowserContextBaseUrl.java diff --git a/playwright/src/main/java/com/microsoft/playwright/Browser.java b/playwright/src/main/java/com/microsoft/playwright/Browser.java index a8af906c..af9cd7d4 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Browser.java +++ b/playwright/src/main/java/com/microsoft/playwright/Browser.java @@ -60,6 +60,17 @@ public interface Browser extends AutoCloseable { * Whether to automatically download all the attachments. Defaults to {@code false} where all the downloads are canceled. */ public Boolean acceptDownloads; + /** + * When using {@link Page#goto Page.goto()}, {@link Page#route Page.route()}, {@link Page#waitForURL Page.waitForURL()}, + * {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse Page.waitForResponse()} it takes the + * base URL in consideration by using the {@code URL()} + * constructor for building the corresponding URL. Examples: + * + */ + public String baseURL; /** * Toggles bypassing page's Content-Security-Policy. */ @@ -182,6 +193,10 @@ public interface Browser extends AutoCloseable { this.acceptDownloads = acceptDownloads; return this; } + public NewContextOptions setBaseURL(String baseURL) { + this.baseURL = baseURL; + return this; + } public NewContextOptions setBypassCSP(boolean bypassCSP) { this.bypassCSP = bypassCSP; return this; @@ -306,6 +321,17 @@ public interface Browser extends AutoCloseable { * Whether to automatically download all the attachments. Defaults to {@code false} where all the downloads are canceled. */ public Boolean acceptDownloads; + /** + * When using {@link Page#goto Page.goto()}, {@link Page#route Page.route()}, {@link Page#waitForURL Page.waitForURL()}, + * {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse Page.waitForResponse()} it takes the + * base URL in consideration by using the {@code URL()} + * constructor for building the corresponding URL. Examples: + * + */ + public String baseURL; /** * Toggles bypassing page's Content-Security-Policy. */ @@ -428,6 +454,10 @@ public interface Browser extends AutoCloseable { this.acceptDownloads = acceptDownloads; return this; } + public NewPageOptions setBaseURL(String baseURL) { + this.baseURL = baseURL; + return this; + } public NewPageOptions setBypassCSP(boolean bypassCSP) { this.bypassCSP = bypassCSP; return this; diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java index 804ba882..65f9e77f 100644 --- a/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java +++ b/playwright/src/main/java/com/microsoft/playwright/BrowserContext.java @@ -555,7 +555,9 @@ public interface BrowserContext extends AutoCloseable { * *

NOTE: Enabling routing disables http cache. * - * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing. + * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing. When a {@code baseURL} via the context + * options was provided and the passed URL is a path, it gets merged via the {@code new URL()} constructor. * @param handler handler function to route the request. */ void route(String url, Consumer handler); @@ -599,7 +601,9 @@ public interface BrowserContext extends AutoCloseable { * *

NOTE: Enabling routing disables http cache. * - * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing. + * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing. When a {@code baseURL} via the context + * options was provided and the passed URL is a path, it gets merged via the {@code new URL()} constructor. * @param handler handler function to route the request. */ void route(Pattern url, Consumer handler); @@ -643,7 +647,9 @@ public interface BrowserContext extends AutoCloseable { * *

NOTE: Enabling routing disables http cache. * - * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing. + * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing. When a {@code baseURL} via the context + * options was provided and the passed URL is a path, it gets merged via the {@code new URL()} constructor. * @param handler handler function to route the request. */ void route(Predicate url, Consumer handler); diff --git a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java index 09ebfde4..aaa5cbc5 100644 --- a/playwright/src/main/java/com/microsoft/playwright/BrowserType.java +++ b/playwright/src/main/java/com/microsoft/playwright/BrowserType.java @@ -278,6 +278,17 @@ public interface BrowserType { * href="http://peter.sh/experiments/chromium-command-line-switches/">here. */ public List args; + /** + * When using {@link Page#goto Page.goto()}, {@link Page#route Page.route()}, {@link Page#waitForURL Page.waitForURL()}, + * {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse Page.waitForResponse()} it takes the + * base URL in consideration by using the {@code URL()} + * constructor for building the corresponding URL. Examples: + *

+ */ + public String baseURL; /** * Toggles bypassing page's Content-Security-Policy. */ @@ -461,6 +472,10 @@ public interface BrowserType { this.args = args; return this; } + public LaunchPersistentContextOptions setBaseURL(String baseURL) { + this.baseURL = baseURL; + return this; + } public LaunchPersistentContextOptions setBypassCSP(boolean bypassCSP) { this.bypassCSP = bypassCSP; return this; diff --git a/playwright/src/main/java/com/microsoft/playwright/Download.java b/playwright/src/main/java/com/microsoft/playwright/Download.java index e9e7ba03..589bf1b4 100644 --- a/playwright/src/main/java/com/microsoft/playwright/Download.java +++ b/playwright/src/main/java/com/microsoft/playwright/Download.java @@ -48,12 +48,10 @@ import java.util.*; */ public interface Download { /** - * **Chromium-only** Cancels a download. Will not fail if the download is already finished or canceled. Upon successful - * cancellations, {@code download.failure()} would resolve to {@code "canceled"}. - * - *

Currently **experimental** and may subject to further changes. + * Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations, + * {@code download.failure()} would resolve to {@code "canceled"}. */ - void _cancel(); + void cancel(); /** * Returns readable stream for current download or {@code null} if download failed. */ @@ -73,6 +71,9 @@ public interface Download { /** * Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if * necessary. The method throws when connected remotely. + * + *

Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()} + * to get suggested file name. */ Path path(); /** diff --git a/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java b/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java index e973c3dd..38d3981f 100644 --- a/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java +++ b/playwright/src/main/java/com/microsoft/playwright/ElementHandle.java @@ -269,6 +269,11 @@ public interface ElementHandle extends JSHandle { } } class FillOptions { + /** + * Whether to bypass the actionability checks. Defaults to + * {@code false}. + */ + public Boolean force; /** * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to @@ -282,6 +287,10 @@ public interface ElementHandle extends JSHandle { */ public Double timeout; + public FillOptions setForce(boolean force) { + this.force = force; + return this; + } public FillOptions setNoWaitAfter(boolean noWaitAfter) { this.noWaitAfter = noWaitAfter; return this; @@ -344,6 +353,19 @@ public interface ElementHandle extends JSHandle { return this; } } + class InputValueOptions { + /** + * 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 + * Page.setDefaultTimeout()} methods. + */ + public Double timeout; + + public InputValueOptions setTimeout(double timeout) { + this.timeout = timeout; + return this; + } + } class PressOptions { /** * Time to wait between {@code keydown} and {@code keyup} in milliseconds. Defaults to 0. @@ -437,6 +459,11 @@ public interface ElementHandle extends JSHandle { } } class SelectOptionOptions { + /** + * Whether to bypass the actionability checks. Defaults to + * {@code false}. + */ + public Boolean force; /** * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to @@ -450,6 +477,10 @@ public interface ElementHandle extends JSHandle { */ public Double timeout; + public SelectOptionOptions setForce(boolean force) { + this.force = force; + return this; + } public SelectOptionOptions setNoWaitAfter(boolean noWaitAfter) { this.noWaitAfter = noWaitAfter; return this; @@ -460,6 +491,11 @@ public interface ElementHandle extends JSHandle { } } class SelectTextOptions { + /** + * Whether to bypass the actionability checks. Defaults to + * {@code false}. + */ + public Boolean force; /** * 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 @@ -467,6 +503,10 @@ public interface ElementHandle extends JSHandle { */ public Double timeout; + public SelectTextOptions setForce(boolean force) { + this.force = force; + return this; + } public SelectTextOptions setTimeout(double timeout) { this.timeout = timeout; return this; @@ -1079,6 +1119,16 @@ public interface ElementHandle extends JSHandle { * Returns the {@code element.innerText}. */ String innerText(); + /** + * Returns {@code input.value} for {@code } or {@code diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION index e126ba5f..15e2ae2a 100644 --- a/scripts/CLI_VERSION +++ b/scripts/CLI_VERSION @@ -1 +1 @@ -1.13.0-next-1623789547000 +1.13.0-next-1626084467000 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 23df6b9f..04045c72 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 @@ -866,7 +866,7 @@ class Interface extends TypeDefinition { if ("Playwright".equals(jsonName)) { output.add("import com.microsoft.playwright.impl.PlaywrightImpl;"); } - if (asList("Page", "Request", "FileChooser", "Frame", "ElementHandle", "Browser", "BrowserContext", "BrowserType", "Mouse", "Keyboard").contains(jsonName)) { + if (asList("Page", "Request", "Response", "FileChooser", "Frame", "ElementHandle", "Browser", "BrowserContext", "BrowserType", "Mouse", "Keyboard").contains(jsonName)) { output.add("import com.microsoft.playwright.options.*;"); } if (jsonName.equals("Route")) {