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

Compare commits

..

18 Commits

Author SHA1 Message Date
Yury Semikhatsky 82260585ce chore: roll 1.41.2 driver, mark 1.41.2 (#1471) 2024-02-01 16:42:13 -08:00
Yury Semikhatsky bae57eec02 cherry-pick(#1469): fix: put file payloads into "payloads" protocol f… (#1470)
Reference https://github.com/microsoft/playwright-java/issues/1468
2024-02-01 12:20:31 -08:00
Yury Semikhatsky fd0c9ca398 chore: set version to 1.41.1 (#1463) 2024-01-25 13:08:40 -08:00
Yury Semikhatsky ae3cfc9e91 chore: roll driver 1.41.1 (#1462) 2024-01-25 12:50:45 -08:00
Yury Semikhatsky 8ed802234d chore: mark 1.41.0 (#1453) 2024-01-17 15:57:30 -08:00
Yury Semikhatsky eefb9b68ff chore(1.41): Revert "feat(junit-playwright) (#1412)" (#1452)
Revert "feat(junit-playwright) (#1412)"

This reverts commit f28ca44fa0.
2024-01-17 15:37:59 -08:00
Yury Semikhatsky bc2857053c chore: roll driver 1.41.0 (#1450) 2024-01-17 11:26:02 -08:00
Yury Semikhatsky 7e6f98c903 chore: roll driver to 1.41 beta (#1449) 2024-01-17 08:55:22 -08:00
Yury Semikhatsky e889b20fda chore: roll driver to 1.41.0-alpha (#1443) 2023-12-18 16:01:35 -08:00
uchagani f28ca44fa0 feat(junit-playwright) (#1412) 2023-12-04 17:32:59 -08:00
Yury Semikhatsky d73f953e68 chore: mark 1.41 dev version (#1428) 2023-11-20 11:03:13 -08:00
Yury Semikhatsky cc28516281 chore: mark version 1.40.0 (#1427) 2023-11-20 10:57:07 -08:00
Yury Semikhatsky d91c93bed1 chore: roll 1.40.0 (#1426) 2023-11-20 10:19:23 -08:00
Yury Semikhatsky 2b45615e14 chore: roll driver to 1.40.0-beta-1700102862000 (#1424) 2023-11-16 10:16:15 -08:00
Max Schmitt d6f6448b1d chore: fix Ubuntu 22.04 WebKit on 20.04 host (#1423) 2023-11-15 19:54:37 +01:00
Yury Semikhatsky 5d9f76f4c5 chore: roll driver to 11/14/23, revert expect change (#1422) 2023-11-14 12:01:12 -08:00
Yury Semikhatsky 38f3dd3f5a chore: roll driver to 1.40.0-alpha-nov-13-2023 (#1420) 2023-11-14 10:24:07 -08:00
Yury Semikhatsky 4efb792c36 chore: set dev version to 1.40 (#1411) 2023-10-13 14:02:10 -07:00
64 changed files with 931 additions and 220 deletions
+2 -2
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 -->119.0.6045.9<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->121.0.6167.57<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->118.0.1<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox <!-- GEN:firefox-version -->121.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/intro#system-requirements) for details.
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.39.0</version>
<version>1.41.2</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.39.0</version>
<version>1.41.2</version>
</parent>
<artifactId>driver</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>org.example</groupId>
<artifactId>examples</artifactId>
<version>1.39.0</version>
<version>1.41.2</version>
<name>Playwright Client Examples</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.39.0</version>
<version>1.41.2</version>
</parent>
<artifactId>playwright</artifactId>
@@ -80,8 +80,8 @@ public interface APIRequestContext {
APIResponse delete(String url, RequestOptions params);
/**
* All responses returned by {@link APIRequestContext#get APIRequestContext.get()} and similar methods are stored in the
* memory, so that you can later call {@link APIResponse#body APIResponse.body()}. This method discards all stored
* responses, and makes {@link APIResponse#body APIResponse.body()} throw "Response disposed" error.
* memory, so that you can later call {@link APIResponse#body APIResponse.body()}.This method discards all its resources,
* calling any method on disposed {@code APIRequestContext} will throw an exception.
*
* @since v1.16
*/
@@ -56,6 +56,20 @@ public interface Browser extends AutoCloseable {
*/
void offDisconnected(Consumer<Browser> handler);
class CloseOptions {
/**
* The reason to be reported to the operations interrupted by the browser closure.
*/
public String reason;
/**
* The reason to be reported to the operations interrupted by the browser closure.
*/
public CloseOptions setReason(String reason) {
this.reason = reason;
return this;
}
}
class NewContextOptions {
/**
* Whether to automatically download all the attachments. Defaults to {@code true} where all the downloads are accepted.
@@ -1165,7 +1179,25 @@ public interface Browser extends AutoCloseable {
*
* @since v1.8
*/
void close();
default void close() {
close(null);
}
/**
* In case this browser is obtained using {@link BrowserType#launch BrowserType.launch()}, closes the browser and all of
* its pages (if any were opened).
*
* <p> In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
* browser server.
*
* <p> <strong>NOTE:</strong> This is similar to force quitting the browser. Therefore, you should call {@link BrowserContext#close
* BrowserContext.close()} on any {@code BrowserContext}'s you explicitly created earlier with {@link Browser#newContext
* Browser.newContext()} **before** calling {@link Browser#close Browser.close()}.
*
* <p> The {@code Browser} object itself is considered to be disposed and cannot be used anymore.
*
* @since v1.8
*/
void close(CloseOptions options);
/**
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
*
@@ -186,6 +186,20 @@ public interface BrowserContext extends AutoCloseable {
*/
void offResponse(Consumer<Response> handler);
class CloseOptions {
/**
* The reason to be reported to the operations interrupted by the context closure.
*/
public String reason;
/**
* The reason to be reported to the operations interrupted by the context closure.
*/
public CloseOptions setReason(String reason) {
this.reason = reason;
return this;
}
}
class ExposeBindingOptions {
/**
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
@@ -504,7 +518,17 @@ public interface BrowserContext extends AutoCloseable {
*
* @since v1.8
*/
void close();
default void close() {
close(null);
}
/**
* Closes the browser context. All the pages that belong to the browser context will be closed.
*
* <p> <strong>NOTE:</strong> The default browser context cannot be closed.
*
* @since v1.8
*/
void close(CloseOptions options);
/**
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
* are returned.
@@ -1236,6 +1260,13 @@ public interface BrowserContext extends AutoCloseable {
* @since v1.12
*/
Tracing tracing();
/**
* Removes all routes created with {@link BrowserContext#route BrowserContext.route()} and {@link
* BrowserContext#routeFromHAR BrowserContext.routeFromHAR()}.
*
* @since v1.41
*/
void unrouteAll();
/**
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
* removes all routes for the {@code url}.
@@ -165,8 +165,10 @@ public interface BrowserType {
}
class LaunchOptions {
/**
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
*
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
*/
public List<String> args;
/**
@@ -253,8 +255,10 @@ public interface BrowserType {
public Path tracesDir;
/**
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
*
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
*/
public LaunchOptions setArgs(List<String> args) {
this.args = args;
@@ -416,8 +420,10 @@ public interface BrowserType {
*/
public Boolean acceptDownloads;
/**
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
*
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
*/
public List<String> args;
/**
@@ -486,6 +492,11 @@ public interface BrowserType {
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
*/
public Map<String, String> extraHTTPHeaders;
/**
* Firefox user preferences. Learn more about the Firefox user preferences at <a
* href="https://support.mozilla.org/en-US/kb/about-config-editor-firefox">{@code about:config}</a>.
*/
public Map<String, Object> firefoxUserPrefs;
/**
* Emulates {@code "forced-colors"} media feature, supported values are {@code "active"}, {@code "none"}. See {@link
* Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
@@ -670,8 +681,10 @@ public interface BrowserType {
return this;
}
/**
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
*
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
*/
public LaunchPersistentContextOptions setArgs(List<String> args) {
this.args = args;
@@ -786,6 +799,14 @@ public interface BrowserType {
this.extraHTTPHeaders = extraHTTPHeaders;
return this;
}
/**
* Firefox user preferences. Learn more about the Firefox user preferences at <a
* href="https://support.mozilla.org/en-US/kb/about-config-editor-firefox">{@code about:config}</a>.
*/
public LaunchPersistentContextOptions setFirefoxUserPrefs(Map<String, Object> firefoxUserPrefs) {
this.firefoxUserPrefs = firefoxUserPrefs;
return this;
}
/**
* Emulates {@code "forced-colors"} media feature, supported values are {@code "active"}, {@code "none"}. See {@link
* Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
@@ -45,7 +45,7 @@ public interface Download {
*/
void cancel();
/**
* Returns readable stream for current download or {@code null} if download failed.
* Returns a readable stream for a successful download, or throws for a failed/canceled download.
*
* @since v1.8
*/
@@ -69,8 +69,8 @@ public interface Download {
*/
Page page();
/**
* 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.
* Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will
* wait for the download to finish if necessary. The method throws when connected remotely.
*
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()}
* to get suggested file name.
@@ -634,6 +634,12 @@ public interface ElementHandle extends JSHandle {
* <p> Defaults to {@code "device"}.
*/
public ScreenshotScale scale;
/**
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
* and applies to the inner frames.
*/
public String style;
/**
* Maximum time 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()} or {@link
@@ -719,6 +725,15 @@ public interface ElementHandle extends JSHandle {
this.scale = scale;
return this;
}
/**
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
* and applies to the inner frames.
*/
public ScreenshotOptions setStyle(String style) {
this.style = style;
return this;
}
/**
* Maximum time 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()} or {@link
@@ -1411,13 +1426,17 @@ public interface ElementHandle extends JSHandle {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -1451,13 +1470,17 @@ public interface ElementHandle extends JSHandle {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -2523,8 +2546,7 @@ public interface ElementHandle extends JSHandle {
* <li> {@code "visible"} Wait until the element is <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.</li>
* <li> {@code "hidden"} Wait until the element is <a href="https://playwright.dev/java/docs/actionability#visible">not
* visible</a> or <a href="https://playwright.dev/java/docs/actionability#attached">not attached</a>. Note that waiting for
* hidden does not throw when the element detaches.</li>
* visible</a> or not attached. Note that waiting for hidden does not throw when the element detaches.</li>
* <li> {@code "stable"} Wait until the element is both <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> and <a
* href="https://playwright.dev/java/docs/actionability#stable">stable</a>.</li>
@@ -2554,8 +2576,7 @@ public interface ElementHandle extends JSHandle {
* <li> {@code "visible"} Wait until the element is <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.</li>
* <li> {@code "hidden"} Wait until the element is <a href="https://playwright.dev/java/docs/actionability#visible">not
* visible</a> or <a href="https://playwright.dev/java/docs/actionability#attached">not attached</a>. Note that waiting for
* hidden does not throw when the element detaches.</li>
* visible</a> or not attached. Note that waiting for hidden does not throw when the element detaches.</li>
* <li> {@code "stable"} Wait until the element is both <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> and <a
* href="https://playwright.dev/java/docs/actionability#stable">stable</a>.</li>
@@ -1470,8 +1470,14 @@ public interface Frame {
}
class LocatorOptions {
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1497,8 +1503,14 @@ public interface Frame {
public Object hasText;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -2582,13 +2594,17 @@ public interface Frame {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -2624,13 +2640,17 @@ public interface Frame {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -2665,13 +2685,17 @@ public interface Frame {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -285,8 +285,14 @@ public interface FrameLocator {
}
class LocatorOptions {
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -312,8 +318,14 @@ public interface FrameLocator {
public Object hasText;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -656,8 +656,14 @@ public interface Locator {
}
class FilterOptions {
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -683,8 +689,14 @@ public interface Locator {
public Object hasText;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1262,8 +1274,14 @@ public interface Locator {
}
class LocatorOptions {
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1289,8 +1307,14 @@ public interface Locator {
public Object hasText;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1483,6 +1507,12 @@ public interface Locator {
* <p> Defaults to {@code "device"}.
*/
public ScreenshotScale scale;
/**
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
* and applies to the inner frames.
*/
public String style;
/**
* Maximum time 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()} or {@link
@@ -1568,6 +1598,15 @@ public interface Locator {
this.scale = scale;
return this;
}
/**
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
* and applies to the inner frames.
*/
public ScreenshotOptions setStyle(String style) {
this.style = style;
return this;
}
/**
* Maximum time 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()} or {@link
@@ -2471,13 +2510,17 @@ public interface Locator {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -2516,13 +2559,17 @@ public interface Locator {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -2560,13 +2607,17 @@ public interface Locator {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -650,12 +650,23 @@ public interface Page extends AutoCloseable {
}
}
class CloseOptions {
/**
* The reason to be reported to the operations interrupted by the page closure.
*/
public String reason;
/**
* Defaults to {@code false}. Whether to run the <a
* href="https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload">before unload</a> page handlers.
*/
public Boolean runBeforeUnload;
/**
* The reason to be reported to the operations interrupted by the page closure.
*/
public CloseOptions setReason(String reason) {
this.reason = reason;
return this;
}
/**
* Defaults to {@code false}. Whether to run the <a
* href="https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload">before unload</a> page handlers.
@@ -1913,8 +1924,14 @@ public interface Page extends AutoCloseable {
}
class LocatorOptions {
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1940,8 +1957,14 @@ public interface Page extends AutoCloseable {
public Object hasText;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
*
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
* document root. For example, you can find {@code content} that has {@code div} in {@code
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
* content}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -2439,6 +2462,12 @@ public interface Page extends AutoCloseable {
* <p> Defaults to {@code "device"}.
*/
public ScreenshotScale scale;
/**
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
* and applies to the inner frames.
*/
public String style;
/**
* Maximum time 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()} or {@link
@@ -2545,6 +2574,15 @@ public interface Page extends AutoCloseable {
this.scale = scale;
return this;
}
/**
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
* and applies to the inner frames.
*/
public ScreenshotOptions setStyle(String style) {
this.style = style;
return this;
}
/**
* Maximum time 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()} or {@link
@@ -3858,13 +3896,17 @@ public interface Page extends AutoCloseable {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -3900,13 +3942,17 @@ public interface Page extends AutoCloseable {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -3941,13 +3987,17 @@ public interface Page extends AutoCloseable {
*
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
* <ul>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
* <li> <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
* </ul>
*
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
@@ -7007,6 +7057,12 @@ public interface Page extends AutoCloseable {
* @since v1.8
*/
void uncheck(String selector, UncheckOptions options);
/**
* Removes all routes created with {@link Page#route Page.route()} and {@link Page#routeFromHAR Page.routeFromHAR()}.
*
* @since v1.41
*/
void unrouteAll();
/**
* Removes a route created with {@link Page#route Page.route()}. When {@code handler} is not specified, removes all routes
* for the {@code url}.
@@ -38,8 +38,9 @@ import java.nio.file.Path;
public interface Tracing {
class StartOptions {
/**
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
* specified in {@link BrowserType#launch BrowserType.launch()}.
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
* name, you need to pass {@code path} option to {@link Tracing#stop Tracing.stop()} instead.
*/
public String name;
/**
@@ -66,8 +67,9 @@ public interface Tracing {
public String title;
/**
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
* specified in {@link BrowserType#launch BrowserType.launch()}.
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
* name, you need to pass {@code path} option to {@link Tracing#stop Tracing.stop()} instead.
*/
public StartOptions setName(String name) {
this.name = name;
@@ -110,8 +112,9 @@ public interface Tracing {
}
class StartChunkOptions {
/**
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
* specified in {@link BrowserType#launch BrowserType.launch()}.
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
* name, you need to pass {@code path} option to {@link Tracing#stopChunk Tracing.stopChunk()} instead.
*/
public String name;
/**
@@ -120,8 +123,9 @@ public interface Tracing {
public String title;
/**
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
* specified in {@link BrowserType#launch BrowserType.launch()}.
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
* name, you need to pass {@code path} option to {@link Tracing#stopChunk Tracing.stopChunk()} instead.
*/
public StartChunkOptions setName(String name) {
this.name = name;
@@ -254,11 +254,24 @@ public interface LocatorAssertions {
}
}
class HasAttributeOptions {
/**
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
* expression flag if specified.
*/
public Boolean ignoreCase;
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
*/
public Double timeout;
/**
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
* expression flag if specified.
*/
public HasAttributeOptions setIgnoreCase(boolean ignoreCase) {
this.ignoreCase = ignoreCase;
return this;
}
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
*/
@@ -414,8 +427,8 @@ public interface LocatorAssertions {
*/
LocatorAssertions not();
/**
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
* DOM node.
* Ensures that {@code Locator} points to an element that is <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected">connected</a> to a Document or a ShadowRoot.
*
* <p> **Usage**
* <pre>{@code
@@ -428,8 +441,8 @@ public interface LocatorAssertions {
isAttached(null);
}
/**
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
* DOM node.
* Ensures that {@code Locator} points to an element that is <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected">connected</a> to a Document or a ShadowRoot.
*
* <p> **Usage**
* <pre>{@code
@@ -658,8 +671,8 @@ public interface LocatorAssertions {
*/
void isInViewport(IsInViewportOptions options);
/**
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
* and <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
* Ensures that {@code Locator} points to an attached and <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
*
* <p> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
*
@@ -685,8 +698,8 @@ public interface LocatorAssertions {
isVisible(null);
}
/**
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
* and <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
* Ensures that {@code Locator} points to an attached and <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
*
* <p> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
*
@@ -710,8 +723,13 @@ public interface LocatorAssertions {
*/
void isVisible(IsVisibleOptions options);
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -750,8 +768,13 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -788,8 +811,13 @@ public interface LocatorAssertions {
*/
void containsText(String expected, ContainsTextOptions options);
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -828,8 +856,13 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -866,8 +899,13 @@ public interface LocatorAssertions {
*/
void containsText(Pattern expected, ContainsTextOptions options);
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -906,8 +944,13 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -944,8 +987,13 @@ public interface LocatorAssertions {
*/
void containsText(String[] expected, ContainsTextOptions options);
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -984,8 +1032,13 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
* when computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1402,8 +1455,13 @@ public interface LocatorAssertions {
*/
void hasJSProperty(String name, Object value, HasJSPropertyOptions options);
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1442,8 +1500,13 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1480,8 +1543,13 @@ public interface LocatorAssertions {
*/
void hasText(String expected, HasTextOptions options);
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1520,8 +1588,13 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1558,8 +1631,13 @@ public interface LocatorAssertions {
*/
void hasText(Pattern expected, HasTextOptions options);
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1598,8 +1676,13 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1636,8 +1719,13 @@ public interface LocatorAssertions {
*/
void hasText(String[] expected, HasTextOptions options);
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1676,8 +1764,13 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
* computing the text content of the element. You can use regular expressions for the value as well.
*
* <p> **Details**
*
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
*
* <p> **Usage**
* <pre>{@code
@@ -1,8 +1,7 @@
package com.microsoft.playwright.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.microsoft.playwright.APIRequestContext;
import com.microsoft.playwright.APIResponse;
import com.microsoft.playwright.PlaywrightException;
@@ -11,6 +10,7 @@ import com.microsoft.playwright.options.FilePayload;
import com.microsoft.playwright.options.RequestOptions;
import java.io.File;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Base64;
@@ -85,11 +85,14 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
byte[] bytes = null;
if (options.data instanceof byte[]) {
bytes = (byte[]) options.data;
} else if (options.data instanceof String && !isJsonContentType(options.headers)) {
bytes = ((String) options.data).getBytes(StandardCharsets.UTF_8);
} else if (options.data instanceof String) {
String stringData = (String) options.data;
if (!isJsonContentType(options.headers) || isJsonParsable(stringData)) {
bytes = (stringData).getBytes(StandardCharsets.UTF_8);
}
}
if (bytes == null) {
params.add("jsonData", gson().toJsonTree(options.data));
params.addProperty("jsonData", gson().toJson(options.data));
} else {
String base64 = Base64.getEncoder().encodeToString(bytes);
params.addProperty("postData", base64);
@@ -202,4 +205,21 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
}
return impl;
}
private static boolean isJsonParsable(String value) {
try {
JsonElement result = JsonParser.parseString(value);
if (result != null && result.isJsonPrimitive()) {
JsonPrimitive primitive = result.getAsJsonPrimitive();
if (primitive.isString() && value.equals(primitive.getAsString())) {
// Gson parses unquoted strings too, but we don't want to treat them
// as valid JSON.
return false;
}
}
return true;
} catch (JsonSyntaxException error) {
return false;
}
}
}
@@ -34,9 +34,6 @@ class ArtifactImpl extends ChannelOwner {
public InputStream createReadStream() {
JsonObject result = sendMessage("stream").getAsJsonObject();
if (!result.has("stream")) {
return null;
}
Stream stream = connection.getExistingObject(result.getAsJsonObject("stream").get("guid").getAsString());
return stream.stream();
}
@@ -51,6 +51,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
private final WaitableEvent<EventType, ?> closePromise;
final Map<String, BindingCallback> bindings = new HashMap<>();
PageImpl ownerPage;
private String closeReason;
private static final Map<EventType, String> eventSubscriptions() {
Map<EventType, String> result = new HashMap<>();
result.put(EventType.CONSOLE, "console");
@@ -115,6 +117,16 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
}
}
String effectiveCloseReason() {
if (closeReason != null) {
return closeReason;
}
if (browser != null) {
return browser.closeReason;
}
return null;
}
@Override
public void onClose(Consumer<BrowserContext> handler) {
listeners.add(EventType.CLOSE, handler);
@@ -242,8 +254,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
}
@Override
public void close() {
withLogging("BrowserContext.close", () -> closeImpl());
public void close(CloseOptions options) {
withLogging("BrowserContext.close", () -> closeImpl(options));
}
@Override
@@ -251,9 +263,13 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
}
private void closeImpl() {
private void closeImpl(CloseOptions options) {
if (!closeWasCalled) {
closeWasCalled = true;
if (options == null) {
options = new CloseOptions();
}
closeReason = options.reason;
for (Map.Entry<String, HarRecorder> entry : harRecorders.entrySet()) {
JsonObject params = new JsonObject();
params.addProperty("harId", entry.getKey());
@@ -275,7 +291,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
}
artifact.delete();
}
sendMessage("close");
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
sendMessage("close", params);
}
runUntil(() -> {}, closePromise);
}
@@ -551,6 +568,14 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
return tracing;
}
@Override
public void unrouteAll() {
withLogging("BrowserContext.unrouteAll", () -> {
routes.removeAll();
updateInterceptionPatterns();
});
}
@Override
public void unroute(String url, Consumer<Route> handler) {
unroute(new UrlMatcher(this.baseUrl, url), handler);
@@ -594,7 +619,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
@Override
public R get() {
throw new PlaywrightException("Context closed");
throw new TargetClosedError(effectiveCloseReason());
}
}
@@ -752,9 +777,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
listeners.notify(EventType.CLOSE, this);
}
WritableStream createTempFile(String name) {
WritableStream createTempFile(String name, long lastModifiedMs) {
JsonObject params = new JsonObject();
params.addProperty("name", name);
params.addProperty("lastModifiedMs", lastModifiedMs);
JsonObject json = sendMessage("createTempFile", params).getAsJsonObject();
return connection.getExistingObject(json.getAsJsonObject("writableStream").get("guid").getAsString());
}
@@ -42,6 +42,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
BrowserTypeImpl browserType;
BrowserType.LaunchOptions launchOptions;
private Path tracePath;
String closeReason;
enum EventType {
DISCONNECTED,
@@ -67,11 +68,15 @@ class BrowserImpl extends ChannelOwner implements Browser {
}
@Override
public void close() {
withLogging("Browser.close", () -> closeImpl());
public void close(CloseOptions options) {
withLogging("Browser.close", () -> closeImpl(options));
}
private void closeImpl() {
private void closeImpl(CloseOptions options) {
if (options == null) {
options = new CloseOptions();
}
closeReason = options.reason;
if (isConnectedOverWebSocket) {
try {
connection.close();
@@ -25,7 +25,9 @@ import com.microsoft.playwright.TimeoutError;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.microsoft.playwright.impl.Serialization.gson;
@@ -38,6 +40,7 @@ class Message {
JsonObject params;
JsonElement result;
SerializedError error;
JsonArray log;
@Override
public String toString() {
@@ -206,6 +209,30 @@ public class Connection {
dispatch(messageObj);
}
private static String formatCallLog(JsonArray log) {
if (log == null) {
return "";
}
boolean allEmpty = true;
for (JsonElement e: log) {
if (!e.getAsString().isEmpty()) {
allEmpty = false;
break;
}
}
if (allEmpty) {
return "";
}
List<String> lines = new ArrayList<>();
lines.add("");
lines.add("Call log:");
for (JsonElement e: log) {
lines.add("- " + e.getAsString());
}
lines.add("");
return String.join("\n", lines);
}
private void dispatch(Message message) {
// System.out.println("Message: " + message.method + " " + message.id);
if (message.id != 0) {
@@ -218,12 +245,18 @@ public class Connection {
if (message.error == null) {
callback.complete(message.result);
} else {
String callLog = formatCallLog(message.log);
if (message.error.error == null) {
callback.completeExceptionally(new PlaywrightException(message.error.toString()));
callback.completeExceptionally(new PlaywrightException(message.error + callLog));
} else if ("Expect".equals(message.error.error.name)) {
callback.complete(message.result);
} else if ("TimeoutError".equals(message.error.error.name)) {
callback.completeExceptionally(new TimeoutError(message.error.error.toString()));
callback.completeExceptionally(new TimeoutError(message.error.error + callLog));
} else if ("TargetClosedError".equals(message.error.error.name)) {
callback.completeExceptionally(new TargetClosedError(message.error.error + callLog));
} else {
callback.completeExceptionally(new DriverException(message.error.error));
callback.completeExceptionally(new DriverException(message.error.error + callLog));
}
}
return;
@@ -22,7 +22,7 @@ import java.io.PrintStream;
import java.io.PrintWriter;
class DriverException extends PlaywrightException {
DriverException(SerializedError.Error error) {
super(error.toString());
DriverException(String error) {
super(error);
}
}
@@ -28,13 +28,12 @@ import com.microsoft.playwright.options.SelectOption;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import static com.microsoft.playwright.impl.Serialization.*;
import static com.microsoft.playwright.impl.Utils.*;
import static com.microsoft.playwright.impl.Utils.addLargeFileUploadParams;
import static com.microsoft.playwright.impl.Utils.addFilePathUploadParams;
import static com.microsoft.playwright.options.ScreenshotType.JPEG;
import static com.microsoft.playwright.options.ScreenshotType.PNG;
@@ -467,16 +466,12 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
if (frame == null) {
throw new Error("Cannot set input files to detached element");
}
if (hasLargeFile(files)) {
if (options == null) {
options = new SetInputFilesOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
addLargeFileUploadParams(files, params, frame.page().context());
sendMessage("setInputFilePaths", params);
} else {
setInputFilesImpl(Utils.toFilePayloads(files), options);
if (options == null) {
options = new SetInputFilesOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
addFilePathUploadParams(files, params, frame.page().context());
sendMessage("setInputFiles", params);
}
@Override
@@ -495,7 +490,7 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
options = new SetInputFilesOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.add("files", Serialization.toJsonArray(files));
params.add("payloads", Serialization.toJsonArray(files));
sendMessage("setInputFiles", params);
}
@@ -761,17 +761,13 @@ public class FrameImpl extends ChannelOwner implements Frame {
}
void setInputFilesImpl(String selector, Path[] files, SetInputFilesOptions options) {
if (hasLargeFile(files)) {
if (options == null) {
options = new SetInputFilesOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
addLargeFileUploadParams(files, params, page.context());
params.addProperty("selector", selector);
sendMessage("setInputFilePaths", params);
} else {
setInputFilesImpl(selector, Utils.toFilePayloads(files), options);
if (options == null) {
options = new SetInputFilesOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
addFilePathUploadParams(files, params, page.context());
params.addProperty("selector", selector);
sendMessage("setInputFiles", params);
}
@Override
@@ -791,7 +787,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.addProperty("selector", selector);
params.add("files", toJsonArray(files));
params.add("payloads", toJsonArray(files));
sendMessage("setInputFiles", params);
}
@@ -86,12 +86,14 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
public void hasAttribute(String name, String text, HasAttributeOptions options) {
ExpectedTextValue expected = new ExpectedTextValue();
expected.string = text;
expected.ignoreCase = shouldIgnoreCase(options);
hasAttribute(name, expected, text, options);
}
@Override
public void hasAttribute(String name, Pattern pattern, HasAttributeOptions options) {
ExpectedTextValue expected = expectedRegex(pattern);
expected.ignoreCase = shouldIgnoreCase(options);
hasAttribute(name, expected, pattern, options);
}
@@ -68,6 +68,7 @@ public class PageImpl extends ChannelOwner implements Page {
private final TimeoutSettings timeoutSettings;
private VideoImpl video;
private final PageImpl opener;
private String closeReason;
enum EventType {
CLOSE,
@@ -200,6 +201,13 @@ public class PageImpl extends ChannelOwner implements Page {
listeners.notify(EventType.CLOSE, this);
}
private String effectiveCloseReason() {
if (closeReason != null) {
return closeReason;
}
return browserContext.effectiveCloseReason();
}
@Override
public void onClose(Consumer<Page> handler) {
listeners.add(EventType.CLOSE, handler);
@@ -488,6 +496,7 @@ public class PageImpl extends ChannelOwner implements Page {
if (options == null) {
options = new CloseOptions();
}
closeReason = options.reason;
try {
if (ownedContext != null) {
ownedContext.close();
@@ -1217,6 +1226,14 @@ public class PageImpl extends ChannelOwner implements Page {
() -> mainFrame.uncheckImpl(selector, convertType(options, Frame.UncheckOptions.class)));
}
@Override
public void unrouteAll() {
withLogging("Page.unrouteAll", () -> {
routes.removeAll();
updateInterceptionPatterns();
});
}
@Override
public void unroute(String url, Consumer<Route> handler) {
unroute(new UrlMatcher(browserContext.baseUrl, url), handler);
@@ -1341,7 +1358,7 @@ public class PageImpl extends ChannelOwner implements Page {
@Override
public T get() {
throw new PlaywrightException("Page closed");
throw new TargetClosedError(effectiveCloseReason());
}
}
@@ -1352,7 +1369,7 @@ public class PageImpl extends ChannelOwner implements Page {
@Override
public T get() {
throw new PlaywrightException("Page crashed");
throw new TargetClosedError("Page crashed");
}
}
@@ -66,8 +66,8 @@ class Router {
.collect(Collectors.toList());
}
int size() {
return routes.size();
void removeAll() {
routes.clear();
}
enum HandleResult { NoMatchingHandler, Handled, Fallback, PendingHandler }
@@ -0,0 +1,29 @@
/*
* Copyright (c) Microsoft Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.playwright.impl;
import com.microsoft.playwright.PlaywrightException;
public class TargetClosedError extends PlaywrightException {
public TargetClosedError() {
super(null);
}
public TargetClosedError(String message) {
super(message != null ? message : "Target page, context or browser has been closed");
}
}
@@ -18,11 +18,9 @@ package com.microsoft.playwright.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.microsoft.playwright.ElementHandle;
import com.microsoft.playwright.PlaywrightException;
import com.microsoft.playwright.options.FilePayload;
import com.microsoft.playwright.options.HttpHeader;
import com.microsoft.playwright.options.SelectOption;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -32,6 +30,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.*;
import java.util.regex.Pattern;
@@ -174,26 +173,21 @@ class Utils {
return mimeType;
}
static final long maxUploadBufferSize = 50 * 1024 * 1024;
static boolean hasLargeFile(Path[] files) {
long totalSize = 0;
for (Path file: files) {
try {
totalSize += Files.size(file);
} catch (IOException e) {
throw new PlaywrightException("Cannot get file size.", e);
}
}
return totalSize > maxUploadBufferSize;
}
static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
if (context.connection.isRemote) {
static void addFilePathUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
if (files.length == 0) {
// FIXME: shouldBeAbleToResetSelectedFilesWithEmptyFileList tesst hangs in Chromium if we pass empty paths list.
params.add("payloads", new JsonArray());
} else if (context.connection.isRemote) {
List<WritableStream> streams = new ArrayList<>();
JsonArray jsonStreams = new JsonArray();
for (Path path : files) {
WritableStream temp = context.createTempFile(path.getFileName().toString());
long lastModifiedMs;
try {
lastModifiedMs = Files.getLastModifiedTime(path).toMillis();
} catch (IOException e) {
throw new PlaywrightException("Cannot read file timestamp: " + path, e);
}
WritableStream temp = context.createTempFile(path.getFileName().toString(), lastModifiedMs);
streams.add(temp);
try (OutputStream out = temp.stream()) {
Files.copy(path, out);
@@ -220,7 +214,7 @@ class Utils {
for (FilePayload file: files) {
totalSize += file.buffer.length;
}
if (totalSize > maxUploadBufferSize) {
if (totalSize > 50 * 1024 * 1024) {
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
}
}
@@ -28,6 +28,12 @@ class WritableStream extends ChannelOwner {
params.addProperty("binary", new String(encoded.array(), StandardCharsets.UTF_8));
sendMessage("write", params);
}
@Override
public void close() throws IOException {
super.close();
sendMessage("close");
}
};
}
}
@@ -42,6 +42,19 @@ public interface FormData {
}
/**
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
* <pre>{@code
* import com.microsoft.playwright.options.FormData;
* ...
* FormData form = FormData.create()
* // Only name and value are set.
* .set("firstName", "John")
* // Name and value are set, filename and Content-Type are inferred from the file path.
* .set("profilePicture1", Paths.get("john.jpg"))
* // Name, value, filename and Content-Type are set.
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
* .set("age", 30);
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
* }</pre>
*
* @param name Field name.
* @param value Field value.
@@ -50,6 +63,19 @@ public interface FormData {
FormData set(String name, String value);
/**
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
* <pre>{@code
* import com.microsoft.playwright.options.FormData;
* ...
* FormData form = FormData.create()
* // Only name and value are set.
* .set("firstName", "John")
* // Name and value are set, filename and Content-Type are inferred from the file path.
* .set("profilePicture1", Paths.get("john.jpg"))
* // Name, value, filename and Content-Type are set.
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
* .set("age", 30);
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
* }</pre>
*
* @param name Field name.
* @param value Field value.
@@ -58,6 +84,19 @@ public interface FormData {
FormData set(String name, boolean value);
/**
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
* <pre>{@code
* import com.microsoft.playwright.options.FormData;
* ...
* FormData form = FormData.create()
* // Only name and value are set.
* .set("firstName", "John")
* // Name and value are set, filename and Content-Type are inferred from the file path.
* .set("profilePicture1", Paths.get("john.jpg"))
* // Name, value, filename and Content-Type are set.
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
* .set("age", 30);
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
* }</pre>
*
* @param name Field name.
* @param value Field value.
@@ -66,6 +105,19 @@ public interface FormData {
FormData set(String name, int value);
/**
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
* <pre>{@code
* import com.microsoft.playwright.options.FormData;
* ...
* FormData form = FormData.create()
* // Only name and value are set.
* .set("firstName", "John")
* // Name and value are set, filename and Content-Type are inferred from the file path.
* .set("profilePicture1", Paths.get("john.jpg"))
* // Name, value, filename and Content-Type are set.
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
* .set("age", 30);
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
* }</pre>
*
* @param name Field name.
* @param value Field value.
@@ -74,6 +126,19 @@ public interface FormData {
FormData set(String name, Path value);
/**
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
* <pre>{@code
* import com.microsoft.playwright.options.FormData;
* ...
* FormData form = FormData.create()
* // Only name and value are set.
* .set("firstName", "John")
* // Name and value are set, filename and Content-Type are inferred from the file path.
* .set("profilePicture1", Paths.get("john.jpg"))
* // Name, value, filename and Content-Type are set.
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
* .set("age", 30);
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
* }</pre>
*
* @param name Field name.
* @param value Field value.
@@ -127,4 +127,15 @@ public class TestBrowser extends TestBase {
session.detach();
}
@Test
void shouldPropagateCloseReasonToPendingActions() {
Browser browser = browserType.launch();
BrowserContext context = browser.newContext();
PlaywrightException e = assertThrows(PlaywrightException.class, () -> context.waitForPage(() -> {
browser.close(new Browser.CloseOptions().setReason("The reason."));
}));
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
}
}
@@ -144,7 +144,7 @@ public class TestBrowserContextBasic extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
context.waitForPage(() -> context.close());
});
assertTrue(e.getMessage().contains("Context closed"));
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
}
@Test
@@ -236,8 +236,17 @@ public class TestBrowserContextBasic extends TestBase {
void shouldWorkWithOfflineOption() {
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setOffline(true));
Page page = context.newPage();
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
if (isFirefox()) {
// Firefox navigates to an error page, and this navigation might conflict with the
// next navigation we do in test.
// So we need to wait for the navigation explicitly.
boolean[] frameNavigated = { false };
page.onFrameNavigated(frame -> frameNavigated[0] = true);
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
page.waitForCondition(() -> frameNavigated[0], new Page.WaitForConditionOptions().setTimeout(10_000));
} else {
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
}
context.setOffline(false);
Response response = page.navigate(server.EMPTY_PAGE);
assertEquals(200, response.status());
@@ -281,7 +290,16 @@ public class TestBrowserContextBasic extends TestBase {
context.close();
return false;
}));
assertTrue(e.getMessage().contains("Context closed"), e.getMessage());
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
}
@Test
void shouldPropagateCloseReasonToPendingActions() {
BrowserContext context = browser.newContext();
Page page = context.newPage();
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.waitForPopup(() -> {
context.close(new BrowserContext.CloseOptions().setReason("The reason."));
}));
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
}
}
@@ -672,7 +672,7 @@ public class TestBrowserContextFetch extends TestBase {
});
page.evaluate("() => setTimeout(closeContext, 1000);");
PlaywrightException e = assertThrows(PlaywrightException.class, () -> context.request().get(server.EMPTY_PAGE));
assertTrue(e.getMessage().contains("Request context disposed"), e.getMessage());
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
e = assertThrows(PlaywrightException.class, () -> context.request().post(server.EMPTY_PAGE));
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
@@ -28,6 +28,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -39,6 +40,8 @@ import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.*;
public class TestBrowserTypeConnect extends TestBase {
static Path FILE_TO_UPLOAD = Paths.get("src/test/resources/file-to-upload.txt");
private Process browserServer;
private String wsEndpoint;
@@ -349,7 +352,7 @@ public class TestBrowserTypeConnect extends TestBase {
}
browser.close();
}
@Test
void shouldSaveAsVideosFromRemoteBrowser(@TempDir Path tempDir) {
Path videosPath = tempDir.resolve("videosPath");
@@ -501,4 +504,17 @@ public class TestBrowserTypeConnect extends TestBase {
assertEquals("200MB.zip", fields.get(0).filename);
assertEquals(200 * 1024 * 1024, fields.get(0).content.length());
}
@Test
void setInputFilesDhouldPreserveLastModifiedTimestamp() throws IOException {
page.setContent("<input type=file multiple=true/>");
Locator input = page.locator("input");
input.setInputFiles(FILE_TO_UPLOAD);
assertEquals(asList("file-to-upload.txt"), input.evaluate("e => [...e.files].map(f => f.name)"));
List<Double> timestamps = (List<Double>) input.evaluate("e => [...e.files].map(f => f.lastModified)");
FileTime expected = Files.getLastModifiedTime(FILE_TO_UPLOAD);
// On Linux browser sometimes reduces the timestamp by 1ms: 1696272058110.0715 -> 1696272058109 or even
// rounds it to seconds in WebKit: 1696272058110 -> 1696272058000.
assertTrue(Math.abs(timestamps.get(0) - expected.toMillis()) < 1000, "expected: " + expected.toMillis() + "; actual: " + timestamps.get(0));
}
}
@@ -18,6 +18,8 @@ package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.*;
public class TestElementHandleConvenience extends TestBase {
@@ -35,6 +37,17 @@ public class TestElementHandleConvenience extends TestBase {
assertEquals("JSHandle@<input checked id=\"check\" foo=\"bar\"\" type=\"checkbox\"/>", check.toString());
}
@Test
void shouldHaveANicePreviewForNonAsciiAttributesChildren() {
page.navigate(server.EMPTY_PAGE);
String text = String.join("", Collections.nCopies(100, "😛"));
page.setContent("<div title='" + text + "'>" + text + "</div>");
ElementHandle handle = page.querySelector("div");
context.waitForCondition(() -> "JSHandle@<div title=\"😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…>😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…</div>"
.equals(handle.toString()), new BrowserContext.WaitForConditionOptions().setTimeout(5_000));
assertEquals("JSHandle@<div title=\"😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…>😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…</div>", handle.toString());
}
@Test
void getAttributeShouldWork() {
page.navigate(server.PREFIX + "/dom.html");
@@ -122,7 +122,7 @@ public class TestEvalOnSelector extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
page.evalOnSelector("section", "e => e.id");
});
assertTrue(e.getMessage().contains("failed to find element matching selector \"section\""));
assertTrue(e.getMessage().contains("Failed to find element matching selector \"section\""), e.getMessage());
}
@Test
@@ -19,10 +19,14 @@ package com.microsoft.playwright;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.api.io.TempDir;
import java.nio.file.Path;
import static com.microsoft.playwright.Utils.mapOf;
import static org.junit.jupiter.api.Assertions.*;
@EnabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="skip")
public class TestFirefoxLauncher extends TestBase {
@Override
@@ -37,7 +41,6 @@ public class TestFirefoxLauncher extends TestBase {
}
@Test
@EnabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="skip")
void shouldPassFirefoxUserPreferences() {
BrowserType.LaunchOptions options = new BrowserType.LaunchOptions().setFirefoxUserPrefs(
mapOf(
@@ -49,4 +52,19 @@ public class TestFirefoxLauncher extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.navigate("http://example.com"));
assertTrue(e.getMessage().contains("NS_ERROR_PROXY_CONNECTION_REFUSED"));
}
@Test
void shouldPassFirefoxUserPreferencesInPersistent(@TempDir Path tmpDir) {
BrowserType.LaunchPersistentContextOptions options = new BrowserType.LaunchPersistentContextOptions().setFirefoxUserPrefs(
mapOf(
"network.proxy.type", 1,
"network.proxy.http", "127.0.0.1",
"network.proxy.http_port", 3333));
initBrowserType();
context = browserType.launchPersistentContext(tmpDir.resolve("user-data-dir"), options);
assertNotNull(context);
Page page = context.pages().get(0);
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.navigate("http://example.com"));
assertTrue(e.getMessage().contains("NS_ERROR_PROXY_CONNECTION_REFUSED"));
}
}
@@ -246,6 +246,14 @@ public class TestLocatorAssertions extends TestBase {
assertTrue(e.getMessage().contains("Locator expected to have text"), e.getMessage());
}
@Test
void hasAttributeTextIgnoreCase() {
page.setContent("<div id=NoDe>Text content</div>");
Locator locator = page.locator("#NoDe");
assertThat(locator).hasAttribute("id", "node", new LocatorAssertions.HasAttributeOptions().setIgnoreCase(true));
assertThat(locator).not().hasAttribute("id", "node");
}
@Test
void hasAttributeTextPass() {
page.setContent("<div id=node>Text content</div>");
@@ -112,12 +112,12 @@ public class TestPageBasic extends TestBase {
PlaywrightException e2 = assertThrows(PlaywrightException.class, () -> {
newPage.waitForRequest(server.EMPTY_PAGE, () -> newPage.close());
});
assertTrue(e2.getMessage().contains("Page closed"));
assertFalse(e2.getMessage().contains("Timeout"));
assertTrue(e2.getMessage().contains("Target page, context or browser has been closed"), e2.getMessage());
assertFalse(e2.getMessage().contains("Timeout"), e2.getMessage());
});
});
assertTrue(e1.getMessage().contains("Page closed"));
assertFalse(e1.getMessage().contains("Timeout"));
assertTrue(e1.getMessage().contains("Target page, context or browser has been closed"), e1.getMessage());
assertFalse(e1.getMessage().contains("Timeout"), e1.getMessage());
}
@Test
@@ -336,6 +336,15 @@ public class TestPageBasic extends TestBase {
page.close();
return false;
}));
assertTrue(e.getMessage().contains("Page closed"), e.getMessage());
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
}
@Test
void shouldPropagateCloseReasonToPendingActions() {
Page page = context.newPage();
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.waitForPopup(() -> {
page.close(new Page.CloseOptions().setReason("The reason."));
}));
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
}
}
@@ -391,7 +391,7 @@ public class TestPageEvaluate extends TestBase {
assertNotNull(element);
element.dispose();
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.evaluate("e => e.textContent", element));
assertTrue(e.getMessage().contains("JSHandle is disposed"));
assertTrue(e.getMessage().contains("no object with guid"), e.getMessage());
}
@Test
@@ -374,17 +374,9 @@ public class TestPageKeyboard extends TestBase {
JSHandle lastEvent = captureLastKeyDown();
page.keyboard().press("Meta");
LinkedHashMap eventData = (LinkedHashMap) lastEvent.jsonValue();
if (isFirefox() && !isMac) {
assertEquals("OS", eventData.get("key"));
} else {
assertEquals("Meta", eventData.get("key"));
}
assertEquals("Meta", eventData.get("key"));
assertEquals("MetaLeft", eventData.get("code"));
if (isFirefox() && !isMac) {
assertFalse((Boolean) eventData.get("metaKey"), eventData.toString());
} else {
assertTrue((Boolean) eventData.get("metaKey"), eventData.toString());
}
assertTrue((Boolean) eventData.get("metaKey"), eventData.toString());
}
@Test
@@ -134,15 +134,4 @@ public class TestPageNetworkRequest extends TestBase {
assertTrue(request[0].isNavigationRequest());
assertTrue(error[0].getMessage().contains("Frame for this navigation request is not available"), error[0].getMessage());
}
@Test
void shouldThrowIfRequestWasGCed() {
List<Request> requests = new ArrayList<>();
page.onRequest(req -> requests.add(req));
for (int i = 0; i < 1001; i++) {
page.navigate(server.EMPTY_PAGE);
}
PlaywrightException e = assertThrows(PlaywrightException.class, () -> requests.get(0).response());
assertEquals("The object has been collected to prevent unbounded heap growth.", e.getMessage());
}
}
@@ -28,7 +28,10 @@ import org.opentest4j.AssertionFailedError;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
@@ -249,4 +252,40 @@ public class TestPageScreenshot extends TestBase {
assertThrows(AssertionError.class, () -> assertArrayEquals(screenshot1, screenshot2));
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isWebKit", disabledReason="array lengths differ")
void shouldHideElementsBasedOnAttr() throws IOException {
page.setViewportSize(500, 500);
page.navigate(server.PREFIX + "/grid.html");
page.locator("div").nth(5).evaluate("element => {\n" +
" element.setAttribute('data-test-screenshot', 'hide');\n" +
"}");
byte[] actual = page.screenshot(new Page.ScreenshotOptions().setStyle("[data-test-screenshot=\"hide\"] {\n" +
" visibility: hidden;\n" +
" }"));
assertArrayEquals(expectedScreenshot("hide-should-work"), actual, "Screenshots should match");
Object visibility = page.locator("div").nth(5).evaluate("element => element.style.visibility");
assertEquals("", visibility);
}
@Test
@DisabledIf(value="com.microsoft.playwright.TestBase#isWebKit", disabledReason="array lengths differ")
void shouldRemoveElementsBasedOnAttr() throws IOException {
page.setViewportSize(500, 500);
page.navigate(server.PREFIX + "/grid.html");
page.locator("div").nth(5).evaluate("element => {\n" +
" element.setAttribute('data-test-screenshot', 'remove');\n" +
" }");
byte[] actual = page.screenshot(new Page.ScreenshotOptions().setStyle("[data-test-screenshot=\"remove\"] {\n" +
" display: none;\n" +
" }"));
assertArrayEquals(expectedScreenshot("remove-should-work"), actual, "Screenshots should match");
Object display = page.locator("div").nth(5).evaluate("element => element.style.display");
assertEquals("", display);
}
private byte[] expectedScreenshot(String name) throws IOException {
Path path = Paths.get("src/test/resources/expectations");
return Files.readAllBytes(path.resolve(name + "-" + browserType.name() + ".png"));
}
}
@@ -27,6 +27,7 @@ import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
@@ -35,6 +36,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import static com.microsoft.playwright.Utils.relativePathOrSkipTest;
@@ -306,7 +308,18 @@ public class TestPageSetInputFiles extends TestBase {
assertEquals("file-to-upload.txt", page.evalOnSelector("input", "input => input.files[0].name"));
}
// @Test
@Test
void shouldAcceptSingleFilePayload() {
page.setContent("<input type=file oninput='javascript:console.timeStamp()'>");
FileChooser fileChooser = page.waitForFileChooser(() -> page.click("input"));
assertEquals(page, fileChooser.page());
assertNotNull(fileChooser.element());
fileChooser.setFiles(new FilePayload("test.txt", "text/plain", "Hello!".getBytes()));
assertEquals(1, page.evalOnSelector("input", "input => input.files.length"));
assertEquals("test.txt", page.evalOnSelector("input", "input => input.files[0].name"));
}
// @Test
void shouldDetectMimeType() throws ExecutionException, InterruptedException {
// TODO: Parse form fields on server
}
@@ -403,5 +416,18 @@ public class TestPageSetInputFiles extends TestBase {
FileChooser fileChooser = page.waitForFileChooser(() -> page.click("input"));
assertTrue(fileChooser.isMultiple());
}
@Test
void shouldPreserveLastModifiedTimestamp() throws IOException {
page.setContent("<input type=file multiple=true/>");
Locator input = page.locator("input");
input.setInputFiles(FILE_TO_UPLOAD);
assertEquals(asList("file-to-upload.txt"), input.evaluate("e => [...e.files].map(f => f.name)"));
List<Double> timestamps = (List<Double>) input.evaluate("e => [...e.files].map(f => f.lastModified)");
FileTime expected = Files.getLastModifiedTime(FILE_TO_UPLOAD);
// On Linux browser sometimes reduces the timestamp by 1ms: 1696272058110.0715 -> 1696272058109 or even
// rounds it to seconds in WebKit: 1696272058110 -> 1696272058000.
assertTrue(Math.abs(timestamps.get(0) - expected.toMillis()) < 1000, "expected: " + expected.toMillis() + "; actual: " + timestamps.get(0));
}
}
@@ -0,0 +1,33 @@
package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestUnrouteBehavior extends TestBase {
@Test
void contextUnrouteAllRemovesAllHandlers() {
context.route("**/*", route -> {
route.abort();
});
context.route("**/empty.html", route -> {
route.abort();
});
context.unrouteAll();
page.navigate(server.EMPTY_PAGE);
}
@Test
void pageUnrouteAllRemovesAllRoutes() {
page.route("**/*", route -> {
route.abort();
});
page.route("**/empty.html", route -> {
route.abort();
});
page.unrouteAll();
Response response = page.navigate(server.EMPTY_PAGE);
assertTrue(response.ok());
}
}
@@ -199,7 +199,7 @@ public class TestWebSocket extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
ws.waitForFrameSent(() -> page.close());
});
assertTrue(e.getMessage().contains("Page closed"));
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
}
@Test
@@ -57,7 +57,7 @@ public class TestWorkers extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
workerThisObj.getProperty("self");
});
assertTrue(e.getMessage().contains("Target closed") || e.getMessage().contains("Worker was closed"), e.getMessage());
assertTrue(e.getMessage().contains("Target page, context or browser has been closed") || e.getMessage().contains("Worker was closed"), e.getMessage());
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.39.0</version>
<version>1.41.2</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.39.0
1.41.2
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>api-generator</artifactId>
<version>1.39.0</version>
<version>1.41.2</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.39.0</version>
<version>1.41.2</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.39.0</version>
<version>1.41.2</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.39.0</version>
<version>1.41.2</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.39.0</version>
<version>1.41.2</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.39.0</version>
<version>1.41.2</version>
<name>Playwright - Update Version in Documentation</name>
<description>
This is an internal module used to update versions in the documentation based on
+9
View File
@@ -54,4 +54,13 @@ RUN cd /tmp/pw-java && \
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
-D exec.args="mark-docker-image '${DOCKER_IMAGE_NAME_TEMPLATE}'" -f playwright/pom.xml --no-transfer-progress && \
rm -rf /tmp/pw-java && \
# Workaround for https://github.com/microsoft/playwright/issues/27313
# While the gstreamer plugin load process can be in-process, it ended up throwing
# an error that it can't have libsoup2 and libsoup3 in the same process because
# libgstwebrtc is linked against libsoup2. So we just remove the plugin.
if [ "$(uname -m)" = "aarch64" ]; then \
rm /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstwebrtc.so; \
else \
rm /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstwebrtc.so; \
fi && \
chmod -R 777 $PLAYWRIGHT_BROWSERS_PATH