1
0
mirror of synced 2026-05-23 11:13:15 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Yury Semikhatsky b9597657d4 chore: set release version to 1.33.0 (#1272) 2023-05-02 12:37:20 -07:00
45 changed files with 174 additions and 738 deletions
+4 -4
View File
@@ -11,9 +11,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->115.0.5790.24<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->113.0.5672.53<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->113.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox <!-- GEN:firefox-version -->112.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/next/intro/#system-requirements) for details.
@@ -65,7 +65,7 @@ You can find Maven project with the examples [here](./examples).
#### Page screenshot
This code snippet navigates to Playwright homepage in Chromium, Firefox and WebKit, and saves 3 screenshots.
This code snippet navigates to whatsmyuseragent.org in Chromium, Firefox and WebKit, and saves 3 screenshots.
```java
import com.microsoft.playwright.*;
@@ -86,7 +86,7 @@ public class PageScreenshot {
try (Browser browser = browserType.launch()) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
page.navigate("https://playwright.dev/");
page.navigate("http://whatsmyuseragent.org/");
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
</parent>
<artifactId>driver-bundle</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
</parent>
<artifactId>driver</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>org.example</groupId>
<artifactId>examples</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Playwright Client Examples</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -34,7 +34,7 @@ public class PageScreenshot {
try (Browser browser = browserType.launch()) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
page.navigate("https://playwright.dev/");
page.navigate("http://whatsmyuseragent.org/");
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
}
}
@@ -24,7 +24,7 @@ public class WebKitScreenshot {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.webkit().launch();
Page page = browser.newPage();
page.navigate("https://playwright.dev/");
page.navigate("http://whatsmyuseragent.org/");
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("example.png")));
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
</parent>
<artifactId>playwright</artifactId>
@@ -42,7 +42,7 @@ public interface APIRequest {
*/
public String baseURL;
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public Map<String, String> extraHTTPHeaders;
/**
@@ -100,7 +100,7 @@ public interface APIRequest {
return this;
}
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
this.extraHTTPHeaders = extraHTTPHeaders;
@@ -66,7 +66,7 @@ public interface Browser extends AutoCloseable {
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
* corresponding URL. Unset by default. Examples:
* corresponding URL. Examples:
* <ul>
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
* http://localhost:3000/bar.html}</li>
@@ -78,7 +78,7 @@ public interface Browser extends AutoCloseable {
*/
public String baseURL;
/**
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
* Toggles bypassing page's Content-Security-Policy.
*/
public Boolean bypassCSP;
/**
@@ -93,7 +93,7 @@ public interface Browser extends AutoCloseable {
*/
public Double deviceScaleFactor;
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public Map<String, String> extraHTTPHeaders;
/**
@@ -130,9 +130,8 @@ public interface Browser extends AutoCloseable {
public Boolean javaScriptEnabled;
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
* locale. Learn more about emulation in our <a
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public String locale;
/**
@@ -142,11 +141,11 @@ public interface Browser extends AutoCloseable {
public Boolean offline;
/**
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
* BrowserContext.grantPermissions()} for more details. Defaults to none.
* BrowserContext.grantPermissions()} for more details.
*/
public List<String> permissions;
/**
* Network proxy settings to use with this context. Defaults to none.
* Network proxy settings to use with this context.
*
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
@@ -221,14 +220,13 @@ public interface Browser extends AutoCloseable {
/**
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
* the strict mode.
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
*/
public Boolean strictSelectors;
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
* metaZones.txt</a> for a list of supported timezone IDs.
*/
public String timezoneId;
/**
@@ -257,7 +255,7 @@ public interface Browser extends AutoCloseable {
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
* corresponding URL. Unset by default. Examples:
* corresponding URL. Examples:
* <ul>
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
* http://localhost:3000/bar.html}</li>
@@ -272,7 +270,7 @@ public interface Browser extends AutoCloseable {
return this;
}
/**
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
* Toggles bypassing page's Content-Security-Policy.
*/
public NewContextOptions setBypassCSP(boolean bypassCSP) {
this.bypassCSP = bypassCSP;
@@ -296,7 +294,7 @@ public interface Browser extends AutoCloseable {
return this;
}
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
this.extraHTTPHeaders = extraHTTPHeaders;
@@ -367,9 +365,8 @@ public interface Browser extends AutoCloseable {
}
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
* locale. Learn more about emulation in our <a
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public NewContextOptions setLocale(String locale) {
this.locale = locale;
@@ -385,14 +382,14 @@ public interface Browser extends AutoCloseable {
}
/**
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
* BrowserContext.grantPermissions()} for more details. Defaults to none.
* BrowserContext.grantPermissions()} for more details.
*/
public NewContextOptions setPermissions(List<String> permissions) {
this.permissions = permissions;
return this;
}
/**
* Network proxy settings to use with this context. Defaults to none.
* Network proxy settings to use with this context.
*
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
@@ -402,7 +399,7 @@ public interface Browser extends AutoCloseable {
return setProxy(new Proxy(server));
}
/**
* Network proxy settings to use with this context. Defaults to none.
* Network proxy settings to use with this context.
*
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
@@ -535,8 +532,7 @@ public interface Browser extends AutoCloseable {
/**
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
* the strict mode.
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
*/
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
this.strictSelectors = strictSelectors;
@@ -545,7 +541,7 @@ public interface Browser extends AutoCloseable {
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
* metaZones.txt</a> for a list of supported timezone IDs.
*/
public NewContextOptions setTimezoneId(String timezoneId) {
this.timezoneId = timezoneId;
@@ -592,7 +588,7 @@ public interface Browser extends AutoCloseable {
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
* corresponding URL. Unset by default. Examples:
* corresponding URL. Examples:
* <ul>
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
* http://localhost:3000/bar.html}</li>
@@ -604,7 +600,7 @@ public interface Browser extends AutoCloseable {
*/
public String baseURL;
/**
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
* Toggles bypassing page's Content-Security-Policy.
*/
public Boolean bypassCSP;
/**
@@ -619,7 +615,7 @@ public interface Browser extends AutoCloseable {
*/
public Double deviceScaleFactor;
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public Map<String, String> extraHTTPHeaders;
/**
@@ -656,9 +652,8 @@ public interface Browser extends AutoCloseable {
public Boolean javaScriptEnabled;
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
* locale. Learn more about emulation in our <a
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public String locale;
/**
@@ -668,11 +663,11 @@ public interface Browser extends AutoCloseable {
public Boolean offline;
/**
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
* BrowserContext.grantPermissions()} for more details. Defaults to none.
* BrowserContext.grantPermissions()} for more details.
*/
public List<String> permissions;
/**
* Network proxy settings to use with this context. Defaults to none.
* Network proxy settings to use with this context.
*
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
@@ -747,14 +742,13 @@ public interface Browser extends AutoCloseable {
/**
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
* the strict mode.
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
*/
public Boolean strictSelectors;
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
* metaZones.txt</a> for a list of supported timezone IDs.
*/
public String timezoneId;
/**
@@ -783,7 +777,7 @@ public interface Browser extends AutoCloseable {
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
* corresponding URL. Unset by default. Examples:
* corresponding URL. Examples:
* <ul>
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
* http://localhost:3000/bar.html}</li>
@@ -798,7 +792,7 @@ public interface Browser extends AutoCloseable {
return this;
}
/**
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
* Toggles bypassing page's Content-Security-Policy.
*/
public NewPageOptions setBypassCSP(boolean bypassCSP) {
this.bypassCSP = bypassCSP;
@@ -822,7 +816,7 @@ public interface Browser extends AutoCloseable {
return this;
}
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public NewPageOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
this.extraHTTPHeaders = extraHTTPHeaders;
@@ -893,9 +887,8 @@ public interface Browser extends AutoCloseable {
}
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
* locale. Learn more about emulation in our <a
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public NewPageOptions setLocale(String locale) {
this.locale = locale;
@@ -911,14 +904,14 @@ public interface Browser extends AutoCloseable {
}
/**
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
* BrowserContext.grantPermissions()} for more details. Defaults to none.
* BrowserContext.grantPermissions()} for more details.
*/
public NewPageOptions setPermissions(List<String> permissions) {
this.permissions = permissions;
return this;
}
/**
* Network proxy settings to use with this context. Defaults to none.
* Network proxy settings to use with this context.
*
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
@@ -928,7 +921,7 @@ public interface Browser extends AutoCloseable {
return setProxy(new Proxy(server));
}
/**
* Network proxy settings to use with this context. Defaults to none.
* Network proxy settings to use with this context.
*
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
@@ -1061,8 +1054,7 @@ public interface Browser extends AutoCloseable {
/**
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
* the strict mode.
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
*/
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
this.strictSelectors = strictSelectors;
@@ -1071,7 +1063,7 @@ public interface Browser extends AutoCloseable {
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
* metaZones.txt</a> for a list of supported timezone IDs.
*/
public NewPageOptions setTimezoneId(String timezoneId) {
this.timezoneId = timezoneId;
@@ -58,51 +58,6 @@ public interface BrowserContext extends AutoCloseable {
*/
void offClose(Consumer<BrowserContext> handler);
/**
* Emitted when JavaScript within the page calls one of console API methods, e.g. {@code console.log} or {@code
* console.dir}. Also emitted if the page throws an error or a warning.
*
* <p> The arguments passed into {@code console.log} and the page are available on the {@code ConsoleMessage} event handler
* argument.
*
* <p> **Usage**
* <pre>{@code
* context.onConsoleMessage(msg -> {
* for (int i = 0; i < msg.args().size(); ++i)
* System.out.println(i + ": " + msg.args().get(i).jsonValue());
* });
* page.evaluate("() => console.log('hello', 5, { foo: 'bar' })");
* }</pre>
*/
void onConsoleMessage(Consumer<ConsoleMessage> handler);
/**
* Removes handler that was previously added with {@link #onConsoleMessage onConsoleMessage(handler)}.
*/
void offConsoleMessage(Consumer<ConsoleMessage> handler);
/**
* Emitted when a JavaScript dialog appears, such as {@code alert}, {@code prompt}, {@code confirm} or {@code
* beforeunload}. Listener **must** either {@link Dialog#accept Dialog.accept()} or {@link Dialog#dismiss Dialog.dismiss()}
* the dialog - otherwise the page will <a
* href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking">freeze</a> waiting for the
* dialog, and actions like click will never finish.
*
* <p> **Usage**
* <pre>{@code
* context.onDialog(dialog -> {
* dialog.accept();
* });
* }</pre>
*
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} or {@link BrowserContext#onDialog BrowserContext.onDialog()} listeners are
* present, all dialogs are automatically dismissed.
*/
void onDialog(Consumer<Dialog> handler);
/**
* Removes handler that was previously added with {@link #onDialog onDialog(handler)}.
*/
void offDialog(Consumer<Dialog> handler);
/**
* The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
* also fire for popup pages. See also {@link Page#onPopup Page.onPopup()} to receive events about popups relevant to a
@@ -340,33 +295,6 @@ public interface BrowserContext extends AutoCloseable {
return this;
}
}
class WaitForConsoleMessageOptions {
/**
* Receives the {@code ConsoleMessage} object and resolves to truthy value when the waiting should resolve.
*/
public Predicate<ConsoleMessage> predicate;
/**
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
*/
public Double timeout;
/**
* Receives the {@code ConsoleMessage} object and resolves to truthy value when the waiting should resolve.
*/
public WaitForConsoleMessageOptions setPredicate(Predicate<ConsoleMessage> predicate) {
this.predicate = predicate;
return this;
}
/**
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
*/
public WaitForConsoleMessageOptions setTimeout(double timeout) {
this.timeout = timeout;
return this;
}
}
class WaitForPageOptions {
/**
* Receives the {@code Page} object and resolves to truthy value when the waiting should resolve.
@@ -403,9 +331,6 @@ public interface BrowserContext extends AutoCloseable {
* browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
* }</pre>
*
* @param cookies Adds cookies to the browser context.
*
* <p> For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com".
* @since v1.8
*/
void addCookies(List<Cookie> cookies);
@@ -1317,28 +1242,6 @@ public interface BrowserContext extends AutoCloseable {
* @since v1.32
*/
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
/**
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the pages in the context. 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 {@link
* BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
*
* @param callback Callback that performs the action triggering the event.
* @since v1.34
*/
default ConsoleMessage waitForConsoleMessage(Runnable callback) {
return waitForConsoleMessage(null, callback);
}
/**
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the pages in the context. 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 {@link
* BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
*
* @param callback Callback that performs the action triggering the event.
* @since v1.34
*/
ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable callback);
/**
* Performs action and waits for a new {@code Page} to be created in the context. If predicate is provided, it passes
* {@code Page} value into the {@code predicate} function and waits for {@code predicate(event)} to return a truthy value.
@@ -382,7 +382,7 @@ public interface BrowserType {
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
* corresponding URL. Unset by default. Examples:
* corresponding URL. Examples:
* <ul>
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
* http://localhost:3000/bar.html}</li>
@@ -394,7 +394,7 @@ public interface BrowserType {
*/
public String baseURL;
/**
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
* Toggles bypassing page's Content-Security-Policy.
*/
public Boolean bypassCSP;
/**
@@ -440,7 +440,7 @@ public interface BrowserType {
*/
public Path executablePath;
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public Map<String, String> extraHTTPHeaders;
/**
@@ -506,9 +506,8 @@ public interface BrowserType {
public Boolean javaScriptEnabled;
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
* locale. Learn more about emulation in our <a
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public String locale;
/**
@@ -518,7 +517,7 @@ public interface BrowserType {
public Boolean offline;
/**
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
* BrowserContext.grantPermissions()} for more details. Defaults to none.
* BrowserContext.grantPermissions()} for more details.
*/
public List<String> permissions;
/**
@@ -586,8 +585,7 @@ public interface BrowserType {
/**
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
* the strict mode.
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
*/
public Boolean strictSelectors;
/**
@@ -598,7 +596,7 @@ public interface BrowserType {
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
* metaZones.txt</a> for a list of supported timezone IDs.
*/
public String timezoneId;
/**
@@ -639,7 +637,7 @@ public interface BrowserType {
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
* corresponding URL. Unset by default. Examples:
* corresponding URL. Examples:
* <ul>
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
* http://localhost:3000/bar.html}</li>
@@ -654,7 +652,7 @@ public interface BrowserType {
return this;
}
/**
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
* Toggles bypassing page's Content-Security-Policy.
*/
public LaunchPersistentContextOptions setBypassCSP(boolean bypassCSP) {
this.bypassCSP = bypassCSP;
@@ -737,7 +735,7 @@ public interface BrowserType {
return this;
}
/**
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
* An object containing additional HTTP headers to be sent with every request.
*/
public LaunchPersistentContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
this.extraHTTPHeaders = extraHTTPHeaders;
@@ -855,9 +853,8 @@ public interface BrowserType {
}
/**
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
* locale. Learn more about emulation in our <a
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
*/
public LaunchPersistentContextOptions setLocale(String locale) {
this.locale = locale;
@@ -873,7 +870,7 @@ public interface BrowserType {
}
/**
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
* BrowserContext.grantPermissions()} for more details. Defaults to none.
* BrowserContext.grantPermissions()} for more details.
*/
public LaunchPersistentContextOptions setPermissions(List<String> permissions) {
this.permissions = permissions;
@@ -1005,8 +1002,7 @@ public interface BrowserType {
/**
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
* the strict mode.
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
*/
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
this.strictSelectors = strictSelectors;
@@ -1023,7 +1019,7 @@ public interface BrowserType {
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
* metaZones.txt</a> for a list of supported timezone IDs.
*/
public LaunchPersistentContextOptions setTimezoneId(String timezoneId) {
this.timezoneId = timezoneId;
@@ -56,12 +56,6 @@ public interface ConsoleMessage {
* @since v1.8
*/
String location();
/**
* The page that produced this console message, if any.
*
* @since v1.34
*/
Page page();
/**
* The text of the console message.
*
@@ -81,12 +81,6 @@ public interface Dialog {
* @since v1.8
*/
String message();
/**
* The page that initiated this dialog, if available.
*
* @since v1.34
*/
Page page();
/**
* Returns dialog's type, can be one of {@code alert}, {@code beforeunload}, {@code confirm} or {@code prompt}.
*
@@ -602,15 +602,9 @@ public interface ElementHandle extends JSHandle {
public ScreenshotCaret caret;
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
* {@code #FF00FF} that completely covers its bounding box.
*/
public List<Locator> mask;
/**
* Specify the color of the overlay box for masked elements, in <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
* #FF00FF}.
*/
public String maskColor;
/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
* images. Defaults to {@code false}.
@@ -669,21 +663,12 @@ public interface ElementHandle extends JSHandle {
}
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
* {@code #FF00FF} that completely covers its bounding box.
*/
public ScreenshotOptions setMask(List<Locator> mask) {
this.mask = mask;
return this;
}
/**
* Specify the color of the overlay box for masked elements, in <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
* #FF00FF}.
*/
public ScreenshotOptions setMaskColor(String maskColor) {
this.maskColor = maskColor;
return this;
}
/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
* images. Defaults to {@code false}.
@@ -1407,15 +1407,9 @@ public interface Locator {
public ScreenshotCaret caret;
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
* {@code #FF00FF} that completely covers its bounding box.
*/
public List<Locator> mask;
/**
* Specify the color of the overlay box for masked elements, in <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
* #FF00FF}.
*/
public String maskColor;
/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
* images. Defaults to {@code false}.
@@ -1474,21 +1468,12 @@ public interface Locator {
}
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
* {@code #FF00FF} that completely covers its bounding box.
*/
public ScreenshotOptions setMask(List<Locator> mask) {
this.mask = mask;
return this;
}
/**
* Specify the color of the overlay box for masked elements, in <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
* #FF00FF}.
*/
public ScreenshotOptions setMaskColor(String maskColor) {
this.maskColor = maskColor;
return this;
}
/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
* images. Defaults to {@code false}.
@@ -2071,20 +2056,6 @@ public interface Locator {
* @since v1.14
*/
List<String> allTextContents();
/**
* Creates a locator that matches both this locator and the argument locator.
*
* <p> **Usage**
*
* <p> The following example finds a button with a specific title.
* <pre>{@code
* Locator button = page.getByRole(AriaRole.BUTTON).and(page.getByTitle("Subscribe"));
* }</pre>
*
* @param locator Additional locator to match.
* @since v1.34
*/
Locator and(Locator locator);
/**
* Calls <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur">blur</a> on the element.
*
@@ -82,15 +82,15 @@ public interface Page extends AutoCloseable {
* Emitted when JavaScript within the page calls one of console API methods, e.g. {@code console.log} or {@code
* console.dir}. Also emitted if the page throws an error or a warning.
*
* <p> The arguments passed into {@code console.log} are available on the {@code ConsoleMessage} event handler argument.
* <p> The arguments passed into {@code console.log} appear as arguments on the event handler.
*
* <p> **Usage**
* <p> An example of handling {@code console} event:
* <pre>{@code
* page.onConsoleMessage(msg -> {
* for (int i = 0; i < msg.args().size(); ++i)
* System.out.println(i + ": " + msg.args().get(i).jsonValue());
* });
* page.evaluate("() => console.log('hello', 5, { foo: 'bar' })");
* page.evaluate("() => console.log('hello', 5, {foo: 'bar'})");
* }</pre>
*/
void onConsoleMessage(Consumer<ConsoleMessage> handler);
@@ -127,16 +127,13 @@ public interface Page extends AutoCloseable {
* the dialog - otherwise the page will <a
* href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking">freeze</a> waiting for the
* dialog, and actions like click will never finish.
*
* <p> **Usage**
* <pre>{@code
* page.onDialog(dialog -> {
* dialog.accept();
* });
* }</pre>
*
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} or {@link BrowserContext#onDialog BrowserContext.onDialog()} listeners are
* present, all dialogs are automatically dismissed.
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} listeners are present, all dialogs are automatically dismissed.
*/
void onDialog(Consumer<Dialog> handler);
/**
@@ -2397,7 +2394,7 @@ public interface Page extends AutoCloseable {
*/
public ScreenshotCaret caret;
/**
* An object which specifies clipping of the resulting image.
* An object which specifies clipping of the resulting image. Should have the following fields:
*/
public Clip clip;
/**
@@ -2407,15 +2404,9 @@ public interface Page extends AutoCloseable {
public Boolean fullPage;
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
* {@code #FF00FF} that completely covers its bounding box.
*/
public List<Locator> mask;
/**
* Specify the color of the overlay box for masked elements, in <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
* #FF00FF}.
*/
public String maskColor;
/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
* images. Defaults to {@code false}.
@@ -2473,13 +2464,13 @@ public interface Page extends AutoCloseable {
return this;
}
/**
* An object which specifies clipping of the resulting image.
* An object which specifies clipping of the resulting image. Should have the following fields:
*/
public ScreenshotOptions setClip(double x, double y, double width, double height) {
return setClip(new Clip(x, y, width, height));
}
/**
* An object which specifies clipping of the resulting image.
* An object which specifies clipping of the resulting image. Should have the following fields:
*/
public ScreenshotOptions setClip(Clip clip) {
this.clip = clip;
@@ -2495,21 +2486,12 @@ public interface Page extends AutoCloseable {
}
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
* {@code #FF00FF} that completely covers its bounding box.
*/
public ScreenshotOptions setMask(List<Locator> mask) {
this.mask = mask;
return this;
}
/**
* Specify the color of the overlay box for masked elements, in <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
* #FF00FF}.
*/
public ScreenshotOptions setMaskColor(String maskColor) {
this.maskColor = maskColor;
return this;
}
/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
* images. Defaults to {@code false}.
@@ -40,7 +40,7 @@ public interface LocatorAssertions {
class IsAttachedOptions {
public Boolean attached;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
@@ -49,7 +49,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsAttachedOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -59,7 +59,7 @@ public interface LocatorAssertions {
class IsCheckedOptions {
public Boolean checked;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
@@ -68,7 +68,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsCheckedOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -77,12 +77,12 @@ public interface LocatorAssertions {
}
class IsDisabledOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsDisabledOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -92,7 +92,7 @@ public interface LocatorAssertions {
class IsEditableOptions {
public Boolean editable;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
@@ -101,7 +101,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsEditableOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -110,12 +110,12 @@ public interface LocatorAssertions {
}
class IsEmptyOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsEmptyOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -125,7 +125,7 @@ public interface LocatorAssertions {
class IsEnabledOptions {
public Boolean enabled;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
@@ -134,7 +134,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsEnabledOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -143,12 +143,12 @@ public interface LocatorAssertions {
}
class IsFocusedOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsFocusedOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -157,12 +157,12 @@ public interface LocatorAssertions {
}
class IsHiddenOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsHiddenOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -176,7 +176,7 @@ public interface LocatorAssertions {
*/
public Double ratio;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
@@ -189,7 +189,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsInViewportOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -198,13 +198,13 @@ public interface LocatorAssertions {
}
class IsVisibleOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
public Boolean visible;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public IsVisibleOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -222,7 +222,7 @@ public interface LocatorAssertions {
*/
public Boolean ignoreCase;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
@@ -239,7 +239,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public ContainsTextOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -255,12 +255,12 @@ public interface LocatorAssertions {
}
class HasAttributeOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasAttributeOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -269,12 +269,12 @@ public interface LocatorAssertions {
}
class HasClassOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasClassOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -283,12 +283,12 @@ public interface LocatorAssertions {
}
class HasCountOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasCountOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -297,12 +297,12 @@ public interface LocatorAssertions {
}
class HasCSSOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasCSSOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -311,12 +311,12 @@ public interface LocatorAssertions {
}
class HasIdOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasIdOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -325,12 +325,12 @@ public interface LocatorAssertions {
}
class HasJSPropertyOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasJSPropertyOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -344,7 +344,7 @@ public interface LocatorAssertions {
*/
public Boolean ignoreCase;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
@@ -361,7 +361,7 @@ public interface LocatorAssertions {
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasTextOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -377,12 +377,12 @@ public interface LocatorAssertions {
}
class HasValueOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasValueOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -391,12 +391,12 @@ public interface LocatorAssertions {
}
class HasValuesOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasValuesOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -39,12 +39,12 @@ import java.util.regex.Pattern;
public interface PageAssertions {
class HasTitleOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasTitleOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -53,12 +53,12 @@ public interface PageAssertions {
}
class HasURLOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public Double timeout;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
* Time to retry the assertion for.
*/
public HasURLOptions setTimeout(double timeout) {
this.timeout = timeout;
@@ -53,8 +53,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
PageImpl ownerPage;
private static final Map<EventType, String> eventSubscriptions() {
Map<EventType, String> result = new HashMap<>();
result.put(EventType.CONSOLE, "console");
result.put(EventType.DIALOG, "dialog");
result.put(EventType.REQUEST, "request");
result.put(EventType.RESPONSE, "response");
result.put(EventType.REQUESTFINISHED, "requestFinished");
@@ -79,8 +77,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
enum EventType {
CLOSE,
CONSOLE,
DIALOG,
PAGE,
REQUEST,
REQUESTFAILED,
@@ -124,26 +120,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
listeners.remove(EventType.CLOSE, handler);
}
@Override
public void onConsoleMessage(Consumer<ConsoleMessage> handler) {
listeners.add(EventType.CONSOLE, handler);
}
@Override
public void offConsoleMessage(Consumer<ConsoleMessage> handler) {
listeners.remove(EventType.CONSOLE, handler);
}
@Override
public void onDialog(Consumer<Dialog> handler) {
listeners.add(EventType.DIALOG, handler);
}
@Override
public void offDialog(Consumer<Dialog> handler) {
listeners.remove(EventType.DIALOG, handler);
}
@Override
public void onPage(Consumer<Page> handler) {
listeners.add(EventType.PAGE, handler);
@@ -445,10 +421,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
@Override
public void setDefaultNavigationTimeout(double timeout) {
setDefaultNavigationTimeoutImpl(timeout);
}
void setDefaultNavigationTimeoutImpl(Double timeout) {
withLogging("BrowserContext.setDefaultNavigationTimeout", () -> {
timeoutSettings.setDefaultNavigationTimeout(timeout);
JsonObject params = new JsonObject();
@@ -459,10 +431,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
@Override
public void setDefaultTimeout(double timeout) {
setDefaultTimeoutImpl(timeout);
}
void setDefaultTimeoutImpl(Double timeout) {
withLogging("BrowserContext.setDefaultTimeout", () -> {
timeoutSettings.setDefaultTimeout(timeout);
JsonObject params = new JsonObject();
@@ -548,18 +516,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
runUntil(() -> {}, new WaitableRace<>(waitables));
}
@Override
public ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable code) {
return withWaitLogging("BrowserContext.waitForConsoleMessage", logger -> waitForConsoleMessageImpl(options, code));
}
private ConsoleMessage waitForConsoleMessageImpl(WaitForConsoleMessageOptions options, Runnable code) {
if (options == null) {
options = new WaitForConsoleMessageOptions();
}
return waitForEventWithTimeout(EventType.CONSOLE, code, options.predicate, options.timeout);
}
private class WaitableContextClose<R> extends WaitableEvent<EventType, R> {
WaitableContextClose() {
super(BrowserContextImpl.this.listeners, EventType.CLOSE);
@@ -588,7 +544,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
updateInterceptionPatterns();
}
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
route.resume(null, true);
route.resume();
}
}
@@ -598,36 +554,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
@Override
protected void handleEvent(String event, JsonObject params) {
if ("dialog".equals(event)) {
String guid = params.getAsJsonObject("dialog").get("guid").getAsString();
DialogImpl dialog = connection.getExistingObject(guid);
boolean hasListeners = false;
if (listeners.hasListeners(EventType.DIALOG)) {
hasListeners = true;
listeners.notify(EventType.DIALOG, dialog);
}
PageImpl page = dialog.page();
if (page != null) {
if (page.listeners.hasListeners(PageImpl.EventType.DIALOG)) {
hasListeners = true;
page.listeners.notify(PageImpl.EventType.DIALOG, dialog);
}
}
// Although we do similar handling on the server side, we still need this logic
// on the client side due to a possible race condition between two async calls:
// a) removing "dialog" listener subscription (client->server)
// b) actual "dialog" event (server->client)
if (!hasListeners) {
if ("beforeunload".equals(dialog.type())) {
try {
dialog.accept();
} catch (PlaywrightException e) {
}
} else {
dialog.dismiss();
}
}
} else if ("route".equals(event)) {
if ("route".equals(event)) {
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
handleRoute(route);
} else if ("page".equals(event)) {
@@ -643,14 +570,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
if (binding != null) {
bindingCall.call(binding);
}
} else if ("console".equals(event)) {
String guid = params.getAsJsonObject("message").get("guid").getAsString();
ConsoleMessageImpl message = connection.getExistingObject(guid);
listeners.notify(BrowserContextImpl.EventType.CONSOLE, message);
PageImpl page = message.page();
if (page != null) {
page.listeners.notify(PageImpl.EventType.CONSOLE, message);
}
} else if ("request".equals(event)) {
String guid = params.getAsJsonObject("request").get("guid").getAsString();
RequestImpl request = connection.getExistingObject(guid);
@@ -20,7 +20,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.microsoft.playwright.ConsoleMessage;
import com.microsoft.playwright.JSHandle;
import com.microsoft.playwright.Page;
import java.util.ArrayList;
import java.util.List;
@@ -28,16 +27,8 @@ import java.util.List;
import static com.microsoft.playwright.impl.Serialization.gson;
public class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
private PageImpl page;
public ConsoleMessageImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
super(parent, type, guid, initializer);
// Note: currently, we only report console messages for pages and they always have a page.
// However, in the future we might report console messages for service workers or something else,
// where page() would be null.
if (initializer.has("page")) {
page = connection.getExistingObject(initializer.getAsJsonObject("page").get("guid").getAsString());
}
}
public String type() {
@@ -64,9 +55,4 @@ public class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
location.get("lineNumber").getAsNumber() + ":" +
location.get("columnNumber").getAsNumber();
}
@Override
public PageImpl page() {
return page;
}
}
@@ -18,18 +18,10 @@ package com.microsoft.playwright.impl;
import com.google.gson.JsonObject;
import com.microsoft.playwright.Dialog;
import com.microsoft.playwright.Page;
class DialogImpl extends ChannelOwner implements Dialog {
private PageImpl page;
DialogImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
super(parent, type, guid, initializer);
// Note: dialogs that open early during page initialization block it.
// Therefore, we must report the dialog without a page to be able to handle it.
if (initializer.has("page")) {
page = connection.getExistingObject(initializer.getAsJsonObject("page").get("guid").getAsString());
}
}
@Override
@@ -58,11 +50,6 @@ class DialogImpl extends ChannelOwner implements Dialog {
return initializer.get("message").getAsString();
}
@Override
public PageImpl page() {
return page;
}
@Override
public String type() {
return initializer.get("type").getAsString();
@@ -91,14 +91,6 @@ class LocatorImpl implements Locator {
return (List<String>) frame.evalOnSelectorAll(selector, "ee => ee.map(e => e.textContent || '')");
}
@Override
public Locator and(Locator locator) {
LocatorImpl other = (LocatorImpl) locator;
if (other.frame != frame)
throw new Error("Locators must belong to the same frame.");
return new LocatorImpl(frame, selector + " >> internal:and=" + gson().toJson(other.selector), null);
}
@Override
public void blur(BlurOptions options) {
frame.withLogging("Locator.blur", () -> blurImpl(options));
@@ -51,8 +51,6 @@ public class PageImpl extends ChannelOwner implements Page {
private final Set<FrameImpl> frames = new LinkedHashSet<>();
private static final Map<EventType, String> eventSubscriptions() {
Map<EventType, String> result = new HashMap<>();
result.put(EventType.CONSOLE, "console");
result.put(EventType.DIALOG, "dialog");
result.put(EventType.REQUEST, "request");
result.put(EventType.RESPONSE, "response");
result.put(EventType.REQUESTFINISHED, "requestFinished");
@@ -115,7 +113,22 @@ public class PageImpl extends ChannelOwner implements Page {
@Override
protected void handleEvent(String event, JsonObject params) {
if ("worker".equals(event)) {
if ("dialog".equals(event)) {
String guid = params.getAsJsonObject("dialog").get("guid").getAsString();
DialogImpl dialog = connection.getExistingObject(guid);
if (listeners.hasListeners(EventType.DIALOG)) {
listeners.notify(EventType.DIALOG, dialog);
} else {
if ("beforeunload".equals(dialog.type())) {
try {
dialog.accept();
} catch (PlaywrightException e) {
}
} else {
dialog.dismiss();
}
}
} else if ("worker".equals(event)) {
String guid = params.getAsJsonObject("worker").get("guid").getAsString();
WorkerImpl worker = connection.getExistingObject(guid);
worker.page = this;
@@ -125,6 +138,10 @@ public class PageImpl extends ChannelOwner implements Page {
String guid = params.getAsJsonObject("webSocket").get("guid").getAsString();
WebSocketImpl webSocket = connection.getExistingObject(guid);
listeners.notify(EventType.WEBSOCKET, webSocket);
} else if ("console".equals(event)) {
String guid = params.getAsJsonObject("message").get("guid").getAsString();
ConsoleMessageImpl message = connection.getExistingObject(guid);
listeners.notify(EventType.CONSOLE, message);
} else if ("download".equals(event)) {
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
@@ -936,16 +953,7 @@ public class PageImpl extends ChannelOwner implements Page {
@Override
public void pause() {
withLogging("Page.pause", () -> {
Double defaultNavigationTimeout = browserContext.timeoutSettings.defaultNavigationTimeout();
Double defaultTimeout = browserContext.timeoutSettings.defaultTimeout();
browserContext.setDefaultNavigationTimeoutImpl(0.0);
browserContext.setDefaultTimeoutImpl(0.0);
try {
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
} finally {
browserContext.setDefaultNavigationTimeoutImpl(defaultNavigationTimeout);
browserContext.setDefaultTimeoutImpl(defaultTimeout);
}
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
});
}
@@ -955,6 +963,9 @@ public class PageImpl extends ChannelOwner implements Page {
}
private byte[] pdfImpl(PdfOptions options) {
if (!browserContext.browser().isChromium()) {
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
}
if (options == null) {
options = new PdfOptions();
}
@@ -58,13 +58,9 @@ public class RouteImpl extends ChannelOwner implements Route {
@Override
public void resume(ResumeOptions options) {
resume(options, false);
}
void resume(ResumeOptions options, boolean isFallback) {
startHandling();
applyOverrides(convertType(options, FallbackOptions.class));
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume(), isFallback));
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume()));
}
@Override
@@ -75,7 +71,7 @@ public class RouteImpl extends ChannelOwner implements Route {
}
applyOverrides(options);
if (shouldResumeIfFallbackIsCalled) {
resume(null, true);
resume();
}
}
@@ -118,7 +114,7 @@ public class RouteImpl extends ChannelOwner implements Route {
request().applyFallbackOverrides(overrides);
}
private void resumeImpl(RequestImpl.FallbackOverrides options, boolean isFallback) {
private void resumeImpl(RequestImpl.FallbackOverrides options) {
JsonObject params = new JsonObject();
if (options != null) {
if (options.url != null) {
@@ -136,7 +132,6 @@ public class RouteImpl extends ChannelOwner implements Route {
}
}
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
params.addProperty("isFallback", isFallback);
sendMessageAsync("continue", params);
}
@@ -30,18 +30,11 @@ class TimeoutSettings {
this.parent = parent;
}
Double defaultTimeout() {
return defaultTimeout;
}
Double defaultNavigationTimeout() {
return defaultNavigationTimeout;
}
void setDefaultTimeout(Double timeout) {
void setDefaultTimeout(double timeout) {
defaultTimeout = timeout;
}
void setDefaultNavigationTimeout(Double timeout) {
void setDefaultNavigationTimeout(double timeout) {
defaultNavigationTimeout = timeout;
}
@@ -80,4 +73,5 @@ class TimeoutSettings {
}
return new WaitableTimeout<>(timeout(timeout));
}
}
@@ -90,11 +90,6 @@ class UrlMatcher {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UrlMatcher that = (UrlMatcher) o;
if (rawSource instanceof Pattern && that.rawSource instanceof Pattern) {
Pattern a = (Pattern) rawSource;
Pattern b = (Pattern) that.rawSource;
return a.pattern().equals(b.pattern()) && a.flags() == b.flags();
}
return Objects.equals(rawSource, that.rawSource);
}
@@ -162,15 +162,16 @@ class Utils {
static final int maxUplodBufferSize = 50 * 1024 * 1024;
static boolean hasLargeFile(Path[] files) {
int totalSize = 0;
for (Path file: files) {
try {
totalSize += Files.size(file);
if (Files.size(file)> maxUplodBufferSize) {
return true;
}
} catch (IOException e) {
throw new PlaywrightException("Cannot get file size.", e);
}
}
return totalSize > maxUplodBufferSize;
return false;
}
static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
@@ -201,12 +202,10 @@ class Utils {
}
static void checkFilePayloadSize(FilePayload[] files) {
int totalSize = 0;
for (FilePayload file: files) {
totalSize += file.buffer.length;
}
if (totalSize > maxUplodBufferSize) {
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
if (file.buffer.length > maxUplodBufferSize) {
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
}
}
}
@@ -1,159 +0,0 @@
package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
import java.io.OutputStreamWriter;
import java.io.Writer;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestBrowserContextEvents extends TestBase {
@Test
void consoleEventShouldWorkSmoke() {
ConsoleMessage message = context.waitForConsoleMessage(() -> {
page.evaluate("console.log('hello')");
});
assertEquals("hello", message.text());
assertEquals(page, message.page());
}
@Test
void consoleEventShouldWorkInPopup() {
Page[] popup = { null };
ConsoleMessage message = context.waitForConsoleMessage(() -> {
popup[0] = page.waitForPopup(() -> {
page.evaluate("const win = window.open('');\n" +
"win.console.log('hello');\n");
});
});
assertEquals("hello", message.text());
assertEquals(popup[0], message.page());
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="console message from javascript: url is not reported at all")
void consoleEventShouldWorkInPopup2() {
Page[] popup = { null };
ConsoleMessage message = context.waitForConsoleMessage(
new BrowserContext.WaitForConsoleMessageOptions().setPredicate(msg -> "log".equals(msg.type())),
() -> {
popup[0] = context.waitForPage(() -> {
page.evaluate("async () => {\n" +
" const win = window.open('javascript:console.log(\"hello\")');\n" +
" await new Promise(f => setTimeout(f, 0));\n" +
" win.close();\n" +
"}");
});
});
assertEquals("hello", message.text());
assertEquals(popup[0], message.page());
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="console message is not reported at all")
void consoleEventShouldWorkInImmediatelyClosedPopup() {
Page[] popup = { null };
ConsoleMessage message = context.waitForConsoleMessage(() -> {
popup[0] = page.waitForPopup(() -> {
page.evaluate("async () => {\n" +
" const win = window.open();\n" +
" win.console.log('hello');\n" +
" win.close();\n" +
" }\n");
});
});
assertEquals("hello", message.text());
assertEquals(popup[0], message.page());
}
@Test
void dialogEventShouldWorkSmoke() {
Dialog[] dialog = { null };
context.onDialog(d -> {
dialog[0] = d;
dialog[0].accept("hello");
});
Object result = page.evaluate("prompt('hey?')");
assertEquals("hello", result);
context.waitForCondition(() -> dialog[0] != null);
assertEquals("hey?", dialog[0].message());
assertEquals(page, dialog[0].page());
}
@Test
void dialogEventShouldWorkInPopup() {
Dialog[] dialog = { null };
context.onDialog(d -> {
dialog[0] = d;
d.accept("hello");
});
Page popup = page.waitForPopup(() -> {
Object result = page.evaluate("() => {\n" +
" const win = window.open('');\n" +
" return win.prompt('hey?');\n" +
" }");
assertEquals("hello", result);
});
assertEquals("hey?", dialog[0].message());
assertEquals(popup, dialog[0].page());
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="dialog from javascript: url is not reported at all")
void dialogEventShouldWorkInPopup2() {
Dialog[] dialog = { null };
context.onDialog(d -> {
dialog[0] = d;
d.accept("hello");
});
page.evaluate("window.open('javascript:prompt(\"hey?\")');");
context.waitForCondition(() -> dialog[0] != null);
assertEquals("hey?", dialog[0].message());
assertEquals(null, dialog[0].page());
}
@Test
void dialogEventShouldWorkInImmdiatelyClosedPopup() {
Dialog[] dialog = { null };
context.onDialog(d -> {
dialog[0] = d;
d.accept("hello");
});
Page popup = page.waitForPopup(() -> {
Object result = page.evaluate("async () => {\n" +
" const win = window.open();\n" +
" const result = win.prompt('hey?');\n" +
" win.close();\n" +
" return result;\n" +
" }");
assertEquals("hello", result);
});
assertEquals("hey?", dialog[0].message());
assertEquals(popup, dialog[0].page());
}
@Test
void dialogEventShouldWorkWithInlineScriptTag() {
server.setRoute("/popup.html", exchange -> {
exchange.getResponseHeaders().add("content-type", "text/html");
exchange.sendResponseHeaders(200, 0);
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
writer.write("<script>window.result = prompt('hey?')</script>");
}
});
page.navigate(server.EMPTY_PAGE);
page.setContent("<a href='popup.html' target=_blank>Click me</a>");
Dialog[] dialog = { null };
context.onDialog(d -> {
dialog[0] = d;
d.accept("hello");
});
Page popup = context.waitForPage(() -> page.click("a"));
page.waitForCondition(() -> dialog[0] != null);
assertEquals("hey?", dialog[0].message());
assertEquals(popup, dialog[0].page());
page.waitForCondition(() -> "hello".equals(popup.evaluate("window.result")),
new Page.WaitForConditionOptions().setTimeout(5_000));
}
}
@@ -182,19 +182,6 @@ public class TestPageLocatorQuery extends TestBase {
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHasNotText("foo"))).hasCount(2);
}
@Test
void shouldSupportLocatorAnd() {
page.setContent("<div data-testid=foo>hello</div><div data-testid=bar>world</div>\n" +
" <span data-testid=foo>hello2</span><span data-testid=bar>world2</span>");
assertThat(page.locator("div").and(page.locator("div"))).hasCount(2);
assertThat(page.locator("div").and(page.getByTestId("foo"))).hasText(new String[] { "hello" });
assertThat(page.locator("div").and(page.getByTestId("bar"))).hasText(new String[] { "world" });
assertThat(page.getByTestId("foo").and(page.locator("div"))).hasText(new String[] { "hello" });
assertThat(page.getByTestId("bar").and(page.locator("span"))).hasText(new String[] { "world2" });
assertThat(page.locator("span").and(page.getByTestId(Pattern.compile("bar|foo")))).hasCount(2);
}
@Test
void shouldSupportLocatorOr() {
page.setContent("<div>hello</div><span>world</span>");
@@ -82,12 +82,12 @@ public class TestPageRoute extends TestBase {
intercepted.add(4);
route.fallback();
};
page.route(Pattern.compile("empty.html"), handler4);
page.route("**/empty.html", handler4);
page.navigate(server.EMPTY_PAGE);
assertEquals(asList(4, 3, 2, 1), intercepted);
intercepted.clear();
page.unroute(Pattern.compile("empty.html"), handler4);
page.unroute("**/empty.html", handler4);
page.navigate(server.EMPTY_PAGE);
assertEquals(asList(3, 2, 1), intercepted);
@@ -35,7 +35,6 @@ import java.util.Arrays;
import static com.microsoft.playwright.options.ScreenshotAnimations.DISABLED;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
// TODO: suite.skip(browserName === "firefox" && headful");
public class TestPageScreenshot extends TestBase {
@@ -234,19 +233,4 @@ public class TestPageScreenshot extends TestBase {
}
assertTrue(hasDifferentScreenshots);
}
@Test
void shouldWorkWhenMaskColorIsNotPinkF0F() {
page.setViewportSize(500, 500);
page.navigate(server.PREFIX + "/grid.html");
byte[] screenshot1 = page.screenshot(
new Page.ScreenshotOptions()
.setMask(asList(page.locator("div").nth(5)))
.setMaskColor("#00FF00"));
byte[] screenshot2 = page.screenshot(
new Page.ScreenshotOptions()
.setMask(asList(page.locator("div").nth(5))));
assertThrows(AssertionError.class, () -> assertArrayEquals(screenshot1, screenshot2));
}
}
@@ -16,7 +16,6 @@
package com.microsoft.playwright;
import com.microsoft.playwright.options.AriaRole;
import com.microsoft.playwright.options.FilePayload;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
@@ -97,34 +96,6 @@ public class TestPageSetInputFiles extends TestBase {
assertEquals(200 * 1024 * 1024, fields.get(0).content.length());
}
@Test
void shouldUploadMultipleLargeFiles(@TempDir Path tmpDir) throws IOException, ExecutionException, InterruptedException {
Assumptions.assumeTrue(3 <= (Runtime.getRuntime().maxMemory() >> 30), "Fails if max heap size is < 3Gb");
int filesCount = 10;
page.navigate(server.PREFIX + "/input/fileupload-multi.html");
Path uploadFile = tmpDir.resolve("50MB_1.zip");
String str = String.join("", Collections.nCopies(1024, "A"));
try (Writer stream = new OutputStreamWriter(Files.newOutputStream(uploadFile))) {
for (int i = 0; i < 49 * 1024; i++) {
stream.write(str);
}
}
Locator input = page.locator("input[type='file']");
List<Path> uploadFiles = new ArrayList<>();
uploadFiles.add(uploadFile);
for (int i = 1; i < filesCount; i++) {
Path dstFile = tmpDir.resolve("50MB_" + i + ".zip");
Files.copy(uploadFile, dstFile);
uploadFiles.add(dstFile);
}
FileChooser fileChooser = page.waitForFileChooser(() -> input.click());
fileChooser.setFiles(uploadFiles.toArray(new Path[0]));
Object filesLen = page.getByRole(AriaRole.TEXTBOX).evaluate("e => e.files.length");
assertTrue(fileChooser.isMultiple());
assertEquals(filesCount, filesLen);
}
@Test
void shouldUploadLargeFileWithRelativePath(@TempDir Path tmpDir) throws IOException, ExecutionException, InterruptedException {
Assumptions.assumeTrue(3 <= (Runtime.getRuntime().maxMemory() >> 30), "Fails if max heap size is < 3Gb");
@@ -52,18 +52,6 @@ public class TestPdf extends TestBase {
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
void shouldThrowInNonChromium() {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
void correctExceptionWithPersistentContext(@TempDir Path tempDir) {
Path profile = tempDir.resolve("profile");
try (BrowserContext context = browserType.launchPersistentContext(profile)) {
Page page = context.newPage();
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
}
assertTrue(e.getMessage().contains("Page.pdf only supported in headless Chromium"));
}
}
@@ -206,17 +206,6 @@ public class TestSelectorsMisc extends TestBase {
assertEquals(2, page.evalOnSelectorAll("section >> internal:has-not=\"article\"", "els => els.length"));
}
@Test
void shouldWorkWithInternalAnd() {
page.setContent("<div class=foo>hello</div><div class=bar>world</div>\n" +
" <span class=foo>hello2</span><span class=bar>world2</span>");
assertEquals(asList(), page.evalOnSelectorAll("div >> internal:and=\"span\"", "els => els.map(e => e.textContent)"));
assertEquals(asList("hello"), page.evalOnSelectorAll("div >> internal:and=\".foo\"", "els => els.map(e => e.textContent)"));
assertEquals(asList("world"), page.evalOnSelectorAll("div >> internal:and=\".bar\"", "els => els.map(e => e.textContent)"));
assertEquals(asList("hello2", "world2"), page.evalOnSelectorAll("span >> internal:and=\"span\"", "els => els.map(e => e.textContent)"));
assertEquals(asList("hello"), page.evalOnSelectorAll(".foo >> internal:and=\"div\"", "els => els.map(e => e.textContent)"));
assertEquals(asList("world2"), page.evalOnSelectorAll(".bar >> internal:and=\"span\"", "els => els.map(e => e.textContent)"));
}
@Test
void shouldWorkWithInternalOr() {
@@ -16,7 +16,6 @@
package com.microsoft.playwright;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
import org.junit.jupiter.api.condition.EnabledIf;
@@ -29,11 +28,6 @@ import static org.junit.jupiter.api.Assertions.*;
public class TestWorkers extends TestBase {
private int browserMajorVersion() {
String version = browser.version();
return Integer.parseInt(version.split("\\.")[0]);
}
@Test
void pageWorkers() {
Worker worker = page.waitForWorker(() -> page.navigate(server.PREFIX + "/worker/worker.html"));
@@ -151,7 +145,6 @@ public class TestWorkers extends TestBase {
@Test
void shouldReportNetworkActivity() {
Assumptions.assumeFalse(isFirefox() && browserMajorVersion() < 114);
Worker worker = page.waitForWorker(() -> page.navigate(server.PREFIX + "/worker/worker.html"));
String url = server.PREFIX + "/one-style.css";
Request[] request = {null};
@@ -167,7 +160,6 @@ public class TestWorkers extends TestBase {
@Test
void shouldReportNetworkActivityOnWorkerCreation() {
Assumptions.assumeFalse(isFirefox() && browserMajorVersion() < 114);
// Chromium needs waitForDebugger enabled for this one.
page.navigate(server.EMPTY_PAGE);
String url = server.PREFIX + "/one-style.css";
@@ -1,12 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>File upload test</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" multiple name="file1">
<input type="submit">
</form>
</body>
</html>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<packaging>pom</packaging>
<name>Playwright Parent Project</name>
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
+1 -1
View File
@@ -1 +1 @@
1.35.0
1.33.0
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>api-generator</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Playwright - API Generator</name>
<description>
This is an internal module used to generate Java API from the upstream Playwright
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-cli-fatjar</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Test Playwright Command Line FatJar</name>
<properties>
<compiler.version>1.8</compiler.version>
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-cli-version</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Test Playwright Command Line Version</name>
<properties>
<compiler.version>1.8</compiler.version>
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-local-installation</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Test local installation</name>
<description>Runs Playwright test suite (copied from playwright module) against locally cached Playwright</description>
<properties>
+1 -1
View File
@@ -9,7 +9,7 @@
</parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-spring-boot-starter</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Test Playwright With Spring Boot</name>
<properties>
<spring.version>2.4.3</spring.version>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>update-version</artifactId>
<version>1.35.1</version>
<version>1.33.0</version>
<name>Playwright - Update Version in Documentation</name>
<description>
This is an internal module used to update versions in the documentation based on
+1
View File
@@ -47,6 +47,7 @@ JAMMY_TAGS=(
"next"
"next-jammy"
"sha-${GITHUB_SHA}"
"v${PW_VERSION}-jammy"
)
if [[ "$RELEASE_CHANNEL" == "stable" ]]; then