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

Compare commits

..

1 Commits

Author SHA1 Message Date
Yury Semikhatsky 0a5673b8bc chore: mark 1.37.0 (#1349) 2023-08-14 09:08:57 -07:00
97 changed files with 523 additions and 1738 deletions
+4 -6
View File
@@ -46,17 +46,15 @@ steps:
done
displayName: 'Create .sha256 files'
- task: EsrpRelease@4
- task: EsrpRelease@2
inputs:
ConnectedServiceName: 'Playwright-ESRP'
ConnectedServiceName: 'Playwright-Java-ESRP'
Intent: 'PackageDistribution'
ContentType: 'Maven'
ContentSource: 'Folder'
FolderLocation: './local-build'
WaitForReleaseCompletion: true
PackageLocation: './local-build'
Owners: 'yurys@microsoft.com'
Approvers: 'maxschmitt@microsoft.com'
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
MainPublisher: 'Playwright'
MainPublisher: 'PlaywrightJava'
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
displayName: 'ESRP Release to Maven'
+4 -4
View File
@@ -11,11 +11,11 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| 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 -->121.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->116.0.5845.82<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->17.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->115.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.
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/next/intro/#system-requirements) for details.
* [Usage](#usage)
- [Add Maven dependency](#add-maven-dependency)
-7
View File
@@ -6,15 +6,8 @@
* regenerate API: `./scripts/download_driver_for_all_platforms.sh -f && ./scripts/generate_api.sh && ./scripts/update_readme.sh`
* commit & send PR with the roll
### Finding driver version
For development versions of Playwright, you can find the latest version by looking at [publish_canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) workflow -> `publish canary NPM & Publish canary Docker` -> `build & publish driver` step -> `PACKAGE_VERSION`
<img width="960" alt="image" src="https://github.com/microsoft/playwright-java/assets/9798949/4f33a7f1-b39a-4179-8ae7-fb1d84094c75">
# Updating Version
```bash
./scripts/set_maven_version.sh 1.15.0
```
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
</parent>
<artifactId>driver-bundle</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
</parent>
<artifactId>driver</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>org.example</groupId>
<artifactId>examples</artifactId>
<version>1.41.2</version>
<version>1.37.0</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.41.2</version>
<version>1.37.0</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 its resources,
* calling any method on disposed {@code APIRequestContext} will throw an exception.
* 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.
*
* @since v1.16
*/
@@ -56,20 +56,6 @@ 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.
@@ -1179,25 +1165,7 @@ public interface Browser extends AutoCloseable {
*
* @since v1.8
*/
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);
void close();
/**
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
*
@@ -127,16 +127,6 @@ public interface BrowserContext extends AutoCloseable {
*/
void offPage(Consumer<Page> handler);
/**
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular page,
* use {@link Page#onPageError Page.onPageError()} instead.
*/
void onWebError(Consumer<WebError> handler);
/**
* Removes handler that was previously added with {@link #onWebError onWebError(handler)}.
*/
void offWebError(Consumer<WebError> handler);
/**
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only
* listen for requests from a particular page, use {@link Page#onRequest Page.onRequest()}.
@@ -186,20 +176,6 @@ 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
@@ -518,17 +494,7 @@ public interface BrowserContext extends AutoCloseable {
*
* @since v1.8
*/
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);
void close();
/**
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
* are returned.
@@ -1260,13 +1226,6 @@ 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,10 +165,8 @@ public interface BrowserType {
}
class LaunchOptions {
/**
* <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>.
* 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>.
*/
public List<String> args;
/**
@@ -255,10 +253,8 @@ public interface BrowserType {
public Path tracesDir;
/**
* <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>.
* 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>.
*/
public LaunchOptions setArgs(List<String> args) {
this.args = args;
@@ -420,10 +416,8 @@ public interface BrowserType {
*/
public Boolean acceptDownloads;
/**
* <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>.
* 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>.
*/
public List<String> args;
/**
@@ -492,11 +486,6 @@ 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.
@@ -681,10 +670,8 @@ public interface BrowserType {
return this;
}
/**
* <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>.
* 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>.
*/
public LaunchPersistentContextOptions setArgs(List<String> args) {
this.args = args;
@@ -799,14 +786,6 @@ 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.
@@ -24,16 +24,14 @@ import java.nio.file.Path;
*
* <p> All the downloaded files belonging to the browser context are deleted when the browser context is closed.
*
* <p> Download event is emitted once the download starts. Download path becomes available once download completes.
* <p> Download event is emitted once the download starts. Download path becomes available once download completes:
* <pre>{@code
* // Wait for the download to start
* // wait for download to start
* Download download = page.waitForDownload(() -> {
* // Perform the action that initiates download
* page.getByText("Download file").click();
* page.getByText("Download file").click();
* });
*
* // Wait for the download process to complete and save the downloaded file somewhere
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
* // wait for download to complete
* Path path = download.path();
* }</pre>
*/
public interface Download {
@@ -45,7 +43,7 @@ public interface Download {
*/
void cancel();
/**
* Returns a readable stream for a successful download, or throws for a failed/canceled download.
* Returns readable stream for current download or {@code null} if download failed.
*
* @since v1.8
*/
@@ -69,8 +67,8 @@ public interface Download {
*/
Page page();
/**
* 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.
* 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.
*
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()}
* to get suggested file name.
@@ -82,11 +80,6 @@ public interface Download {
* Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will
* wait for the download to finish if necessary.
*
* <p> **Usage**
* <pre>{@code
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
* }</pre>
*
* @param path Path where the download should be copied.
* @since v1.8
*/
@@ -634,12 +634,6 @@ 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
@@ -725,15 +719,6 @@ 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
@@ -1426,17 +1411,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -1470,17 +1451,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -1605,7 +1582,7 @@ public interface ElementHandle extends JSHandle {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link ElementHandle#type ElementHandle.type()}.
*
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
* @since v1.8
@@ -1623,7 +1600,7 @@ public interface ElementHandle extends JSHandle {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link ElementHandle#type ElementHandle.type()}.
*
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
* @since v1.8
@@ -1901,7 +1878,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -1932,7 +1909,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -1961,7 +1938,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -1992,7 +1969,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2021,7 +1998,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2052,7 +2029,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2081,7 +2058,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2112,7 +2089,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2141,7 +2118,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2172,7 +2149,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2201,7 +2178,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2232,7 +2209,7 @@ public interface ElementHandle extends JSHandle {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* handle.selectOption("blue");
* // single selection matching the label
* handle.selectOption(new SelectOption().setLabel("Blue"));
@@ -2473,9 +2450,24 @@ public interface ElementHandle extends JSHandle {
*/
String textContent();
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link ElementHandle#press
* ElementHandle.press()}.
*
* <p> **Usage**
* <pre>{@code
* elementHandle.type("Hello"); // Types instantly
* elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
* }</pre>
*
* <p> An example of typing into a text field and then submitting the form:
* <pre>{@code
* ElementHandle elementHandle = page.querySelector("input");
* elementHandle.type("some text");
* elementHandle.press("Enter");
* }</pre>
*
* @param text A text to type into a focused element.
* @since v1.8
@@ -2484,9 +2476,24 @@ public interface ElementHandle extends JSHandle {
type(text, null);
}
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link ElementHandle#press
* ElementHandle.press()}.
*
* <p> **Usage**
* <pre>{@code
* elementHandle.type("Hello"); // Types instantly
* elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
* }</pre>
*
* <p> An example of typing into a text field and then submitting the form:
* <pre>{@code
* ElementHandle elementHandle = page.querySelector("input");
* elementHandle.type("some text");
* elementHandle.press("Enter");
* }</pre>
*
* @param text A text to type into a focused element.
* @since v1.8
@@ -2546,7 +2553,8 @@ 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 not attached. Note that waiting for hidden does not throw when the element detaches.</li>
* 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>
* <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>
@@ -2576,7 +2584,8 @@ 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 not attached. Note that waiting for hidden does not throw when the element detaches.</li>
* 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>
* <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,14 +1470,8 @@ public interface Frame {
}
class LocatorOptions {
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1503,14 +1497,8 @@ public interface Frame {
public Object hasText;
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -2594,17 +2582,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -2640,17 +2624,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -2685,17 +2665,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -3011,7 +2987,7 @@ public interface Frame {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link Frame#type Frame.type()}.
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
@@ -3030,7 +3006,7 @@ public interface Frame {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link Frame#type Frame.type()}.
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
@@ -4082,7 +4058,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4115,7 +4091,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4146,7 +4122,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4179,7 +4155,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4210,7 +4186,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4243,7 +4219,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4274,7 +4250,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4307,7 +4283,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4338,7 +4314,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4371,7 +4347,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4402,7 +4378,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4435,7 +4411,7 @@ public interface Frame {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* frame.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -4701,9 +4677,19 @@ public interface Frame {
*/
String title();
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
* frame.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Frame#fill
* Frame.fill()}.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
*
* <p> **Usage**
* <pre>{@code
* // Types instantly
* frame.type("#mytextarea", "Hello");
* // Types slower, like a user
* frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
* }</pre>
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param text A text to type into a focused element.
@@ -4713,9 +4699,19 @@ public interface Frame {
type(selector, text, null);
}
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
* frame.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Frame#fill
* Frame.fill()}.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
*
* <p> **Usage**
* <pre>{@code
* // Types instantly
* frame.type("#mytextarea", "Hello");
* // Types slower, like a user
* frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
* }</pre>
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param text A text to type into a focused element.
@@ -285,14 +285,8 @@ public interface FrameLocator {
}
class LocatorOptions {
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -318,14 +312,8 @@ public interface FrameLocator {
public Object hasText;
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -132,9 +132,7 @@ public interface Keyboard {
*/
void insertText(String text);
/**
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
*
* <p> {@code key} can specify the intended <a
* {@code key} can specify the intended <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
* character to generate the text for. A superset of the {@code key} values can be found <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
@@ -177,9 +175,7 @@ public interface Keyboard {
press(key, null);
}
/**
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
*
* <p> {@code key} can specify the intended <a
* {@code key} can specify the intended <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
* character to generate the text for. A superset of the {@code key} values can be found <a
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
@@ -220,11 +216,7 @@ public interface Keyboard {
*/
void press(String key, PressOptions options);
/**
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
*
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
*
@@ -247,11 +239,7 @@ public interface Keyboard {
type(text, null);
}
/**
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
*
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
*
@@ -656,14 +656,8 @@ public interface Locator {
}
class FilterOptions {
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -689,14 +683,8 @@ public interface Locator {
public Object hasText;
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1274,14 +1262,8 @@ public interface Locator {
}
class LocatorOptions {
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1307,14 +1289,8 @@ public interface Locator {
public Object hasText;
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1412,50 +1388,6 @@ public interface Locator {
return this;
}
}
class PressSequentiallyOptions {
/**
* Time to wait between key presses in milliseconds. Defaults to 0.
*/
public Double delay;
/**
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
* inaccessible pages. Defaults to {@code false}.
*/
public Boolean noWaitAfter;
/**
* 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
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
*/
public Double timeout;
/**
* Time to wait between key presses in milliseconds. Defaults to 0.
*/
public PressSequentiallyOptions setDelay(double delay) {
this.delay = delay;
return this;
}
/**
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
* inaccessible pages. Defaults to {@code false}.
*/
public PressSequentiallyOptions setNoWaitAfter(boolean noWaitAfter) {
this.noWaitAfter = noWaitAfter;
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
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
*/
public PressSequentiallyOptions setTimeout(double timeout) {
this.timeout = timeout;
return this;
}
}
class ScreenshotOptions {
/**
* When set to {@code "disabled"}, stops CSS animations, CSS transitions and Web Animations. Animations get different
@@ -1507,12 +1439,6 @@ 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
@@ -1598,15 +1524,6 @@ 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
@@ -2135,10 +2052,6 @@ public interface Locator {
/**
* Returns an array of {@code node.innerText} values for all matching nodes.
*
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} with {@code
* useInnerText} option to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions
* guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* String[] texts = page.getByRole(AriaRole.LINK).allInnerTexts();
@@ -2150,9 +2063,6 @@ public interface Locator {
/**
* Returns an array of {@code node.textContent} values for all matching nodes.
*
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} to avoid
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* String[] texts = page.getByRole(AriaRole.LINK).allTextContents();
@@ -2426,10 +2336,6 @@ public interface Locator {
/**
* Returns the number of elements matching the locator.
*
* <p> <strong>NOTE:</strong> If you need to assert the number of elements on the page, prefer {@link LocatorAssertions#hasCount
* LocatorAssertions.hasCount()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* int count = page.getByRole(AriaRole.LISTITEM).count();
@@ -2510,17 +2416,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -2559,17 +2461,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -2607,17 +2505,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -2938,7 +2832,7 @@ public interface Locator {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link Locator#type Locator.type()}.
*
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
* @since v1.14
@@ -2965,7 +2859,7 @@ public interface Locator {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link Locator#type Locator.type()}.
*
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
* @since v1.14
@@ -3048,10 +2942,6 @@ public interface Locator {
/**
* Returns the matching element's attribute value.
*
* <p> <strong>NOTE:</strong> If you need to assert an element's attribute, prefer {@link LocatorAssertions#hasAttribute
* LocatorAssertions.hasAttribute()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* @param name Attribute name to get the value for.
* @since v1.14
*/
@@ -3061,10 +2951,6 @@ public interface Locator {
/**
* Returns the matching element's attribute value.
*
* <p> <strong>NOTE:</strong> If you need to assert an element's attribute, prefer {@link LocatorAssertions#hasAttribute
* LocatorAssertions.hasAttribute()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* @param name Attribute name to get the value for.
* @since v1.14
*/
@@ -3704,10 +3590,6 @@ public interface Locator {
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText">{@code
* element.innerText}</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} with {@code
* useInnerText} option to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions
* guide</a> for more details.
*
* @since v1.14
*/
default String innerText() {
@@ -3717,19 +3599,12 @@ public interface Locator {
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText">{@code
* element.innerText}</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} with {@code
* useInnerText} option to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions
* guide</a> for more details.
*
* @since v1.14
*/
String innerText(InnerTextOptions options);
/**
* Returns the value for the matching {@code <input>} or {@code <textarea>} or {@code <select>} element.
*
* <p> <strong>NOTE:</strong> If you need to assert input value, prefer {@link LocatorAssertions#hasValue LocatorAssertions.hasValue()} to avoid
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* String value = page.getByRole(AriaRole.TEXTBOX).inputValue();
@@ -3750,9 +3625,6 @@ public interface Locator {
/**
* Returns the value for the matching {@code <input>} or {@code <textarea>} or {@code <select>} element.
*
* <p> <strong>NOTE:</strong> If you need to assert input value, prefer {@link LocatorAssertions#hasValue LocatorAssertions.hasValue()} to avoid
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* String value = page.getByRole(AriaRole.TEXTBOX).inputValue();
@@ -3771,10 +3643,6 @@ public interface Locator {
/**
* Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
*
* <p> <strong>NOTE:</strong> If you need to assert that checkbox is checked, prefer {@link LocatorAssertions#isChecked LocatorAssertions.isChecked()}
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
* details.
*
* <p> **Usage**
* <pre>{@code
* boolean checked = page.getByRole(AriaRole.CHECKBOX).isChecked();
@@ -3788,10 +3656,6 @@ public interface Locator {
/**
* Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
*
* <p> <strong>NOTE:</strong> If you need to assert that checkbox is checked, prefer {@link LocatorAssertions#isChecked LocatorAssertions.isChecked()}
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
* details.
*
* <p> **Usage**
* <pre>{@code
* boolean checked = page.getByRole(AriaRole.CHECKBOX).isChecked();
@@ -3804,10 +3668,6 @@ public interface Locator {
* Returns whether the element is disabled, the opposite of <a
* href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that an element is disabled, prefer {@link LocatorAssertions#isDisabled
* LocatorAssertions.isDisabled()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean disabled = page.getByRole(AriaRole.BUTTON).isDisabled();
@@ -3822,10 +3682,6 @@ public interface Locator {
* Returns whether the element is disabled, the opposite of <a
* href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that an element is disabled, prefer {@link LocatorAssertions#isDisabled
* LocatorAssertions.isDisabled()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean disabled = page.getByRole(AriaRole.BUTTON).isDisabled();
@@ -3837,10 +3693,6 @@ public interface Locator {
/**
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#editable">editable</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that an element is editable, prefer {@link LocatorAssertions#isEditable
* LocatorAssertions.isEditable()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean editable = page.getByRole(AriaRole.TEXTBOX).isEditable();
@@ -3854,10 +3706,6 @@ public interface Locator {
/**
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#editable">editable</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that an element is editable, prefer {@link LocatorAssertions#isEditable
* LocatorAssertions.isEditable()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean editable = page.getByRole(AriaRole.TEXTBOX).isEditable();
@@ -3869,10 +3717,6 @@ public interface Locator {
/**
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that an element is enabled, prefer {@link LocatorAssertions#isEnabled
* LocatorAssertions.isEnabled()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean enabled = page.getByRole(AriaRole.BUTTON).isEnabled();
@@ -3886,10 +3730,6 @@ public interface Locator {
/**
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that an element is enabled, prefer {@link LocatorAssertions#isEnabled
* LocatorAssertions.isEnabled()} to avoid flakiness. See <a
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean enabled = page.getByRole(AriaRole.BUTTON).isEnabled();
@@ -3902,9 +3742,6 @@ public interface Locator {
* Returns whether the element is hidden, the opposite of <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that element is hidden, prefer {@link LocatorAssertions#isHidden LocatorAssertions.isHidden()} to
* avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean hidden = page.getByRole(AriaRole.BUTTON).isHidden();
@@ -3919,9 +3756,6 @@ public interface Locator {
* Returns whether the element is hidden, the opposite of <a
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that element is hidden, prefer {@link LocatorAssertions#isHidden LocatorAssertions.isHidden()} to
* avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* <p> **Usage**
* <pre>{@code
* boolean hidden = page.getByRole(AriaRole.BUTTON).isHidden();
@@ -3933,10 +3767,6 @@ public interface Locator {
/**
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that element is visible, prefer {@link LocatorAssertions#isVisible LocatorAssertions.isVisible()}
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
* details.
*
* <p> **Usage**
* <pre>{@code
* boolean visible = page.getByRole(AriaRole.BUTTON).isVisible();
@@ -3950,10 +3780,6 @@ public interface Locator {
/**
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert that element is visible, prefer {@link LocatorAssertions#isVisible LocatorAssertions.isVisible()}
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
* details.
*
* <p> **Usage**
* <pre>{@code
* boolean visible = page.getByRole(AriaRole.BUTTON).isVisible();
@@ -4130,60 +3956,6 @@ public interface Locator {
* @since v1.14
*/
void press(String key, PressOptions options);
/**
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page.
*
* <p> Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
*
* <p> **Usage**
* <pre>{@code
* locator.pressSequentially("Hello"); // Types instantly
* locator.pressSequentially("World", new Locator.pressSequentiallyOptions().setDelay(100)); // Types slower, like a user
* }</pre>
*
* <p> An example of typing into a text field and then submitting the form:
* <pre>{@code
* Locator locator = page.getByLabel("Password");
* locator.pressSequentially("my password");
* locator.press("Enter");
* }</pre>
*
* @param text String of characters to sequentially press into a focused element.
* @since v1.38
*/
default void pressSequentially(String text) {
pressSequentially(text, null);
}
/**
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page.
*
* <p> Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
*
* <p> **Usage**
* <pre>{@code
* locator.pressSequentially("Hello"); // Types instantly
* locator.pressSequentially("World", new Locator.pressSequentiallyOptions().setDelay(100)); // Types slower, like a user
* }</pre>
*
* <p> An example of typing into a text field and then submitting the form:
* <pre>{@code
* Locator locator = page.getByLabel("Password");
* locator.pressSequentially("my password");
* locator.press("Enter");
* }</pre>
*
* @param text String of characters to sequentially press into a focused element.
* @since v1.38
*/
void pressSequentially(String text, PressSequentiallyOptions options);
/**
* Take a screenshot of the element matching the locator.
*
@@ -5081,9 +4853,6 @@ public interface Locator {
/**
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent">{@code node.textContent}</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} to avoid
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* @since v1.14
*/
default String textContent() {
@@ -5092,16 +4861,30 @@ public interface Locator {
/**
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent">{@code node.textContent}</a>.
*
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} to avoid
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
*
* @since v1.14
*/
String textContent(TextContentOptions options);
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to type characters if there is
* special keyboard handling on the page.
*
* <p> Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
*
* <p> **Usage**
* <pre>{@code
* element.type("Hello"); // Types instantly
* element.type("World", new Locator.TypeOptions().setDelay(100)); // Types slower, like a user
* }</pre>
*
* <p> An example of typing into a text field and then submitting the form:
* <pre>{@code
* Locator element = page.getByLabel("Password");
* element.type("my password");
* element.press("Enter");
* }</pre>
*
* @param text A text to type into a focused element.
* @since v1.14
@@ -5110,9 +4893,26 @@ public interface Locator {
type(text, null);
}
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to type characters if there is
* special keyboard handling on the page.
*
* <p> Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
* character in the text.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
*
* <p> **Usage**
* <pre>{@code
* element.type("Hello"); // Types instantly
* element.type("World", new Locator.TypeOptions().setDelay(100)); // Types slower, like a user
* }</pre>
*
* <p> An example of typing into a text field and then submitting the form:
* <pre>{@code
* Locator element = page.getByLabel("Password");
* element.type("my password");
* element.press("Enter");
* }</pre>
*
* @param text A text to type into a focused element.
* @since v1.14
@@ -650,23 +650,12 @@ 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.
@@ -1924,14 +1913,8 @@ public interface Page extends AutoCloseable {
}
class LocatorOptions {
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -1957,14 +1940,8 @@ public interface Page extends AutoCloseable {
public Object hasText;
/**
* 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}.
* 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>}.
*
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
*/
@@ -2462,12 +2439,6 @@ 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
@@ -2574,15 +2545,6 @@ 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
@@ -3896,17 +3858,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -3942,17 +3900,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -3987,17 +3941,13 @@ 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/WheelEvent/WheelEvent">WheelEvent</a></li>
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</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:
@@ -4585,7 +4535,7 @@ public interface Page extends AutoCloseable {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link Page#type Page.type()}.
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
@@ -4604,7 +4554,7 @@ public interface Page extends AutoCloseable {
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
* instead.
*
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
* <p> To send fine-grained keyboard events, use {@link Page#type Page.type()}.
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
@@ -6307,7 +6257,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6340,7 +6290,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6371,7 +6321,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6404,7 +6354,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6435,7 +6385,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6468,7 +6418,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6499,7 +6449,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6532,7 +6482,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6563,7 +6513,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6596,7 +6546,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6627,7 +6577,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6660,7 +6610,7 @@ public interface Page extends AutoCloseable {
*
* <p> **Usage**
* <pre>{@code
* // Single selection matching the value or label
* // single selection matching the value
* page.selectOption("select#colors", "blue");
* // single selection matching both the value and the label
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
@@ -6992,9 +6942,19 @@ public interface Page extends AutoCloseable {
*/
Touchscreen touchscreen();
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
* page.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Page#fill
* Page.fill()}.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
*
* <p> **Usage**
* <pre>{@code
* // Types instantly
* page.type("#mytextarea", "Hello");
* // Types slower, like a user
* page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
* }</pre>
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param text A text to type into a focused element.
@@ -7004,9 +6964,19 @@ public interface Page extends AutoCloseable {
type(selector, text, null);
}
/**
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
* Locator.pressSequentially()}.
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
* page.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Page#fill
* Page.fill()}.
*
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
*
* <p> **Usage**
* <pre>{@code
* // Types instantly
* page.type("#mytextarea", "Hello");
* // Types slower, like a user
* page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
* }</pre>
*
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* @param text A text to type into a focused element.
@@ -7057,12 +7027,6 @@ 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}.
@@ -7874,8 +7838,8 @@ public interface Page extends AutoCloseable {
*/
ElementHandle waitForSelector(String selector, WaitForSelectorOptions options);
/**
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
* waiting for the condition.
* The method will block until the codition returns true. All Playwright events will be dispatched while the method is
* waiting for the codition.
*
* <p> **Usage**
*
@@ -7887,15 +7851,15 @@ public interface Page extends AutoCloseable {
* page.waitForCondition(() -> messages.size() > 3);
* }</pre>
*
* @param condition Condition to wait for.
* @param condition Codition to wait for.
* @since v1.32
*/
default void waitForCondition(BooleanSupplier condition) {
waitForCondition(condition, null);
}
/**
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
* waiting for the condition.
* The method will block until the codition returns true. All Playwright events will be dispatched while the method is
* waiting for the codition.
*
* <p> **Usage**
*
@@ -7907,7 +7871,7 @@ public interface Page extends AutoCloseable {
* page.waitForCondition(() -> messages.size() > 3);
* }</pre>
*
* @param condition Condition to wait for.
* @param condition Codition to wait for.
* @since v1.32
*/
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
@@ -62,22 +62,6 @@ public interface Request {
/**
* Returns the {@code Frame} that initiated this request.
*
* <p> **Usage**
* <pre>{@code
* String frameUrl = request.frame().url();
* }</pre>
*
* <p> **Details**
*
* <p> Note that in some cases the frame is not available, and this method will throw.
* <ul>
* <li> When request originates in the Service Worker. You can use {@code request.serviceWorker()} to check that.</li>
* <li> When navigation request is issued before the corresponding frame is created. You can use {@link
* Request#isNavigationRequest Request.isNavigationRequest()} to check that.</li>
* </ul>
*
* <p> Here is an example that handles all the cases:
*
* @since v1.8
*/
Frame frame();
@@ -107,9 +91,6 @@ public interface Request {
/**
* Whether this request is driving frame's navigation.
*
* <p> Some navigation requests are issued before the corresponding frame is created, and therefore do not have {@link
* Request#frame Request.frame()} available.
*
* @since v1.8
*/
boolean isNavigationRequest();
@@ -38,9 +38,8 @@ import java.nio.file.Path;
public interface Tracing {
class StartOptions {
/**
* 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.
* 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()}.
*/
public String name;
/**
@@ -67,9 +66,8 @@ public interface Tracing {
public String title;
/**
* 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.
* 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()}.
*/
public StartOptions setName(String name) {
this.name = name;
@@ -112,9 +110,8 @@ public interface Tracing {
}
class StartChunkOptions {
/**
* 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.
* 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()}.
*/
public String name;
/**
@@ -123,9 +120,8 @@ public interface Tracing {
public String title;
/**
* 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.
* 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()}.
*/
public StartChunkOptions setName(String name) {
this.name = name;
@@ -1,47 +0,0 @@
/*
* Copyright (c) Microsoft Corporation.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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;
/**
* {@code WebError} class represents an unhandled exception thrown in the page. It is dispatched via the {@link
* BrowserContext#onWebError BrowserContext.onWebError()} event.
* <pre>{@code
* // Log all uncaught errors to the terminal
* context.onWebError(webError -> {
* System.out.println("Uncaught exception: " + webError.error());
* });
*
* // Navigate to a page with an exception.
* page.navigate("data:text/html,<script>throw new Error('Test')</script>");
* }</pre>
*/
public interface WebError {
/**
* The page that produced this unhandled exception, if any.
*
* @since v1.38
*/
Page page();
/**
* Unhandled error that was thrown.
*
* @since v1.38
*/
String error();
}
@@ -254,24 +254,11 @@ 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}.
*/
@@ -427,8 +414,8 @@ public interface LocatorAssertions {
*/
LocatorAssertions not();
/**
* 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.
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
* DOM node.
*
* <p> **Usage**
* <pre>{@code
@@ -441,8 +428,8 @@ public interface LocatorAssertions {
isAttached(null);
}
/**
* 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.
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
* DOM node.
*
* <p> **Usage**
* <pre>{@code
@@ -671,25 +658,12 @@ public interface LocatorAssertions {
*/
void isInViewport(IsInViewportOptions options);
/**
* 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()}.
* 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.
*
* <p> **Usage**
* <pre>{@code
* // A specific element is visible.
* assertThat(page.getByText("Welcome")).isVisible();
*
* // At least one item in the list is visible.
* asserThat(page.getByTestId("todo-item").first()).isVisible();
*
* // At least one of the two elements is visible, possibly both.
* asserThat(
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
* .first()
* ).isVisible();
* }</pre>
*
* @since v1.20
@@ -698,38 +672,20 @@ public interface LocatorAssertions {
isVisible(null);
}
/**
* 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()}.
* 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.
*
* <p> **Usage**
* <pre>{@code
* // A specific element is visible.
* assertThat(page.getByText("Welcome")).isVisible();
*
* // At least one item in the list is visible.
* asserThat(page.getByTestId("todo-item").first()).isVisible();
*
* // At least one of the two elements is visible, possibly both.
* asserThat(
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
* .first()
* ).isVisible();
* }</pre>
*
* @since v1.20
*/
void isVisible(IsVisibleOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -768,13 +724,8 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -811,13 +762,8 @@ public interface LocatorAssertions {
*/
void containsText(String expected, ContainsTextOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -856,13 +802,8 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -899,13 +840,8 @@ public interface LocatorAssertions {
*/
void containsText(Pattern expected, ContainsTextOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -944,13 +880,8 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -987,13 +918,8 @@ public interface LocatorAssertions {
*/
void containsText(String[] expected, ContainsTextOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -1032,13 +958,8 @@ public interface LocatorAssertions {
containsText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
* value as well.
*
* <p> **Usage**
* <pre>{@code
@@ -1455,13 +1376,8 @@ public interface LocatorAssertions {
*/
void hasJSProperty(String name, Object value, HasJSPropertyOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1500,13 +1416,8 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1543,13 +1454,8 @@ public interface LocatorAssertions {
*/
void hasText(String expected, HasTextOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1588,13 +1494,8 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1631,13 +1532,8 @@ public interface LocatorAssertions {
*/
void hasText(Pattern expected, HasTextOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1676,13 +1572,8 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1719,13 +1610,8 @@ public interface LocatorAssertions {
*/
void hasText(String[] expected, HasTextOptions options);
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1764,13 +1650,8 @@ public interface LocatorAssertions {
hasText(expected, null);
}
/**
* 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.
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
* well.
*
* <p> **Usage**
* <pre>{@code
@@ -1,7 +1,8 @@
package com.microsoft.playwright.impl;
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.microsoft.playwright.APIRequestContext;
import com.microsoft.playwright.APIResponse;
import com.microsoft.playwright.PlaywrightException;
@@ -10,7 +11,6 @@ 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,14 +85,11 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
byte[] bytes = null;
if (options.data instanceof byte[]) {
bytes = (byte[]) options.data;
} else if (options.data instanceof String) {
String stringData = (String) options.data;
if (!isJsonContentType(options.headers) || isJsonParsable(stringData)) {
bytes = (stringData).getBytes(StandardCharsets.UTF_8);
}
} else if (options.data instanceof String && !isJsonContentType(options.headers)) {
bytes = ((String) options.data).getBytes(StandardCharsets.UTF_8);
}
if (bytes == null) {
params.addProperty("jsonData", gson().toJson(options.data));
params.add("jsonData", gson().toJsonTree(options.data));
} else {
String base64 = Base64.getEncoder().encodeToString(bytes);
params.addProperty("postData", base64);
@@ -205,21 +202,4 @@ 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,6 +34,9 @@ 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,8 +51,6 @@ 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");
@@ -84,7 +82,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
CONSOLE,
DIALOG,
PAGE,
WEBERROR,
REQUEST,
REQUESTFAILED,
REQUESTFINISHED,
@@ -117,16 +114,6 @@ 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);
@@ -167,16 +154,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
listeners.remove(EventType.PAGE, handler);
}
@Override
public void onWebError(Consumer<WebError> handler) {
listeners.add(EventType.WEBERROR, handler);
}
@Override
public void offWebError(Consumer<WebError> handler) {
listeners.remove(EventType.WEBERROR, handler);
}
@Override
public void onRequest(Consumer<Request> handler) {
listeners.add(EventType.REQUEST, handler);
@@ -254,8 +231,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
}
@Override
public void close(CloseOptions options) {
withLogging("BrowserContext.close", () -> closeImpl(options));
public void close() {
withLogging("BrowserContext.close", () -> closeImpl());
}
@Override
@@ -263,13 +240,9 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
}
private void closeImpl(CloseOptions options) {
private void closeImpl() {
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());
@@ -291,8 +264,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
}
artifact.delete();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
sendMessage("close", params);
sendMessage("close");
}
runUntil(() -> {}, closePromise);
}
@@ -568,14 +540,6 @@ 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);
@@ -619,7 +583,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
@Override
public R get() {
throw new TargetClosedError(effectiveCloseReason());
throw new PlaywrightException("Context closed");
}
}
@@ -681,7 +645,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
}
} else if ("route".equals(event)) {
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
route.browserContext = this;
handleRoute(route);
} else if ("page".equals(event)) {
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
@@ -697,7 +660,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
bindingCall.call(binding);
}
} else if ("console".equals(event)) {
ConsoleMessageImpl message = new ConsoleMessageImpl(connection, params);
String guid = params.getAsJsonObject("message").get("guid").getAsString();
ConsoleMessageImpl message = connection.getExistingObject(guid);
listeners.notify(BrowserContextImpl.EventType.CONSOLE, message);
PageImpl page = message.page();
if (page != null) {
@@ -746,25 +710,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
page.listeners.notify(PageImpl.EventType.RESPONSE, response);
}
} else if ("pageError".equals(event)) {
SerializedError error = gson().fromJson(params.getAsJsonObject("error"), SerializedError.class);
String errorStr = "";
if (error.error != null) {
errorStr = error.error.name + ": " + error.error.message;
if (error.error.stack != null && !error.error.stack.isEmpty()) {
errorStr += "\n" + error.error.stack;
}
}
PageImpl page;
try {
page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
} catch (PlaywrightException e) {
page = null;
}
listeners.notify(BrowserContextImpl.EventType.WEBERROR, new WebErrorImpl(page, errorStr));
if (page != null) {
page.listeners.notify(PageImpl.EventType.PAGEERROR, errorStr);
}
} else if ("close".equals(event)) {
didClose();
}
@@ -777,10 +722,9 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
listeners.notify(EventType.CLOSE, this);
}
WritableStream createTempFile(String name, long lastModifiedMs) {
WritableStream createTempFile(String name) {
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,7 +42,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
BrowserTypeImpl browserType;
BrowserType.LaunchOptions launchOptions;
private Path tracePath;
String closeReason;
enum EventType {
DISCONNECTED,
@@ -68,15 +67,11 @@ class BrowserImpl extends ChannelOwner implements Browser {
}
@Override
public void close(CloseOptions options) {
withLogging("Browser.close", () -> closeImpl(options));
public void close() {
withLogging("Browser.close", () -> closeImpl());
}
private void closeImpl(CloseOptions options) {
if (options == null) {
options = new CloseOptions();
}
closeReason = options.reason;
private void closeImpl() {
if (isConnectedOverWebSocket) {
try {
connection.close();
@@ -188,7 +183,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
}
if (options.recordVideoDir != null) {
JsonObject recordVideo = new JsonObject();
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
recordVideo.addProperty("dir", options.recordVideoDir.toString());
if (options.recordVideoSize != null) {
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
}
@@ -208,10 +203,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
params.addProperty("noDefaultViewport", true);
}
}
params.remove("acceptDownloads");
if (options.acceptDownloads != null) {
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
}
JsonElement result = sendMessage("newContext", params);
BrowserContextImpl context = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("context").get("guid").getAsString());
context.videosDir = options.recordVideoDir;
@@ -33,6 +33,8 @@ import static com.microsoft.playwright.impl.Serialization.gson;
import static com.microsoft.playwright.impl.Utils.convertType;
class BrowserTypeImpl extends ChannelOwner implements BrowserType {
LocalUtils localUtils;
BrowserTypeImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
super(parent, type, guid, initializer);
}
@@ -201,7 +203,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
}
if (options.recordVideoDir != null) {
JsonObject recordVideo = new JsonObject();
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
recordVideo.addProperty("dir", options.recordVideoDir.toString());
if (options.recordVideoSize != null) {
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
}
@@ -221,10 +223,6 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
params.addProperty("noDefaultViewport", true);
}
}
params.remove("acceptDownloads");
if (options.acceptDownloads != null) {
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
}
JsonObject json = sendMessage("launchPersistentContext", params).getAsJsonObject();
BrowserContextImpl context = connection.getExistingObject(json.getAsJsonObject("context").get("guid").getAsString());
context.videosDir = options.recordVideoDir;
@@ -18,11 +18,11 @@ package com.microsoft.playwright.impl;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.microsoft.playwright.PlaywrightException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -34,7 +34,6 @@ class ChannelOwner extends LoggingSupport {
final String type;
final String guid;
final JsonObject initializer;
private boolean wasCollected;
protected ChannelOwner(ChannelOwner parent, String type, String guid, JsonObject initializer) {
this(parent.connection, parent, type, guid, initializer);
@@ -58,16 +57,15 @@ class ChannelOwner extends LoggingSupport {
}
}
void disposeChannelOwner(boolean wasGarbageCollected) {
void disconnect() {
// Clean up from parent and connection.
if (parent != null) {
parent.objects.remove(guid);
}
connection.unregisterObject(guid);
wasCollected = wasGarbageCollected;
// Dispose all children.
for (ChannelOwner child : new ArrayList<>(objects.values())) {
child.disposeChannelOwner(wasGarbageCollected);
child.disconnect();
}
objects.clear();
}
@@ -93,7 +91,6 @@ class ChannelOwner extends LoggingSupport {
}
WaitableResult<JsonElement> sendMessageAsync(String method, JsonObject params) {
checkNotCollected();
return connection.sendMessageAsync(guid, method, params);
}
@@ -102,15 +99,9 @@ class ChannelOwner extends LoggingSupport {
}
JsonElement sendMessage(String method, JsonObject params) {
checkNotCollected();
return connection.sendMessage(guid, method, params);
}
private void checkNotCollected() {
if (wasCollected)
throw new PlaywrightException("The object has been collected to prevent unbounded heap growth.");
}
<T> T runUntil(Runnable code, Waitable<T> waitable) {
try {
code.run();
@@ -25,9 +25,7 @@ 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;
@@ -40,7 +38,6 @@ class Message {
JsonObject params;
JsonElement result;
SerializedError error;
JsonArray log;
@Override
public String toString() {
@@ -209,30 +206,6 @@ 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) {
@@ -245,18 +218,12 @@ 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 + callLog));
} else if ("Expect".equals(message.error.error.name)) {
callback.complete(message.result);
callback.completeExceptionally(new PlaywrightException(message.error.toString()));
} else if ("TimeoutError".equals(message.error.error.name)) {
callback.completeExceptionally(new TimeoutError(message.error.error + callLog));
} else if ("TargetClosedError".equals(message.error.error.name)) {
callback.completeExceptionally(new TargetClosedError(message.error.error + callLog));
callback.completeExceptionally(new TimeoutError(message.error.error.toString()));
} else {
callback.completeExceptionally(new DriverException(message.error.error + callLog));
callback.completeExceptionally(new DriverException(message.error.error));
}
}
return;
@@ -285,8 +252,7 @@ public class Connection {
return;
}
if (message.method.equals("__dispose__")) {
boolean wasCollected = message.params.has("reason") && "gc".equals(message.params.get("reason").getAsString());
object.disposeChannelOwner(wasCollected);
object.disconnect();
return;
}
object.handleEvent(message.method, message.params);
@@ -327,6 +293,9 @@ public class Connection {
case "BrowserContext":
result = new BrowserContextImpl(parent, type, guid, initializer);
break;
case "ConsoleMessage":
result = new ConsoleMessageImpl(parent, type, guid, initializer);
break;
case "Dialog":
result = new DialogImpl(parent, type, guid, initializer);
break;
@@ -27,20 +27,17 @@ import java.util.List;
import static com.microsoft.playwright.impl.Serialization.gson;
public class ConsoleMessageImpl implements ConsoleMessage {
private final Connection connection;
public class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
private PageImpl page;
private final JsonObject initializer;
public ConsoleMessageImpl(Connection connection, JsonObject initializer) {
this.connection = connection;
public ConsoleMessageImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
super(parent, type, guid, initializer);
// Note: currently, we only report console messages for pages and they always have a page.
// However, in the future we might report console messages for service workers or something else,
// where page() would be null.
if (initializer.has("page")) {
page = connection.getExistingObject(initializer.getAsJsonObject("page").get("guid").getAsString());
}
this.initializer = initializer;
}
public String type() {
@@ -22,7 +22,7 @@ import java.io.PrintStream;
import java.io.PrintWriter;
class DriverException extends PlaywrightException {
DriverException(String error) {
super(error);
DriverException(SerializedError.Error error) {
super(error.toString());
}
}
@@ -28,12 +28,13 @@ 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.addFilePathUploadParams;
import static com.microsoft.playwright.impl.Utils.addLargeFileUploadParams;
import static com.microsoft.playwright.options.ScreenshotType.JPEG;
import static com.microsoft.playwright.options.ScreenshotType.PNG;
@@ -466,12 +467,16 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
if (frame == null) {
throw new Error("Cannot set input files to detached element");
}
if (options == null) {
options = new SetInputFilesOptions();
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);
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
addFilePathUploadParams(files, params, frame.page().context());
sendMessage("setInputFiles", params);
}
@Override
@@ -490,7 +495,7 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
options = new SetInputFilesOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.add("payloads", Serialization.toJsonArray(files));
params.add("files", Serialization.toJsonArray(files));
sendMessage("setInputFiles", params);
}
@@ -761,13 +761,17 @@ public class FrameImpl extends ChannelOwner implements Frame {
}
void setInputFilesImpl(String selector, Path[] files, SetInputFilesOptions options) {
if (options == null) {
options = new SetInputFilesOptions();
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);
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
addFilePathUploadParams(files, params, page.context());
params.addProperty("selector", selector);
sendMessage("setInputFiles", params);
}
@Override
@@ -787,7 +791,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.addProperty("selector", selector);
params.add("payloads", toJsonArray(files));
params.add("files", toJsonArray(files));
sendMessage("setInputFiles", params);
}
@@ -86,14 +86,12 @@ 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);
}
@@ -107,7 +105,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
if (expectedValue instanceof Pattern) {
message += " matching regex";
}
expectImpl("to.have.attribute.value", expectedText, expectedValue, message, commonOptions);
expectImpl("to.have.attribute", expectedText, expectedValue, message, commonOptions);
}
@Override
@@ -436,11 +436,6 @@ class LocatorImpl implements Locator {
frame.press(selector, key, convertType(options, Frame.PressOptions.class).setStrict(true));
}
@Override
public void pressSequentially(String text, PressSequentiallyOptions options) {
type(text, convertType(options, TypeOptions.class));
}
@Override
public byte[] screenshot(ScreenshotOptions options) {
return withElement((h, o) -> h.screenshot(o), convertType(options, ElementHandle.ScreenshotOptions.class));
@@ -5,7 +5,6 @@ import com.microsoft.playwright.options.AriaRole;
import java.util.regex.Pattern;
import static com.microsoft.playwright.impl.Serialization.gson;
import static com.microsoft.playwright.impl.Utils.toJsRegexFlags;
public class LocatorUtils {
@@ -26,7 +25,10 @@ public class LocatorUtils {
}
private static String getByAttributeTextSelector(String attrName, Object value, boolean exact) {
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector(value, exact) + "]";
if (value instanceof Pattern) {
return "internal:attr=[" + attrName + "=" + toJsRegExp((Pattern) value) + "]";
}
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector((String) value, exact) + "]";
}
static String getByTestIdSelector(Object testId) {
@@ -69,7 +71,14 @@ public class LocatorUtils {
if (options.level != null)
addAttr(result, "level", options.level.toString());
if (options.name != null) {
String name = escapeForAttributeSelector(options.name, options.exact != null && options.exact);
String name;
if (options.name instanceof String) {
name = escapeForAttributeSelector((String) options.name, options.exact != null && options.exact);
} else if (options.name instanceof Pattern) {
name = toJsRegExp((Pattern) options.name);
} else {
throw new IllegalArgumentException("options.name can be String or Pattern, found: " + options.name);
}
addAttr(result, "name", name);
}
if (options.pressed != null)
@@ -78,33 +87,38 @@ public class LocatorUtils {
return result.toString();
}
private static String escapeRegexForSelector(Pattern re) {
// Even number of backslashes followed by the quote -> insert a backslash.
return toJsRegExp(re).replaceAll("(^|[^\\\\])(\\\\\\\\)*([\"'`])", "$1$2\\\\$3").replaceAll(">>", "\\\\>\\\\>");
static String escapeForTextSelector(Object text, boolean exact) {
return escapeForTextSelector(text, exact, false);
}
static String escapeForTextSelector(Object value, boolean exact) {
if (value instanceof Pattern) {
return escapeRegexForSelector((Pattern) value);
private static String escapeForTextSelector(Object param, boolean exact, boolean caseSensitive) {
if (param instanceof Pattern) {
return toJsRegExp((Pattern) param);
}
if (value instanceof String) {
return gson().toJson(value) + (exact ? "s" : "i");
if (!(param instanceof String)) {
throw new IllegalArgumentException("text parameter must be Pattern or String: " + param);
}
throw new IllegalArgumentException("text parameter must be Pattern or String: " + value);
String text = (String) param;
if (exact) {
return '"' + text.replace("\"", "\\\"") + '"';
}
if (text.contains("\"") || text.contains(">>") || text.startsWith("/")) {
return "/" + escapeForRegex(text).replaceAll("\\s+", "\\\\s+") + "/" + (caseSensitive ? "" : "i");
}
return text;
}
private static String escapeForAttributeSelector(Object value, boolean exact) {
if (value instanceof Pattern) {
return escapeRegexForSelector((Pattern) value);
}
if (value instanceof String) {
// TODO: this should actually be
// cssEscape(value).replace(/\\ /g, ' ')
// However, our attribute selectors do not conform to CSS parsing spec,
// so we escape them differently.
return '"' + ((String) value).replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i");
}
throw new IllegalArgumentException("Attribute can be String or Pattern, found: " + value);
private static String escapeForRegex(String text) {
return text.replaceAll("[.*+?^>${}()|\\[\\]\\\\]", "\\\\\\\\$0");
}
private static String escapeForAttributeSelector(String value, boolean exact) {
// TODO: this should actually be
// cssEscape(value).replace(/\\ /g, ' ')
// However, our attribute selectors do not conform to CSS parsing spec,
// so we escape them differently.
return '"' + value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i");
}
private static String toJsRegExp(Pattern pattern) {
@@ -68,7 +68,6 @@ public class PageImpl extends ChannelOwner implements Page {
private final TimeoutSettings timeoutSettings;
private VideoImpl video;
private final PageImpl opener;
private String closeReason;
enum EventType {
CLOSE,
@@ -172,7 +171,6 @@ public class PageImpl extends ChannelOwner implements Page {
listeners.notify(EventType.FRAMEDETACHED, frame);
} else if ("route".equals(event)) {
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
route.browserContext = browserContext;
Router.HandleResult handled = routes.handle(route);
if (handled != Router.HandleResult.NoMatchingHandler) {
updateInterceptionPatterns();
@@ -184,6 +182,16 @@ public class PageImpl extends ChannelOwner implements Page {
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
forceVideo().setArtifact(artifact);
} else if ("pageError".equals(event)) {
SerializedError error = gson().fromJson(params.getAsJsonObject("error"), SerializedError.class);
String errorStr = "";
if (error.error != null) {
errorStr = error.error.name + ": " + error.error.message;
if (error.error.stack != null && !error.error.stack.isEmpty()) {
errorStr += "\n" + error.error.stack;
}
}
listeners.notify(EventType.PAGEERROR, errorStr);
} else if ("crash".equals(event)) {
listeners.notify(EventType.CRASH, this);
} else if ("close".equals(event)) {
@@ -201,13 +209,6 @@ 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);
@@ -496,7 +497,6 @@ public class PageImpl extends ChannelOwner implements Page {
if (options == null) {
options = new CloseOptions();
}
closeReason = options.reason;
try {
if (ownedContext != null) {
ownedContext.close();
@@ -1226,14 +1226,6 @@ 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);
@@ -1358,7 +1350,7 @@ public class PageImpl extends ChannelOwner implements Page {
@Override
public T get() {
throw new TargetClosedError(effectiveCloseReason());
throw new PlaywrightException("Page closed");
}
}
@@ -1369,7 +1361,7 @@ public class PageImpl extends ChannelOwner implements Page {
@Override
public T get() {
throw new TargetClosedError("Page crashed");
throw new PlaywrightException("Page crashed");
}
}
@@ -63,6 +63,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
private final BrowserTypeImpl webkit;
private final SelectorsImpl selectors;
private final APIRequestImpl apiRequest;
private final LocalUtils localUtils;
private SharedSelectors sharedSelectors;
PlaywrightImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
@@ -73,6 +74,10 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
selectors = connection.getExistingObject(initializer.getAsJsonObject("selectors").get("guid").getAsString());
apiRequest = new APIRequestImpl(this);
localUtils = connection.getExistingObject(initializer.getAsJsonObject("utils").get("guid").getAsString());
chromium.localUtils = localUtils;
firefox.localUtils = localUtils;
webkit.localUtils = localUtils;
}
void initSharedSelectors(PlaywrightImpl parent) {
@@ -47,10 +47,6 @@ class SerializedValue{
Number h;
Integer id;
Integer ref;
// JS representation of Map: [[key1, value1], [key2, value2], ...].
SerializedValue m;
// JS representation of Set: [item1, item2, ...].
SerializedValue se;
}
class SerializedArgument{
@@ -78,13 +78,7 @@ public class RequestImpl extends ChannelOwner implements Request {
@Override
public FrameImpl frame() {
FrameImpl frame = connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
if (frame.page == null) {
throw new PlaywrightException("Frame for this navigation request is not available, because the request\n" +
"was issued before the frame is created. You can check whether the request\n" +
"is a navigation request by calling isNavigationRequest() method.");
}
return frame;
return connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
}
@Override
@@ -32,7 +32,7 @@ import static com.microsoft.playwright.impl.Utils.convertType;
public class RouteImpl extends ChannelOwner implements Route {
private final RequestImpl request;
private boolean handled;
BrowserContextImpl browserContext;
boolean fallbackCalled;
boolean shouldResumeIfFallbackIsCalled;
@@ -99,7 +99,7 @@ public class RouteImpl extends ChannelOwner implements Route {
if (fetchOptions != null && fetchOptions.timeout != null) {
options.timeout = fetchOptions.timeout;
}
APIRequestContextImpl apiRequest = browserContext.request();
APIRequestContextImpl apiRequest = request.frame().page().context().request();
String url = (fetchOptions == null || fetchOptions.url == null) ? request().url() : fetchOptions.url;
return apiRequest.fetch(url, options);
}
@@ -66,8 +66,8 @@ class Router {
.collect(Collectors.toList());
}
void removeAll() {
routes.clear();
int size() {
return routes.size();
}
enum HandleResult { NoMatchingHandler, Handled, Fallback, PendingHandler }
@@ -280,16 +280,6 @@ class Serialization {
}
return (T) map;
}
if (value.m != null) {
Map<?, ?> map = new LinkedHashMap<>();
idToValue.put(value.id, map);
return (T) map;
}
if (value.se != null) {
Map<?, ?> map = new LinkedHashMap<>();
idToValue.put(value.id, map);
return (T) map;
}
throw new PlaywrightException("Unexpected result: " + gson().toJson(value));
}
@@ -1,29 +0,0 @@
/*
* 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");
}
}
@@ -77,8 +77,19 @@ class TracingImpl extends ChannelOwner implements Tracing {
connection.localUtils.zip(path, new JsonArray(), stacksId, true, includeSources);
}
@Override
public void start(StartOptions options) {
withLogging("Tracing.start", () -> startImpl(options));
}
@Override
public void startChunk(StartChunkOptions options) {
withLogging("Tracing.startChunk", () -> {
startChunkImpl(options);
});
}
private void startChunkImpl(StartChunkOptions options) {
if (options == null) {
options = new StartChunkOptions();
}
@@ -105,8 +116,7 @@ class TracingImpl extends ChannelOwner implements Tracing {
stacksId = connection.localUtils().tracingStarted(tracesDir == null ? null : tracesDir.toString(), traceName);
}
@Override
public void start(StartOptions options) {
private void startImpl(StartOptions options) {
if (options == null) {
options = new StartOptions();
}
@@ -121,13 +131,17 @@ class TracingImpl extends ChannelOwner implements Tracing {
@Override
public void stop(StopOptions options) {
stopChunkImpl(options == null ? null : options.path);
sendMessage("tracingStop");
withLogging("Tracing.stop", () -> {
stopChunkImpl(options == null ? null : options.path);
sendMessage("tracingStop");
});
}
@Override
public void stopChunk(StopChunkOptions options) {
stopChunkImpl(options == null ? null : options.path);
withLogging("Tracing.stopChunk", () -> {
stopChunkImpl(options == null ? null : options.path);
});
}
void setTracesDir(Path tracesDir) {
@@ -18,9 +18,11 @@ 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;
@@ -30,7 +32,6 @@ 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;
@@ -173,21 +174,26 @@ class Utils {
return mimeType;
}
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) {
static final int maxUplodBufferSize = 50 * 1024 * 1024;
static boolean hasLargeFile(Path[] files) {
int totalSize = 0;
for (Path file: files) {
try {
totalSize += Files.size(file);
} catch (IOException e) {
throw new PlaywrightException("Cannot get file size.", e);
}
}
return totalSize > maxUplodBufferSize;
}
static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
if (context.connection.isRemote) {
List<WritableStream> streams = new ArrayList<>();
JsonArray jsonStreams = new JsonArray();
for (Path path : files) {
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);
WritableStream temp = context.createTempFile(path.getFileName().toString());
streams.add(temp);
try (OutputStream out = temp.stream()) {
Files.copy(path, out);
@@ -210,11 +216,11 @@ class Utils {
}
static void checkFilePayloadSize(FilePayload[] files) {
long totalSize = 0;
int totalSize = 0;
for (FilePayload file: files) {
totalSize += file.buffer.length;
}
if (totalSize > 50 * 1024 * 1024) {
if (totalSize > maxUplodBufferSize) {
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
}
}
@@ -1,23 +0,0 @@
package com.microsoft.playwright.impl;
import com.microsoft.playwright.WebError;
public class WebErrorImpl implements WebError {
private final PageImpl page;
private final String error;
WebErrorImpl(PageImpl page, String error) {
this.page = page;
this.error = error;
}
@Override
public PageImpl page() {
return page;
}
@Override
public String error() {
return error;
}
}
@@ -28,12 +28,6 @@ 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,19 +42,6 @@ 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.
@@ -63,19 +50,6 @@ 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.
@@ -84,19 +58,6 @@ 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.
@@ -105,19 +66,6 @@ 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.
@@ -126,19 +74,6 @@ 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.
@@ -20,17 +20,10 @@ import org.junit.jupiter.api.*;
import com.microsoft.playwright.options.SameSiteAttribute;
import javax.sql.rowset.Predicate;
import java.io.IOException;
import java.security.Provider;
import java.time.Duration;
import java.time.Instant;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import static com.microsoft.playwright.Utils.getBrowserNameFromEnv;
import static com.microsoft.playwright.Utils.nextFreePort;
import static org.junit.jupiter.api.Assertions.assertTrue;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class TestBase {
@@ -157,13 +150,6 @@ public class TestBase {
}
}
void waitForCondition(BooleanSupplier predicate) {
waitForCondition(predicate, 5_000);
}
void waitForCondition(BooleanSupplier predicate, int timeoutMs) {
page.waitForCondition(predicate, new Page.WaitForConditionOptions().setTimeout(timeoutMs));
}
private static SameSiteAttribute initSameSiteAttribute() {
if (isChromium()) return SameSiteAttribute.LAX;
if (isWebKit()) return SameSiteAttribute.NONE;
@@ -127,15 +127,4 @@ 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());
}
}
@@ -38,14 +38,6 @@ public class TestBrowserContextAddCookies extends TestBase {
assertEquals("password=123456", page.evaluate("document.cookie"));
}
// Slightly different rounding on chromium win.
private static List<Cookie> normalizeExpires(List<Cookie> cookies) {
for (Cookie cookie: cookies) {
cookie.expires = (double) Math.round(cookie.expires);
}
return cookies;
}
@Test
void shouldRoundtripCookie() {
page.navigate(server.EMPTY_PAGE);
@@ -61,7 +53,7 @@ public class TestBrowserContextAddCookies extends TestBase {
context.clearCookies();
assertEquals(0, context.cookies().size());
context.addCookies(cookies);
assertJsonEquals(normalizeExpires(cookies), normalizeExpires(context.cookies()));
assertJsonEquals(cookies, context.cookies());
}
@Test
@@ -144,7 +144,7 @@ public class TestBrowserContextBasic extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
context.waitForPage(() -> context.close());
});
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
assertTrue(e.getMessage().contains("Context closed"));
}
@Test
@@ -236,17 +236,8 @@ public class TestBrowserContextBasic extends TestBase {
void shouldWorkWithOfflineOption() {
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setOffline(true));
Page page = context.newPage();
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));
}
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
context.setOffline(false);
Response response = page.navigate(server.EMPTY_PAGE);
assertEquals(200, response.status());
@@ -290,16 +281,7 @@ public class TestBrowserContextBasic extends TestBase {
context.close();
return false;
}));
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
assertTrue(e.getMessage().contains("Context 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());
}
}
@@ -7,7 +7,6 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestBrowserContextEvents extends TestBase {
@Test
@@ -157,17 +156,4 @@ public class TestBrowserContextEvents extends TestBase {
page.waitForCondition(() -> "hello".equals(popup.evaluate("window.result")),
new Page.WaitForConditionOptions().setTimeout(5_000));
}
@Test
void pageErrorEventShouldWork() {
WebError[] webError = { null };
context.onWebError(e -> {
webError[0] = e;
});
page.setContent("<script>throw new Error('boom')</script>");
waitForCondition(() -> webError[0] != null);
assertEquals(page, webError[0].page());
assertTrue(webError[0].error().contains("boom"), webError[0].error());
}
}
@@ -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("Target page, context or browser has been closed"), e.getMessage());
assertTrue(e.getMessage().contains("Request context disposed"), 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());
@@ -175,33 +175,17 @@ public class TestBrowserContextProxy extends TestBase {
// @see https://gist.github.com/CollinChaffin/24f6c9652efb3d6d5ef2f5502720ef00
.setBypass("1.non.existent.domain.for.the.test, 2.non.existent.domain.for.the.test, .another.test")));
{
Page page = context.newPage();
page.navigate("http://0.non.existent.domain.for.the.test/target.html");
assertEquals("Served by the proxy", page.title());
page.close();
}
{
Page page = context.newPage();
assertThrows(PlaywrightException.class, () -> page.navigate("http://1.non.existent.domain.for.the.test/target.html"));
page.close();
}
{
Page page = context.newPage();
assertThrows(PlaywrightException.class, () -> page.navigate("http://2.non.existent.domain.for.the.test/target.html"));
page.close();
}
{
Page page = context.newPage();
assertThrows(PlaywrightException.class, () -> page.navigate("http://foo.is.the.another.test/target.html"));
page.close();
}
{
Page page = context.newPage();
page.navigate("http://3.non.existent.domain.for.the.test/target.html");
assertEquals("Served by the proxy", page.title());
page.close();
}
Page page = context.newPage();
page.navigate("http://0.non.existent.domain.for.the.test/target.html");
assertEquals("Served by the proxy", page.title());
assertThrows(PlaywrightException.class, () -> page.navigate("http://1.non.existent.domain.for.the.test/target.html"));
assertThrows(PlaywrightException.class, () -> page.navigate("http://2.non.existent.domain.for.the.test/target.html"));
assertThrows(PlaywrightException.class, () -> page.navigate("http://foo.is.the.another.test/target.html"));
page.navigate("http://3.non.existent.domain.for.the.test/target.html");
assertEquals("Served by the proxy", page.title());
context.close();
}
@@ -28,7 +28,6 @@ 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;
@@ -40,8 +39,6 @@ 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;
@@ -352,7 +349,7 @@ public class TestBrowserTypeConnect extends TestBase {
}
browser.close();
}
@Test
void shouldSaveAsVideosFromRemoteBrowser(@TempDir Path tempDir) {
Path videosPath = tempDir.resolve("videosPath");
@@ -504,17 +501,4 @@ 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,8 +18,6 @@ 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 {
@@ -37,17 +35,6 @@ 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\""), e.getMessage());
assertTrue(e.getMessage().contains("failed to find element matching selector \"section\""));
}
@Test
@@ -19,14 +19,10 @@ 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
@@ -41,6 +37,7 @@ 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(
@@ -52,19 +49,4 @@ 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,14 +246,6 @@ 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>");
@@ -116,11 +116,4 @@ public class TestLocatorMisc extends TestBase{
assertEquals("outer", divLocator.locator("input").inputValue());
assertEquals("inner", page.frameLocator("iframe").locator(divLocator).locator("input").inputValue());
}
@Test
void shouldPressSequentially() {
page.setContent("<input type='text' />");
page.locator("input").pressSequentially("hello");
assertEquals("hello", page.evalOnSelector("input", "input => input.value"));
}
}
@@ -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("Target page, context or browser has been closed"), e2.getMessage());
assertFalse(e2.getMessage().contains("Timeout"), e2.getMessage());
assertTrue(e2.getMessage().contains("Page closed"));
assertFalse(e2.getMessage().contains("Timeout"));
});
});
assertTrue(e1.getMessage().contains("Target page, context or browser has been closed"), e1.getMessage());
assertFalse(e1.getMessage().contains("Timeout"), e1.getMessage());
assertTrue(e1.getMessage().contains("Page closed"));
assertFalse(e1.getMessage().contains("Timeout"));
}
@Test
@@ -336,15 +336,6 @@ public class TestPageBasic extends TestBase {
page.close();
return false;
}));
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());
assertTrue(e.getMessage().contains("Page closed"), 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("no object with guid"), e.getMessage());
assertTrue(e.getMessage().contains("JSHandle is disposed"));
}
@Test
@@ -645,14 +645,4 @@ public class TestPageEvaluate extends TestBase {
assertTrue(object instanceof Date);
assertEquals(Date.from(instant), object);
}
@Test
void shouldTransferMaps() {
assertEquals(mapOf(), page.evaluate("() => new Map([[1, { test: 42n }]])"));
}
@Test
void shouldTransferSets() {
assertEquals(mapOf(), page.evaluate("() => new Set([1, { test: 42n }])"));
}
}
@@ -66,18 +66,17 @@ public class TestPageEventNetwork extends TestBase {
assertTrue(failedRequests.get(0).url().contains("one-style.css"));
assertNull(failedRequests.get(0).response());
assertEquals("stylesheet", failedRequests.get(0).resourceType());
String error = failedRequests.get(0).failure();
if (isChromium()) {
assertEquals("net::ERR_EMPTY_RESPONSE", error);
assertEquals("net::ERR_EMPTY_RESPONSE", failedRequests.get(0).failure());
} else if (isWebKit()) {
if (isMac)
assertEquals("The network connection was lost.", error);
assertEquals("The network connection was lost.", failedRequests.get(0).failure());
else if (isWindows)
assertEquals("Server returned nothing (no headers, no data)", error);
assertEquals("Server returned nothing (no headers, no data)", failedRequests.get(0).failure());
else
assertTrue("Message Corrupt".equals(error) || "Connection terminated unexpectedly".equals(error), error);
assertEquals("Message Corrupt", failedRequests.get(0).failure());
} else {
assertEquals("NS_ERROR_NET_RESET", error);
assertEquals("NS_ERROR_NET_RESET", failedRequests.get(0).failure());
}
assertNotNull(failedRequests.get(0).frame());
}
@@ -1,17 +0,0 @@
package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestPageEventPopup extends TestBase {
@Test
void shouldWorkWithClickingTarget_blank() {
page.navigate(server.EMPTY_PAGE);
page.setContent("<a target=_blank rel='opener' href='/one-style.html'>yo</a>");
Page popup = page.waitForPopup(() -> page.click("a"));
assertEquals(false, page.evaluate("() => !!window.opener"));
assertEquals(true, popup.evaluate("() => !!window.opener"));
assertEquals(popup, popup.mainFrame().page());
}
}
@@ -374,9 +374,21 @@ public class TestPageKeyboard extends TestBase {
JSHandle lastEvent = captureLastKeyDown();
page.keyboard().press("Meta");
LinkedHashMap eventData = (LinkedHashMap) lastEvent.jsonValue();
assertEquals("Meta", eventData.get("key"));
assertEquals("MetaLeft", eventData.get("code"));
assertTrue((Boolean) eventData.get("metaKey"), eventData.toString());
if (isFirefox() && !isMac) {
assertEquals("OS", eventData.get("key"));
} else {
assertEquals("Meta", eventData.get("key"));
}
if (isFirefox()) {
assertEquals("OSLeft", eventData.get("code"));
} else {
assertEquals("MetaLeft", eventData.get("code"));
}
if (isFirefox() && !isMac) {
assertFalse((Boolean) eventData.get("metaKey"), eventData.toString());
} else {
assertTrue((Boolean) eventData.get("metaKey"), eventData.toString());
}
}
@Test
@@ -107,39 +107,6 @@ public class TestPageLocatorQuery extends TestBase {
assertEquals("Hello \"world\"", page.locator("div", new Page.LocatorOptions().setHasText(Pattern.compile("Hello \"world\""))).textContent());
}
@Test
void shouldFilterByRegexWithASingleQuote() {
page.setContent("<button>let's let's<span>hello</span></button>");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let['abc]s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let['abc]s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let's let\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let's let\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\'s let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\'s let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
page.setContent("<button>let\\'s let\\'s<span>hello</span></button>");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\'s let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\'s let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\\\'s let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\\\'s let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
}
@Test
void shouldFilterByRegexAndRegexpFlags() {
page.setContent("<div>Hello \"world\"</div><div>Hello world</div>");
@@ -21,8 +21,6 @@ import com.microsoft.playwright.options.HttpHeader;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -115,23 +113,4 @@ public class TestPageNetworkRequest extends TestBase {
assertEquals("POST", request.method());
assertEquals(403, request.response().status());
}
@Test
void shouldNotAllowToAccessFrameOnPopupMainRequest() {
page.setContent("<a target=_blank href='" + server.EMPTY_PAGE + "'>click me</a>");
Request[] request = { null };
PlaywrightException[] error = { null };
page.context().onRequest(req -> {
request[0] = req;
try {
req.frame();
} catch (PlaywrightException e) {
error[0] = e;
}
});
page.getByText("click me").click();
waitForCondition(() -> request[0] != null);
assertTrue(request[0].isNavigationRequest());
assertTrue(error[0].getMessage().contains("Frame for this navigation request is not available"), error[0].getMessage());
}
}
@@ -1,18 +0,0 @@
package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestPageRequestIntercept extends TestBase {
@Test
void shouldFulfillPopupMainRequestUsingAlias() {
page.context().route("**/*", route -> {
APIResponse response = route.fetch();
route.fulfill(new Route.FulfillOptions().setResponse(response).setBody("hello" ));
});
page.setContent("<a target=_blank href='" + server.EMPTY_PAGE + "'>click me</a>");
Page popup = page.waitForPopup(() -> page.getByText("click me").click());
assertThat(popup.locator("body")).hasText("hello");
}
}
@@ -389,7 +389,7 @@ public class TestPageRoute extends TestBase {
Request r = intercepted.get(1);
for (String url : asList("/one-style.css", "/two-style.css", "/three-style.css", "/four-style.css")) {
assertEquals("stylesheet", r.resourceType());
assertTrue(r.url().contains(url), "actual: " + r.url() + "; expected: " + url);
assertTrue(r.url().contains(url));
r = r.redirectedTo();
}
assertNull(r);
@@ -28,10 +28,7 @@ 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;
@@ -252,40 +249,4 @@ 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"));
}
}
@@ -21,13 +21,11 @@ import com.microsoft.playwright.options.FilePayload;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.platform.commons.support.AnnotationSupport;
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;
@@ -36,10 +34,8 @@ 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;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.*;
@@ -149,7 +145,8 @@ public class TestPageSetInputFiles extends TestBase {
" return events;\n" +
" }");
Path relativeUploadPath = relativePathOrSkipTest(uploadFile);
Path cwd = Paths.get("").toAbsolutePath();
Path relativeUploadPath = cwd.relativize(uploadFile);
assertFalse(relativeUploadPath.isAbsolute());
input.setInputFiles(relativeUploadPath);
assertEquals("200MB.zip", input.evaluate("e => e.files[0].name"));
@@ -308,18 +305,7 @@ public class TestPageSetInputFiles extends TestBase {
assertEquals("file-to-upload.txt", page.evalOnSelector("input", "input => input.files[0].name"));
}
@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
// @Test
void shouldDetectMimeType() throws ExecutionException, InterruptedException {
// TODO: Parse form fields on server
}
@@ -416,18 +402,5 @@ 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));
}
}
@@ -153,25 +153,6 @@ public class TestSelectorsGetBy extends TestBase {
assertThat(page.getByTitle("my title", new Page.GetByTitleOptions().setExact(true))).hasCount(1, new LocatorAssertions.HasCountOptions().setTimeout(500));
assertThat(page.getByTitle("my t\\itle", new Page.GetByTitleOptions().setExact(true))).hasCount(0, new LocatorAssertions.HasCountOptions().setTimeout(500));
assertThat(page.getByTitle("my t\\\\itle", new Page.GetByTitleOptions().setExact(true))).hasCount(0, new LocatorAssertions.HasCountOptions().setTimeout(500));
page.setContent("<label for=target>foo &gt;&gt; bar</label><input id=target>");
page.evalOnSelector("input", "input => {\n" +
" input.setAttribute('placeholder', 'foo >> bar');\n" +
" input.setAttribute('title', 'foo >> bar');\n" +
" input.setAttribute('alt', 'foo >> bar');\n" +
" }");
assertEquals("foo >> bar", page.getByText("foo >> bar").textContent());
assertThat(page.locator("label")).hasText("foo >> bar");
assertThat(page.getByText("foo >> bar")).hasText("foo >> bar");
assertEquals("foo >> bar", page.getByText(Pattern.compile("foo >> bar")).textContent());
assertThat(page.getByLabel("foo >> bar")).hasAttribute("id", "target");
assertThat(page.getByLabel(Pattern.compile("foo >> bar"))).hasAttribute("id", "target");
assertThat(page.getByPlaceholder("foo >> bar")).hasAttribute("id", "target");
assertThat(page.getByAltText("foo >> bar")).hasAttribute("id", "target");
assertThat(page.getByTitle("foo >> bar")).hasAttribute("id", "target");
assertThat(page.getByPlaceholder(Pattern.compile("foo >> bar"))).hasAttribute("id", "target");
assertThat(page.getByAltText(Pattern.compile("foo >> bar"))).hasAttribute("id", "target");
assertThat(page.getByTitle(Pattern.compile("foo >> bar"))).hasAttribute("id", "target");
}
@Test
@@ -9,18 +9,6 @@ import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestSelectorsText extends TestBase {
@Test
void shouldWorkSmoke() {
page.setContent("<div>Hi&gt;&gt;<span></span></div>");
assertEquals("<span></span>", page.evalOnSelector("text=\"Hi>>\">>span", "e => e.outerHTML"));
assertEquals("<span></span>", page.evalOnSelector("text=/Hi\\>\\>/ >> span", "e => e.outerHTML"));
page.setContent("<div>let's<span>hello</span></div>");
assertEquals("<span>hello</span>", page.evalOnSelector("text=/let's/i >> span", "e => e.outerHTML"));
assertEquals("<span>hello</span>", page.evalOnSelector("text=/let\'s/i >> span", "e => e.outerHTML"));
}
@Test
void hasTextAndInternalTextShouldMatchFullNodeTextInStrictMode() {
page.setContent("<div id=div1>hello<span>world</span></div>\n" +
@@ -1,33 +0,0 @@
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());
}
}
@@ -1,24 +0,0 @@
package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.nio.file.Files;
import java.nio.file.Path;
import static com.microsoft.playwright.Utils.relativePathOrSkipTest;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestVideo extends TestBase {
@Test
void shouldWorkWithRelativePathForRecordVideoDir(@TempDir Path tmpDir) {
Path relativeDir = relativePathOrSkipTest(tmpDir);
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.setRecordVideoSize(320, 240).setRecordVideoDir(relativeDir));
Page page = context.newPage();
Path videoPath = page.video().path();
context.close();
assertTrue(videoPath.isAbsolute(), "videosPath = " + videoPath);
assertTrue(Files.exists(videoPath), "videosPath = " + videoPath);
}
}
@@ -199,7 +199,7 @@ public class TestWebSocket extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
ws.waitForFrameSent(() -> page.close());
});
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
assertTrue(e.getMessage().contains("Page closed"));
}
@Test
@@ -57,7 +57,7 @@ public class TestWorkers extends TestBase {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
workerThisObj.getProperty("self");
});
assertTrue(e.getMessage().contains("Target page, context or browser has been closed") || e.getMessage().contains("Worker was closed"), e.getMessage());
assertTrue(e.getMessage().contains("Target closed") || e.getMessage().contains("Worker was closed"), e.getMessage());
}
@@ -19,13 +19,11 @@ package com.microsoft.playwright;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.junit.jupiter.api.Assumptions;
import java.io.*;
import java.net.ServerSocket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -216,17 +214,4 @@ class Utils {
static String generateDifferentOriginPort(final Server server){
return server.PREFIX.replace(String.valueOf(server.PORT), String.valueOf(server.PORT+1));
}
static Path relativePathOrSkipTest(Path path) {
Path cwd = Paths.get("").toAbsolutePath();
try {
return cwd.relativize(path.toAbsolutePath());
} catch (IllegalArgumentException e) {
// May happen on Windows when the path and temp are on different disks.
if (e.getMessage().contains("has different root")) {
Assumptions.assumeTrue(false, "cwd is on another disk, skipping the test.");
}
throw e;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

+1 -2
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>parent-pom</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
<packaging>pom</packaging>
<name>Playwright Parent Project</name>
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
@@ -44,7 +44,6 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>
<gson.version>2.8.9</gson.version>
<junit.version>5.7.0</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+1 -1
View File
@@ -1 +1 @@
1.41.2
1.37.0-beta-1691701681000
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>api-generator</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
<name>Playwright - API Generator</name>
<description>
This is an internal module used to generate Java API from the upstream Playwright
@@ -1156,18 +1156,13 @@ public class ApiGenerator {
File assertionsDir = new File(cwd,"playwright/src/main/java/com/microsoft/playwright/assertions");
System.out.println("Writing assertion files to: " + dir.getCanonicalPath());
generate(api, assertionsDir, "com.microsoft.playwright.assertions", isAssertion().and(isSoftAssertion().negate()));
generate(api, assertionsDir, "com.microsoft.playwright.assertions", isAssertion());
}
private static Predicate<String> isAssertion() {
return className -> className.toLowerCase().contains("assert");
}
// TODO: Remove this predicate once SoftAssertions are implemented.
private static Predicate<String> isSoftAssertion() {
return className -> className.contains("SoftAssertions");
}
private void generate(JsonArray api, File dir, String packageName, Predicate<String> classFilter) throws IOException {
Map<String, TypeDefinition> topLevelTypes = new HashMap<>();
for (JsonElement entry: api) {
+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.41.2</version>
<version>1.37.0</version>
<name>Test Playwright Command Line FatJar</name>
<properties>
<compiler.version>1.8</compiler.version>
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-cli-version</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
<name>Test Playwright Command Line Version</name>
<properties>
<compiler.version>1.8</compiler.version>
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-local-installation</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
<name>Test local installation</name>
<description>Runs Playwright test suite (copied from playwright module) against locally cached Playwright</description>
<properties>
+1 -1
View File
@@ -9,7 +9,7 @@
</parent>
<groupId>com.microsoft.playwright</groupId>
<artifactId>test-spring-boot-starter</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
<name>Test Playwright With Spring Boot</name>
<properties>
<spring.version>2.4.3</spring.version>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.microsoft.playwright</groupId>
<artifactId>update-version</artifactId>
<version>1.41.2</version>
<version>1.37.0</version>
<name>Playwright - Update Version in Documentation</name>
<description>
This is an internal module used to update versions in the documentation based on
+1 -1
View File
@@ -24,7 +24,7 @@ RUN apt-get update && \
# Create the pwuser
adduser pwuser
RUN VERSION=3.9.4 && \
RUN VERSION=3.8.8 && \
curl -o - https://archive.apache.org/dist/maven/maven-3/$VERSION/binaries/apache-maven-$VERSION-bin.tar.gz | tar zxfv - -C /opt/ && \
ln -s /opt/apache-maven-$VERSION/bin/mvn /usr/local/bin/
+1 -10
View File
@@ -24,7 +24,7 @@ RUN apt-get update && \
# Create the pwuser
adduser pwuser
RUN VERSION=3.9.4 && \
RUN VERSION=3.8.8 && \
curl -o - https://archive.apache.org/dist/maven/maven-3/$VERSION/binaries/apache-maven-$VERSION-bin.tar.gz | tar zxfv - -C /opt/ && \
ln -s /opt/apache-maven-$VERSION/bin/mvn /usr/local/bin/
@@ -54,13 +54,4 @@ 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