Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f38f97718d | |||
| aa4f9754de | |||
| 7d9d9a2d9d | |||
| db1c899cf6 | |||
| 91e70280a3 | |||
| 5fe5a3e925 | |||
| fb2188cd2a | |||
| fc4a536308 | |||
| 4312a98ae0 | |||
| f629f915de | |||
| 85c5f90029 | |||
| 30778a3b04 | |||
| 25ba8474f4 | |||
| 5394b5d9b3 | |||
| 883487772a | |||
| 4d912193e7 | |||
| 05eb1f1161 | |||
| 2dbfa9d38e | |||
| 86f929aaf0 | |||
| fa75e29fcf | |||
| 7d5953c96e | |||
| 632fba54a5 | |||
| f76af33f52 | |||
| 4204096c24 | |||
| d3495ca511 | |||
| 4b873ec3ad | |||
| 463146ab11 | |||
| f6bc9a8b3d | |||
| 35e3c3653e | |||
| ed63ba4dcf | |||
| 48a92d1a62 | |||
| d219fddc8b | |||
| 7a1bbe23b1 | |||
| 2a047bff9a | |||
| 4e5285950d | |||
| b8a9d888be | |||
| 5a4640fe2a |
@@ -46,15 +46,17 @@ steps:
|
||||
done
|
||||
displayName: 'Create .sha256 files'
|
||||
|
||||
- task: EsrpRelease@2
|
||||
- task: EsrpRelease@4
|
||||
inputs:
|
||||
ConnectedServiceName: 'Playwright-Java-ESRP'
|
||||
ConnectedServiceName: 'Playwright-ESRP'
|
||||
Intent: 'PackageDistribution'
|
||||
ContentType: 'Maven'
|
||||
PackageLocation: './local-build'
|
||||
ContentSource: 'Folder'
|
||||
FolderLocation: './local-build'
|
||||
WaitForReleaseCompletion: true
|
||||
Owners: 'yurys@microsoft.com'
|
||||
Approvers: 'maxschmitt@microsoft.com'
|
||||
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
|
||||
MainPublisher: 'PlaywrightJava'
|
||||
MainPublisher: 'Playwright'
|
||||
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
|
||||
displayName: 'ESRP Release to Maven'
|
||||
|
||||
@@ -11,11 +11,11 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->114.0.5735.35<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->113.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->119.0.6045.9<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->118.0.1<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
* [Usage](#usage)
|
||||
- [Add Maven dependency](#add-maven-dependency)
|
||||
|
||||
@@ -6,8 +6,15 @@
|
||||
* 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
|
||||
```
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver</artifactId>
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>playwright</artifactId>
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface APIRequest {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -100,7 +100,7 @@ public interface APIRequest {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
|
||||
@@ -66,7 +66,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -78,7 +78,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
@@ -130,8 +130,9 @@ public interface Browser extends AutoCloseable {
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
|
||||
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
@@ -141,11 +142,11 @@ public interface Browser extends AutoCloseable {
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -220,13 +221,14 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -234,8 +236,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -255,7 +257,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -270,7 +272,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public NewContextOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -294,7 +296,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -349,7 +351,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public NewContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
@@ -365,8 +367,9 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
|
||||
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public NewContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
@@ -382,14 +385,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public NewContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -399,7 +402,7 @@ public interface Browser extends AutoCloseable {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -532,7 +535,8 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -541,7 +545,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public NewContextOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -555,8 +559,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -566,8 +570,8 @@ public interface Browser extends AutoCloseable {
|
||||
return setViewportSize(new ViewportSize(width, height));
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -588,7 +592,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -600,7 +604,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -615,7 +619,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -642,7 +646,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
@@ -652,8 +656,9 @@ public interface Browser extends AutoCloseable {
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
|
||||
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
@@ -663,11 +668,11 @@ public interface Browser extends AutoCloseable {
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -742,13 +747,14 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -756,8 +762,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -777,7 +783,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -792,7 +798,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public NewPageOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -816,7 +822,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public NewPageOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -871,7 +877,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public NewPageOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
@@ -887,8 +893,9 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
|
||||
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public NewPageOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
@@ -904,14 +911,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public NewPageOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -921,7 +928,7 @@ public interface Browser extends AutoCloseable {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -1054,7 +1061,8 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1063,7 +1071,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public NewPageOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -1077,8 +1085,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -1088,8 +1096,8 @@ public interface Browser extends AutoCloseable {
|
||||
return setViewportSize(new ViewportSize(width, height));
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -1178,6 +1186,14 @@ public interface Browser extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
boolean isConnected();
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP Sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> Returns the newly created browser session.
|
||||
*
|
||||
* @since v1.11
|
||||
*/
|
||||
CDPSession newBrowserCDPSession();
|
||||
/**
|
||||
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
||||
*
|
||||
|
||||
@@ -127,6 +127,16 @@ 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()}.
|
||||
@@ -752,6 +762,26 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
void grantPermissions(List<String> permissions, GrantPermissionsOptions options);
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> Returns the newly created session.
|
||||
*
|
||||
* @param page Target to create new session for. For backwards-compatibility, this parameter is named {@code page}, but it can be a
|
||||
* {@code Page} or {@code Frame} type.
|
||||
* @since v1.11
|
||||
*/
|
||||
CDPSession newCDPSession(Page page);
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> Returns the newly created session.
|
||||
*
|
||||
* @param page Target to create new session for. For backwards-compatibility, this parameter is named {@code page}, but it can be a
|
||||
* {@code Page} or {@code Frame} type.
|
||||
* @since v1.11
|
||||
*/
|
||||
CDPSession newCDPSession(Frame page);
|
||||
/**
|
||||
* Creates a new page in the browser context.
|
||||
*
|
||||
@@ -1096,7 +1126,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
*
|
||||
* <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
@@ -1111,7 +1141,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
*
|
||||
* <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
|
||||
@@ -43,6 +43,26 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface BrowserType {
|
||||
class ConnectOptions {
|
||||
/**
|
||||
* This option exposes network available on the connecting client to the browser being connected to. Consists of a list of
|
||||
* rules separated by comma.
|
||||
*
|
||||
* <p> Available rules:
|
||||
* <ol>
|
||||
* <li> Hostname pattern, for example: {@code example.com}, {@code *.org:99}, {@code x.*.y.com}, {@code *foo.org}.</li>
|
||||
* <li> IP literal, for example: {@code 127.0.0.1}, {@code 0.0.0.0:99}, {@code [::1]}, {@code [0:0::1]:99}.</li>
|
||||
* <li> {@code <loopback>} that matches local loopback interfaces: {@code localhost}, {@code *.localhost}, {@code 127.0.0.1},
|
||||
* {@code [::1]}.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p> Some common examples:
|
||||
* <ol>
|
||||
* <li> {@code "*"} to expose all network.</li>
|
||||
* <li> {@code "<loopback>"} to expose localhost network.</li>
|
||||
* <li> {@code "*.test.internal-domain,*.staging.internal-domain,<loopback>"} to expose test/staging deployments and localhost.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public String exposeNetwork;
|
||||
/**
|
||||
* Additional HTTP headers to be sent with web socket connect request. Optional.
|
||||
*/
|
||||
@@ -57,6 +77,29 @@ public interface BrowserType {
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* This option exposes network available on the connecting client to the browser being connected to. Consists of a list of
|
||||
* rules separated by comma.
|
||||
*
|
||||
* <p> Available rules:
|
||||
* <ol>
|
||||
* <li> Hostname pattern, for example: {@code example.com}, {@code *.org:99}, {@code x.*.y.com}, {@code *foo.org}.</li>
|
||||
* <li> IP literal, for example: {@code 127.0.0.1}, {@code 0.0.0.0:99}, {@code [::1]}, {@code [0:0::1]:99}.</li>
|
||||
* <li> {@code <loopback>} that matches local loopback interfaces: {@code localhost}, {@code *.localhost}, {@code 127.0.0.1},
|
||||
* {@code [::1]}.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p> Some common examples:
|
||||
* <ol>
|
||||
* <li> {@code "*"} to expose all network.</li>
|
||||
* <li> {@code "<loopback>"} to expose localhost network.</li>
|
||||
* <li> {@code "*.test.internal-domain,*.staging.internal-domain,<loopback>"} to expose test/staging deployments and localhost.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public ConnectOptions setExposeNetwork(String exposeNetwork) {
|
||||
this.exposeNetwork = exposeNetwork;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Additional HTTP headers to be sent with web socket connect request. Optional.
|
||||
*/
|
||||
@@ -382,7 +425,7 @@ public interface BrowserType {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -394,7 +437,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -440,7 +483,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -496,7 +539,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
@@ -506,8 +549,9 @@ public interface BrowserType {
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
|
||||
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
@@ -517,7 +561,7 @@ public interface BrowserType {
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
@@ -585,7 +629,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
@@ -596,7 +641,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -608,8 +653,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -637,7 +682,7 @@ public interface BrowserType {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -652,7 +697,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -735,7 +780,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -837,7 +882,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#isMobile">mobile emulation</a>.
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
@@ -853,8 +898,9 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Learn more about emulation in
|
||||
* our <a href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
@@ -870,7 +916,7 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
@@ -1002,7 +1048,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1019,7 +1066,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -1040,8 +1087,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
@@ -1051,8 +1098,8 @@ public interface BrowserType {
|
||||
return setViewportSize(new ViewportSize(width, height));
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the
|
||||
* consistent viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
* The {@code CDPSession} instances are used to talk raw Chrome Devtools Protocol:
|
||||
* <ul>
|
||||
* <li> protocol methods can be called with {@code session.send} method.</li>
|
||||
* <li> protocol events can be subscribed to with {@code session.on} method.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Useful links:
|
||||
* <ul>
|
||||
* <li> Documentation on DevTools Protocol can be found here: <a
|
||||
* href="https://chromedevtools.github.io/devtools-protocol/">DevTools Protocol Viewer</a>.</li>
|
||||
* <li> Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md</li>
|
||||
* <pre>{@code
|
||||
* CDPSession client = page.context().newCDPSession(page);
|
||||
* client.send("Runtime.enable");
|
||||
*
|
||||
* client.on("Animation.animationCreated", (event) -> System.out.println("Animation created!"));
|
||||
*
|
||||
* JsonObject response = client.send("Animation.getPlaybackRate");
|
||||
* double playbackRate = response.get("playbackRate").getAsDouble();
|
||||
* System.out.println("playback rate is " + playbackRate);
|
||||
*
|
||||
* JsonObject params = new JsonObject();
|
||||
* params.addProperty("playbackRate", playbackRate / 2);
|
||||
* client.send("Animation.setPlaybackRate", params);
|
||||
* }</pre>
|
||||
* </ul>
|
||||
*/
|
||||
public interface CDPSession {
|
||||
/**
|
||||
* Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
||||
* send messages.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void detach();
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param method Protocol method name.
|
||||
* @since v1.8
|
||||
*/
|
||||
default JsonObject send(String method) {
|
||||
return send(method, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param method Protocol method name.
|
||||
* @param args Optional method parameters.
|
||||
* @since v1.8
|
||||
*/
|
||||
JsonObject send(String method, JsonObject args);
|
||||
/**
|
||||
* Register an event handler for events with the specified event name. The given handler will be called for every event
|
||||
* with the given name.
|
||||
*
|
||||
* @param eventName CDP event name.
|
||||
* @param handler Event handler.
|
||||
* @since v1.37
|
||||
*/
|
||||
void on(String eventName, Consumer<JsonObject> handler);
|
||||
/**
|
||||
* Unregister an event handler for events with the specified event name. The given handler will not be called anymore for
|
||||
* events with the given name.
|
||||
*
|
||||
* @param eventName CDP event name.
|
||||
* @param handler Event handler.
|
||||
* @since v1.37
|
||||
*/
|
||||
void off(String eventName, Consumer<JsonObject> handler);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public interface ConsoleMessage {
|
||||
/**
|
||||
* The page that produced this console message, if any.
|
||||
*
|
||||
* @since v1.33
|
||||
* @since v1.34
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
|
||||
@@ -84,7 +84,7 @@ public interface Dialog {
|
||||
/**
|
||||
* The page that initiated this dialog, if available.
|
||||
*
|
||||
* @since v1.33
|
||||
* @since v1.34
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
|
||||
@@ -24,14 +24,16 @@ 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 download to start
|
||||
* // Wait for the download to start
|
||||
* Download download = page.waitForDownload(() -> {
|
||||
* page.getByText("Download file").click();
|
||||
* // Perform the action that initiates download
|
||||
* page.getByText("Download file").click();
|
||||
* });
|
||||
* // wait for download to complete
|
||||
* Path path = download.path();
|
||||
*
|
||||
* // Wait for the download process to complete and save the downloaded file somewhere
|
||||
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
|
||||
* }</pre>
|
||||
*/
|
||||
public interface Download {
|
||||
@@ -80,6 +82,11 @@ 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
|
||||
*/
|
||||
|
||||
@@ -602,9 +602,15 @@ public interface ElementHandle extends JSHandle {
|
||||
public ScreenshotCaret caret;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -663,12 +669,21 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -1567,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 ElementHandle#type ElementHandle.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.8
|
||||
@@ -1585,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 ElementHandle#type ElementHandle.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.8
|
||||
@@ -1863,7 +1878,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1894,7 +1909,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1923,7 +1938,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1954,7 +1969,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1983,7 +1998,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2014,7 +2029,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2043,7 +2058,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2074,7 +2089,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2103,7 +2118,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2134,7 +2149,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2163,7 +2178,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2194,7 +2209,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2435,24 +2450,9 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
String textContent();
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.8
|
||||
@@ -2461,24 +2461,9 @@ public interface ElementHandle extends JSHandle {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.8
|
||||
|
||||
@@ -2987,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 Frame#type Frame.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -3006,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 Frame#type Frame.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -4058,7 +4058,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4091,7 +4091,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4122,7 +4122,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4155,7 +4155,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4186,7 +4186,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4219,7 +4219,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4250,7 +4250,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4283,7 +4283,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4314,7 +4314,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4347,7 +4347,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4378,7 +4378,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4411,7 +4411,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4473,7 +4473,9 @@ public interface Frame {
|
||||
*/
|
||||
void setChecked(String selector, boolean checked, SetCheckedOptions options);
|
||||
/**
|
||||
*
|
||||
* This method internally calls <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Document/write">document.write()</a>, inheriting all its specific
|
||||
* characteristics and behaviors.
|
||||
*
|
||||
* @param html HTML markup to assign to the page.
|
||||
* @since v1.8
|
||||
@@ -4482,7 +4484,9 @@ public interface Frame {
|
||||
setContent(html, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This method internally calls <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Document/write">document.write()</a>, inheriting all its specific
|
||||
* characteristics and behaviors.
|
||||
*
|
||||
* @param html HTML markup to assign to the page.
|
||||
* @since v1.8
|
||||
@@ -4673,19 +4677,9 @@ public interface Frame {
|
||||
*/
|
||||
String title();
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -4695,19 +4689,9 @@ public interface Frame {
|
||||
type(selector, text, null);
|
||||
}
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @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.
|
||||
|
||||
@@ -135,7 +135,7 @@ public interface JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* JSHandle handle = page.evaluateHandle("() => ({window, document})");
|
||||
* JSHandle handle = page.evaluateHandle("() => ({ window, document })");
|
||||
* Map<String, JSHandle> properties = handle.getProperties();
|
||||
* JSHandle windowHandle = properties.get("window");
|
||||
* JSHandle documentHandle = properties.get("document");
|
||||
|
||||
@@ -132,7 +132,9 @@ public interface Keyboard {
|
||||
*/
|
||||
void insertText(String text);
|
||||
/**
|
||||
* {@code key} can specify the intended <a
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@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:
|
||||
@@ -175,7 +177,9 @@ public interface Keyboard {
|
||||
press(key, null);
|
||||
}
|
||||
/**
|
||||
* {@code key} can specify the intended <a
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@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:
|
||||
@@ -216,7 +220,11 @@ public interface Keyboard {
|
||||
*/
|
||||
void press(String key, PressOptions options);
|
||||
/**
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* <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.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
@@ -239,7 +247,11 @@ public interface Keyboard {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* <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.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way
|
||||
* to find element(s) on the page at any moment. Locator can be created with the {@link Page#locator Page.locator()}
|
||||
* to find element(s) on the page at any moment. A locator can be created with the {@link Page#locator Page.locator()}
|
||||
* method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
@@ -1388,6 +1388,50 @@ 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
|
||||
@@ -1407,9 +1451,15 @@ public interface Locator {
|
||||
public ScreenshotCaret caret;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -1468,12 +1518,21 @@ public interface Locator {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -2018,7 +2077,7 @@ public interface Locator {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* When locator points to a list of elements, returns array of locators, pointing to respective elements.
|
||||
* When the locator points to a list of elements, this returns an array of locators, pointing to their respective elements.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link Locator#all Locator.all()} does not wait for elements to match the locator, and instead immediately returns
|
||||
* whatever is present in the page. When the list of elements changes dynamically, {@link Locator#all Locator.all()} will
|
||||
@@ -2037,6 +2096,10 @@ 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();
|
||||
@@ -2048,6 +2111,9 @@ 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();
|
||||
@@ -2067,7 +2133,7 @@ public interface Locator {
|
||||
* }</pre>
|
||||
*
|
||||
* @param locator Additional locator to match.
|
||||
* @since v1.33
|
||||
* @since v1.34
|
||||
*/
|
||||
Locator and(Locator locator);
|
||||
/**
|
||||
@@ -2321,6 +2387,10 @@ 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();
|
||||
@@ -2817,7 +2887,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#type Locator.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.14
|
||||
@@ -2844,7 +2914,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#type Locator.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.14
|
||||
@@ -2927,6 +2997,10 @@ 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
|
||||
*/
|
||||
@@ -2936,6 +3010,10 @@ 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
|
||||
*/
|
||||
@@ -3575,6 +3653,10 @@ 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() {
|
||||
@@ -3584,12 +3666,19 @@ 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();
|
||||
@@ -3610,6 +3699,9 @@ 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();
|
||||
@@ -3628,6 +3720,10 @@ 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();
|
||||
@@ -3641,6 +3737,10 @@ 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();
|
||||
@@ -3653,6 +3753,10 @@ 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();
|
||||
@@ -3667,6 +3771,10 @@ 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();
|
||||
@@ -3678,6 +3786,10 @@ 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();
|
||||
@@ -3691,6 +3803,10 @@ 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();
|
||||
@@ -3702,6 +3818,10 @@ 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();
|
||||
@@ -3715,6 +3835,10 @@ 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();
|
||||
@@ -3727,6 +3851,9 @@ 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();
|
||||
@@ -3741,6 +3868,9 @@ 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();
|
||||
@@ -3752,6 +3882,10 @@ 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();
|
||||
@@ -3765,6 +3899,10 @@ 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();
|
||||
@@ -3941,6 +4079,60 @@ 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.
|
||||
*
|
||||
@@ -4838,6 +5030,9 @@ 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() {
|
||||
@@ -4846,27 +5041,16 @@ 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);
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.14
|
||||
@@ -4875,23 +5059,9 @@ public interface Locator {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.14
|
||||
|
||||
@@ -2407,9 +2407,15 @@ public interface Page extends AutoCloseable {
|
||||
public Boolean fullPage;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -2489,12 +2495,21 @@ public interface Page extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -4520,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 Page#type Page.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -4539,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 Page#type Page.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -6186,7 +6201,7 @@ public interface Page extends AutoCloseable {
|
||||
void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* If specified the network requests that are made in the page will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
*
|
||||
* <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
@@ -6201,7 +6216,7 @@ public interface Page extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* If specified the network requests that are made in the page will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
*
|
||||
* <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
@@ -6242,7 +6257,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6275,7 +6290,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6306,7 +6321,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6339,7 +6354,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6370,7 +6385,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6403,7 +6418,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6434,7 +6449,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6467,7 +6482,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6498,7 +6513,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6531,7 +6546,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6562,7 +6577,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6595,7 +6610,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6657,7 +6672,9 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
void setChecked(String selector, boolean checked, SetCheckedOptions options);
|
||||
/**
|
||||
*
|
||||
* This method internally calls <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Document/write">document.write()</a>, inheriting all its specific
|
||||
* characteristics and behaviors.
|
||||
*
|
||||
* @param html HTML markup to assign to the page.
|
||||
* @since v1.8
|
||||
@@ -6666,7 +6683,9 @@ public interface Page extends AutoCloseable {
|
||||
setContent(html, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This method internally calls <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Document/write">document.write()</a>, inheriting all its specific
|
||||
* characteristics and behaviors.
|
||||
*
|
||||
* @param html HTML markup to assign to the page.
|
||||
* @since v1.8
|
||||
@@ -6923,19 +6942,9 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
Touchscreen touchscreen();
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -6945,19 +6954,9 @@ public interface Page extends AutoCloseable {
|
||||
type(selector, text, null);
|
||||
}
|
||||
/**
|
||||
* 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>
|
||||
* @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()}.
|
||||
*
|
||||
* @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.
|
||||
@@ -7819,8 +7818,8 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
ElementHandle waitForSelector(String selector, WaitForSelectorOptions options);
|
||||
/**
|
||||
* The method will block until the codition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the codition.
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
@@ -7832,15 +7831,15 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForCondition(() -> messages.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Codition to wait for.
|
||||
* @param condition Condition to wait for.
|
||||
* @since v1.32
|
||||
*/
|
||||
default void waitForCondition(BooleanSupplier condition) {
|
||||
waitForCondition(condition, null);
|
||||
}
|
||||
/**
|
||||
* The method will block until the codition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the codition.
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
@@ -7852,7 +7851,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForCondition(() -> messages.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Codition to wait for.
|
||||
* @param condition Condition to wait for.
|
||||
* @since v1.32
|
||||
*/
|
||||
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
|
||||
|
||||
@@ -62,6 +62,22 @@ 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();
|
||||
@@ -91,6 +107,9 @@ 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();
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
+66
-40
@@ -40,7 +40,7 @@ public interface LocatorAssertions {
|
||||
class IsAttachedOptions {
|
||||
public Boolean attached;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -49,7 +49,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsAttachedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -59,7 +59,7 @@ public interface LocatorAssertions {
|
||||
class IsCheckedOptions {
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsCheckedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -77,12 +77,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsDisabledOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsDisabledOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -92,7 +92,7 @@ public interface LocatorAssertions {
|
||||
class IsEditableOptions {
|
||||
public Boolean editable;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -101,7 +101,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsEditableOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -110,12 +110,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsEmptyOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsEmptyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -125,7 +125,7 @@ public interface LocatorAssertions {
|
||||
class IsEnabledOptions {
|
||||
public Boolean enabled;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -134,7 +134,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsEnabledOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -143,12 +143,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsFocusedOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsFocusedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -157,12 +157,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsHiddenOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsHiddenOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -176,7 +176,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Double ratio;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -189,7 +189,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsInViewportOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -198,13 +198,13 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsVisibleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
public Boolean visible;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsVisibleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -222,7 +222,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -239,7 +239,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public ContainsTextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -255,12 +255,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasAttributeOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasAttributeOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -269,12 +269,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasClassOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasClassOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -283,12 +283,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasCountOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasCountOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -297,12 +297,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasCSSOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasCSSOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -311,12 +311,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasIdOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasIdOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -325,12 +325,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasJSPropertyOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasJSPropertyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -344,7 +344,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -361,7 +361,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasTextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -377,12 +377,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasValueOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasValueOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -391,12 +391,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasValuesOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasValuesOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -661,9 +661,22 @@ public interface LocatorAssertions {
|
||||
* 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> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
|
||||
*
|
||||
* <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
|
||||
@@ -675,9 +688,22 @@ public interface LocatorAssertions {
|
||||
* 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> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
|
||||
*
|
||||
* <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
|
||||
|
||||
@@ -39,12 +39,12 @@ import java.util.regex.Pattern;
|
||||
public interface PageAssertions {
|
||||
class HasTitleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasTitleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -53,12 +53,12 @@ public interface PageAssertions {
|
||||
}
|
||||
class HasURLOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasURLOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.microsoft.playwright.impl;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
@@ -39,6 +41,20 @@ class ArtifactImpl extends ChannelOwner {
|
||||
return stream.stream();
|
||||
}
|
||||
|
||||
byte[] readAllBytes() {
|
||||
final int bufLen = 1024 * 1024;
|
||||
byte[] buf = new byte[bufLen];
|
||||
int readLen;
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); InputStream stream = createReadStream()) {
|
||||
while ((readLen = stream.read(buf, 0, bufLen)) != -1) {
|
||||
outputStream.write(buf, 0, readLen);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read artifact", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
sendMessage("cancel");
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
CONSOLE,
|
||||
DIALOG,
|
||||
PAGE,
|
||||
WEBERROR,
|
||||
REQUEST,
|
||||
REQUESTFAILED,
|
||||
REQUESTFINISHED,
|
||||
@@ -154,6 +155,16 @@ 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);
|
||||
@@ -214,6 +225,22 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return waitForEventWithTimeout(EventType.PAGE, code, options.predicate, options.timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDPSession newCDPSession(Page page) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.add("page", ((PageImpl) page).toProtocolRef());
|
||||
JsonObject result = sendMessage("newCDPSession", params).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDPSession newCDPSession(Frame frame) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.add("frame", ((FrameImpl) frame).toProtocolRef());
|
||||
JsonObject result = sendMessage("newCDPSession", params).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
withLogging("BrowserContext.close", () -> closeImpl());
|
||||
@@ -445,6 +472,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public void setDefaultNavigationTimeout(double timeout) {
|
||||
setDefaultNavigationTimeoutImpl(timeout);
|
||||
}
|
||||
|
||||
void setDefaultNavigationTimeoutImpl(Double timeout) {
|
||||
withLogging("BrowserContext.setDefaultNavigationTimeout", () -> {
|
||||
timeoutSettings.setDefaultNavigationTimeout(timeout);
|
||||
JsonObject params = new JsonObject();
|
||||
@@ -455,6 +486,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public void setDefaultTimeout(double timeout) {
|
||||
setDefaultTimeoutImpl(timeout);
|
||||
}
|
||||
|
||||
void setDefaultTimeoutImpl(Double timeout) {
|
||||
withLogging("BrowserContext.setDefaultTimeout", () -> {
|
||||
timeoutSettings.setDefaultTimeout(timeout);
|
||||
JsonObject params = new JsonObject();
|
||||
@@ -580,7 +615,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
updateInterceptionPatterns();
|
||||
}
|
||||
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
|
||||
route.resume();
|
||||
route.resume(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,6 +656,7 @@ 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());
|
||||
@@ -636,8 +672,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
bindingCall.call(binding);
|
||||
}
|
||||
} else if ("console".equals(event)) {
|
||||
String guid = params.getAsJsonObject("message").get("guid").getAsString();
|
||||
ConsoleMessageImpl message = connection.getExistingObject(guid);
|
||||
ConsoleMessageImpl message = new ConsoleMessageImpl(connection, params);
|
||||
listeners.notify(BrowserContextImpl.EventType.CONSOLE, message);
|
||||
PageImpl page = message.page();
|
||||
if (page != null) {
|
||||
@@ -686,6 +721,25 @@ 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();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.addHarUrlFilter;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
@@ -42,6 +41,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
private boolean isConnected = true;
|
||||
BrowserTypeImpl browserType;
|
||||
BrowserType.LaunchOptions launchOptions;
|
||||
private Path tracePath;
|
||||
|
||||
enum EventType {
|
||||
DISCONNECTED,
|
||||
@@ -183,7 +183,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
if (options.recordVideoDir != null) {
|
||||
JsonObject recordVideo = new JsonObject();
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toString());
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
|
||||
if (options.recordVideoSize != null) {
|
||||
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
|
||||
}
|
||||
@@ -203,6 +203,10 @@ 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;
|
||||
@@ -231,6 +235,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
if (options == null) {
|
||||
options = new StartTracingOptions();
|
||||
}
|
||||
tracePath = options.path;
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
if (page != null) {
|
||||
params.add("page", ((PageImpl) page).toProtocolRef());
|
||||
@@ -245,7 +250,20 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
|
||||
private byte[] stopTracingImpl() {
|
||||
JsonObject json = sendMessage("stopTracing").getAsJsonObject();
|
||||
return Base64.getDecoder().decode(json.get("binary").getAsString());
|
||||
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject().getAsJsonObject("artifact").get("guid").getAsString());
|
||||
byte[] data = artifact.readAllBytes();
|
||||
artifact.delete();
|
||||
if (tracePath != null) {
|
||||
try {
|
||||
Files.createDirectories(tracePath.getParent());
|
||||
Files.write(tracePath, data);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to write trace file", e);
|
||||
} finally {
|
||||
tracePath = null;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private Page newPageImpl(NewPageOptions options) {
|
||||
@@ -276,6 +294,13 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDPSession newBrowserCDPSession() {
|
||||
JsonObject params = new JsonObject();
|
||||
JsonObject result = sendMessage("newBrowserCDPSession", params).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
private void didClose() {
|
||||
isConnected = false;
|
||||
listeners.notify(EventType.DISCONNECTED, this);
|
||||
|
||||
@@ -33,8 +33,6 @@ 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);
|
||||
}
|
||||
@@ -203,7 +201,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
}
|
||||
if (options.recordVideoDir != null) {
|
||||
JsonObject recordVideo = new JsonObject();
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toString());
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
|
||||
if (options.recordVideoSize != null) {
|
||||
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
|
||||
}
|
||||
@@ -223,6 +221,10 @@ 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;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.CDPSession;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CDPSessionImpl extends ChannelOwner implements CDPSession {
|
||||
private final ListenerCollection<String> listeners = new ListenerCollection<>(new HashMap<>(), this);
|
||||
|
||||
protected CDPSessionImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
void handleEvent(String event, JsonObject parameters) {
|
||||
super.handleEvent(event, parameters);
|
||||
if ("event".equals(event)) {
|
||||
String method = parameters.get("method").getAsString();
|
||||
JsonObject params = parameters.get("params").getAsJsonObject();
|
||||
listeners.notify(method, params);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject send(String method) {
|
||||
return send(method, null);
|
||||
}
|
||||
|
||||
public JsonObject send(String method, JsonObject params) {
|
||||
JsonObject args = new JsonObject();
|
||||
if (params != null) {
|
||||
args.add("params", params);
|
||||
}
|
||||
args.addProperty("method", method);
|
||||
JsonElement response = connection.sendMessage(guid, "send", args);
|
||||
if (response == null) return null;
|
||||
else return response.getAsJsonObject().get("result").getAsJsonObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void on(String event, Consumer<JsonObject> handler) {
|
||||
listeners.add(event, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void off(String event, Consumer<JsonObject> handler) {
|
||||
listeners.remove(event, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
sendMessage("detach");
|
||||
}
|
||||
}
|
||||
@@ -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,6 +34,7 @@ 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);
|
||||
@@ -57,15 +58,16 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
void disposeChannelOwner(boolean wasGarbageCollected) {
|
||||
// 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.disconnect();
|
||||
child.disposeChannelOwner(wasGarbageCollected);
|
||||
}
|
||||
objects.clear();
|
||||
}
|
||||
@@ -91,6 +93,7 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
|
||||
WaitableResult<JsonElement> sendMessageAsync(String method, JsonObject params) {
|
||||
checkNotCollected();
|
||||
return connection.sendMessageAsync(guid, method, params);
|
||||
}
|
||||
|
||||
@@ -99,9 +102,15 @@ 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();
|
||||
|
||||
@@ -252,7 +252,8 @@ public class Connection {
|
||||
return;
|
||||
}
|
||||
if (message.method.equals("__dispose__")) {
|
||||
object.disconnect();
|
||||
boolean wasCollected = message.params.has("reason") && "gc".equals(message.params.get("reason").getAsString());
|
||||
object.disposeChannelOwner(wasCollected);
|
||||
return;
|
||||
}
|
||||
object.handleEvent(message.method, message.params);
|
||||
@@ -293,9 +294,6 @@ 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;
|
||||
@@ -359,6 +357,9 @@ public class Connection {
|
||||
case "WritableStream":
|
||||
result = new WritableStream(parent, type, guid, initializer);
|
||||
break;
|
||||
case "CDPSession":
|
||||
result = new CDPSessionImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
default:
|
||||
throw new PlaywrightException("Unknown type " + type);
|
||||
}
|
||||
|
||||
@@ -27,17 +27,20 @@ import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
public class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
|
||||
public class ConsoleMessageImpl implements ConsoleMessage {
|
||||
private final Connection connection;
|
||||
private PageImpl page;
|
||||
private final JsonObject initializer;
|
||||
|
||||
public ConsoleMessageImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
public ConsoleMessageImpl(Connection connection, JsonObject initializer) {
|
||||
this.connection = connection;
|
||||
// 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() {
|
||||
|
||||
@@ -105,7 +105,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
if (expectedValue instanceof Pattern) {
|
||||
message += " matching regex";
|
||||
}
|
||||
expectImpl("to.have.attribute", expectedText, expectedValue, message, commonOptions);
|
||||
expectImpl("to.have.attribute.value", expectedText, expectedValue, message, commonOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -407,7 +407,7 @@ class LocatorImpl implements Locator {
|
||||
if (other.frame != frame) {
|
||||
throw new PlaywrightException("Locators must belong to the same frame.");
|
||||
}
|
||||
return locator(other.selector, options);
|
||||
return new LocatorImpl(frame, this.selector + " >> internal:chain=" + gson().toJson(other.selector), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -436,6 +436,11 @@ 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,6 +5,7 @@ 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 {
|
||||
@@ -25,10 +26,7 @@ public class LocatorUtils {
|
||||
}
|
||||
|
||||
private static String getByAttributeTextSelector(String attrName, Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return "internal:attr=[" + attrName + "=" + toJsRegExp((Pattern) value) + "]";
|
||||
}
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector((String) value, exact) + "]";
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector(value, exact) + "]";
|
||||
}
|
||||
|
||||
static String getByTestIdSelector(Object testId) {
|
||||
@@ -71,14 +69,7 @@ public class LocatorUtils {
|
||||
if (options.level != null)
|
||||
addAttr(result, "level", options.level.toString());
|
||||
if (options.name != null) {
|
||||
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);
|
||||
}
|
||||
String name = escapeForAttributeSelector(options.name, options.exact != null && options.exact);
|
||||
addAttr(result, "name", name);
|
||||
}
|
||||
if (options.pressed != null)
|
||||
@@ -87,38 +78,33 @@ public class LocatorUtils {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static String escapeForTextSelector(Object text, boolean exact) {
|
||||
return escapeForTextSelector(text, exact, false);
|
||||
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(">>", "\\\\>\\\\>");
|
||||
}
|
||||
|
||||
private static String escapeForTextSelector(Object param, boolean exact, boolean caseSensitive) {
|
||||
if (param instanceof Pattern) {
|
||||
return toJsRegExp((Pattern) param);
|
||||
static String escapeForTextSelector(Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return escapeRegexForSelector((Pattern) value);
|
||||
}
|
||||
if (!(param instanceof String)) {
|
||||
throw new IllegalArgumentException("text parameter must be Pattern or String: " + param);
|
||||
if (value instanceof String) {
|
||||
return gson().toJson(value) + (exact ? "s" : "i");
|
||||
}
|
||||
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;
|
||||
throw new IllegalArgumentException("text parameter must be Pattern or String: " + 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 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 toJsRegExp(Pattern pattern) {
|
||||
|
||||
@@ -171,6 +171,7 @@ 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();
|
||||
@@ -182,16 +183,6 @@ 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)) {
|
||||
@@ -936,7 +927,16 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
@Override
|
||||
public void pause() {
|
||||
withLogging("Page.pause", () -> {
|
||||
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
|
||||
Double defaultNavigationTimeout = browserContext.timeoutSettings.defaultNavigationTimeout();
|
||||
Double defaultTimeout = browserContext.timeoutSettings.defaultTimeout();
|
||||
browserContext.setDefaultNavigationTimeoutImpl(0.0);
|
||||
browserContext.setDefaultTimeoutImpl(0.0);
|
||||
try {
|
||||
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
|
||||
} finally {
|
||||
browserContext.setDefaultNavigationTimeoutImpl(defaultNavigationTimeout);
|
||||
browserContext.setDefaultTimeoutImpl(defaultTimeout);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -946,9 +946,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
private byte[] pdfImpl(PdfOptions options) {
|
||||
if (!browserContext.browser().isChromium()) {
|
||||
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new PdfOptions();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ 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) {
|
||||
@@ -74,10 +73,6 @@ 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) {
|
||||
|
||||
@@ -32,6 +32,7 @@ class SerializedValue{
|
||||
String v;
|
||||
String d;
|
||||
String u;
|
||||
String bi;
|
||||
public static class R {
|
||||
String p;
|
||||
String f;
|
||||
@@ -46,6 +47,10 @@ 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,7 +78,13 @@ public class RequestImpl extends ChannelOwner implements Request {
|
||||
|
||||
@Override
|
||||
public FrameImpl frame() {
|
||||
return connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
|
||||
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;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
@@ -58,9 +58,13 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
|
||||
@Override
|
||||
public void resume(ResumeOptions options) {
|
||||
resume(options, false);
|
||||
}
|
||||
|
||||
void resume(ResumeOptions options, boolean isFallback) {
|
||||
startHandling();
|
||||
applyOverrides(convertType(options, FallbackOptions.class));
|
||||
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume()));
|
||||
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume(), isFallback));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +75,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
}
|
||||
applyOverrides(options);
|
||||
if (shouldResumeIfFallbackIsCalled) {
|
||||
resume();
|
||||
resume(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +99,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
if (fetchOptions != null && fetchOptions.timeout != null) {
|
||||
options.timeout = fetchOptions.timeout;
|
||||
}
|
||||
APIRequestContextImpl apiRequest = request.frame().page().context().request();
|
||||
APIRequestContextImpl apiRequest = browserContext.request();
|
||||
String url = (fetchOptions == null || fetchOptions.url == null) ? request().url() : fetchOptions.url;
|
||||
return apiRequest.fetch(url, options);
|
||||
}
|
||||
@@ -114,7 +118,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
request().applyFallbackOverrides(overrides);
|
||||
}
|
||||
|
||||
private void resumeImpl(RequestImpl.FallbackOverrides options) {
|
||||
private void resumeImpl(RequestImpl.FallbackOverrides options, boolean isFallback) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (options != null) {
|
||||
if (options.url != null) {
|
||||
@@ -132,6 +136,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
}
|
||||
}
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
params.addProperty("isFallback", isFallback);
|
||||
sendMessageAsync("continue", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigInteger;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -162,6 +163,8 @@ class Serialization {
|
||||
result.d = ((LocalDateTime)value).atZone(ZoneId.systemDefault()).toInstant().toString();
|
||||
} else if (value instanceof URL) {
|
||||
result.u = ((URL)value).toString();
|
||||
} else if (value instanceof BigInteger) {
|
||||
result.bi = ((BigInteger)value).toString();
|
||||
} else if (value instanceof Pattern) {
|
||||
result.r = new SerializedValue.R();
|
||||
result.r.p = ((Pattern)value).pattern();
|
||||
@@ -236,6 +239,9 @@ class Serialization {
|
||||
throw new PlaywrightException("Unexpected value: " + value.u, e);
|
||||
}
|
||||
}
|
||||
if (value.bi != null) {
|
||||
return (T) new BigInteger(value.bi);
|
||||
}
|
||||
if (value.d != null)
|
||||
return (T)(Date.from(Instant.parse(value.d)));
|
||||
if (value.r != null)
|
||||
@@ -274,6 +280,16 @@ 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));
|
||||
}
|
||||
|
||||
@@ -330,6 +346,11 @@ class Serialization {
|
||||
}
|
||||
|
||||
static JsonArray toProtocol(Map<String, String> map) {
|
||||
for (String value : map.values()) {
|
||||
if (value == null) {
|
||||
throw new PlaywrightException("Value cannot be null");
|
||||
}
|
||||
}
|
||||
return toNameValueArray(map);
|
||||
}
|
||||
|
||||
@@ -348,7 +369,11 @@ class Serialization {
|
||||
for (Map.Entry<String, ?> e : map.entrySet()) {
|
||||
JsonObject item = new JsonObject();
|
||||
item.addProperty("name", e.getKey());
|
||||
item.add("value", gson().toJsonTree(e.getValue()));
|
||||
if (e.getValue() instanceof FilePayload) {
|
||||
item.add("value", gson().toJsonTree(e.getValue()));
|
||||
} else {
|
||||
item.addProperty("value", "" + e.getValue());
|
||||
}
|
||||
array.add(item);
|
||||
}
|
||||
return array;
|
||||
|
||||
@@ -30,11 +30,18 @@ class TimeoutSettings {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
void setDefaultTimeout(double timeout) {
|
||||
Double defaultTimeout() {
|
||||
return defaultTimeout;
|
||||
}
|
||||
Double defaultNavigationTimeout() {
|
||||
return defaultNavigationTimeout;
|
||||
}
|
||||
|
||||
void setDefaultTimeout(Double timeout) {
|
||||
defaultTimeout = timeout;
|
||||
}
|
||||
|
||||
void setDefaultNavigationTimeout(double timeout) {
|
||||
void setDefaultNavigationTimeout(Double timeout) {
|
||||
defaultNavigationTimeout = timeout;
|
||||
}
|
||||
|
||||
@@ -73,5 +80,4 @@ class TimeoutSettings {
|
||||
}
|
||||
return new WaitableTimeout<>(timeout(timeout));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,19 +77,8 @@ 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();
|
||||
}
|
||||
@@ -116,7 +105,8 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
stacksId = connection.localUtils().tracingStarted(tracesDir == null ? null : tracesDir.toString(), traceName);
|
||||
}
|
||||
|
||||
private void startImpl(StartOptions options) {
|
||||
@Override
|
||||
public void start(StartOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartOptions();
|
||||
}
|
||||
@@ -131,17 +121,13 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
|
||||
@Override
|
||||
public void stop(StopOptions options) {
|
||||
withLogging("Tracing.stop", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
sendMessage("tracingStop");
|
||||
});
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
sendMessage("tracingStop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopChunk(StopChunkOptions options) {
|
||||
withLogging("Tracing.stopChunk", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
});
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
}
|
||||
|
||||
void setTracesDir(Path tracesDir) {
|
||||
|
||||
@@ -89,7 +89,8 @@ class Utils {
|
||||
}
|
||||
|
||||
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('/', '$', '^', '+', '.', '(', ')', '=', '!', '|'));
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('$', '^', '+', '.', '*', '(', ')', '|', '\\', '?', '{', '}', '[', ']'));
|
||||
|
||||
static String globToRegex(String glob) {
|
||||
StringBuilder tokens = new StringBuilder();
|
||||
@@ -97,8 +98,12 @@ class Utils {
|
||||
boolean inGroup = false;
|
||||
for (int i = 0; i < glob.length(); ++i) {
|
||||
char c = glob.charAt(i);
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append("\\").append(c);
|
||||
if (c == '\\' && i + 1 < glob.length()) {
|
||||
char nextChar = glob.charAt(++i);
|
||||
if (escapeGlobChars.contains(nextChar)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(nextChar);
|
||||
continue;
|
||||
}
|
||||
if (c == '*') {
|
||||
@@ -123,6 +128,12 @@ class Utils {
|
||||
case '?':
|
||||
tokens.append('.');
|
||||
break;
|
||||
case '[':
|
||||
tokens.append('[');
|
||||
break;
|
||||
case ']':
|
||||
tokens.append(']');
|
||||
break;
|
||||
case '{':
|
||||
inGroup = true;
|
||||
tokens.append('(');
|
||||
@@ -139,7 +150,11 @@ class Utils {
|
||||
tokens.append("\\").append(c);
|
||||
break;
|
||||
default:
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokens.append('$');
|
||||
@@ -159,19 +174,18 @@ class Utils {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
static final int maxUplodBufferSize = 50 * 1024 * 1024;
|
||||
static final long maxUploadBufferSize = 50 * 1024 * 1024;
|
||||
|
||||
static boolean hasLargeFile(Path[] files) {
|
||||
long totalSize = 0;
|
||||
for (Path file: files) {
|
||||
try {
|
||||
if (Files.size(file)> maxUplodBufferSize) {
|
||||
return true;
|
||||
}
|
||||
totalSize += Files.size(file);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot get file size.", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return totalSize > maxUploadBufferSize;
|
||||
}
|
||||
|
||||
static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
|
||||
@@ -202,10 +216,12 @@ class Utils {
|
||||
}
|
||||
|
||||
static void checkFilePayloadSize(FilePayload[] files) {
|
||||
long totalSize = 0;
|
||||
for (FilePayload file: files) {
|
||||
if (file.buffer.length > maxUplodBufferSize) {
|
||||
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
|
||||
}
|
||||
totalSize += file.buffer.length;
|
||||
}
|
||||
if (totalSize > maxUploadBufferSize) {
|
||||
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,17 @@ 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 {
|
||||
@@ -150,6 +157,13 @@ 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;
|
||||
|
||||
@@ -16,10 +16,14 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.options.BrowserChannel;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -98,4 +102,29 @@ public class TestBrowser extends TestBase {
|
||||
void shouldReturnBrowserType() {
|
||||
assertEquals(browserType, browser.browserType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledIf(value = "com.microsoft.playwright.TestBase#isChromium", disabledReason = "Chrome Devtools Protocol supported by chromium only")
|
||||
void shouldWorkWithNewBrowserCDPSession() {
|
||||
CDPSession session = browser.newBrowserCDPSession();
|
||||
|
||||
JsonElement response = session.send("Browser.getVersion");
|
||||
assertNotNull(response.getAsJsonObject().get("userAgent").toString());
|
||||
|
||||
AtomicReference<Boolean> gotEvent = new AtomicReference<>(false);
|
||||
|
||||
session.on("Target.targetCreated", jsonElement -> {
|
||||
gotEvent.set(true);
|
||||
});
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("discover", true);
|
||||
session.send("Target.setDiscoverTargets", params);
|
||||
|
||||
Page page = browser.newPage();
|
||||
assertTrue(gotEvent.get());
|
||||
page.close();
|
||||
|
||||
session.detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,14 @@ 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);
|
||||
@@ -53,7 +61,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
context.clearCookies();
|
||||
assertEquals(0, context.cookies().size());
|
||||
context.addCookies(cookies);
|
||||
assertJsonEquals(cookies, context.cookies());
|
||||
assertJsonEquals(normalizeExpires(cookies), normalizeExpires(context.cookies()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@EnabledIf(value = "com.microsoft.playwright.TestBase#isChromium", disabledReason = "Chrome Devtools Protocol supported by chromium only")
|
||||
public class TestBrowserContextCDPSession extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldWork() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
cdpSession.send("Runtime.enable");
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("expression", "window.foo = 'bar'");
|
||||
cdpSession.send("Runtime.evaluate", params);
|
||||
|
||||
Object foo = page.evaluate("window['foo']");
|
||||
assertEquals("bar", foo);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSendEvents() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
cdpSession.send("Network.enable");
|
||||
|
||||
List<JsonElement> events = new ArrayList<>();
|
||||
cdpSession.on("Network.requestWillBeSent", events::add);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
|
||||
assertEquals(1, events.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDetachSession() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
cdpSession.send("Runtime.enable");
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("expression", "1 + 2");
|
||||
params.addProperty("returnByValue", true);
|
||||
|
||||
JsonElement evaluateResult = cdpSession.send("Runtime.evaluate", params);
|
||||
assertEquals(3, evaluateResult.getAsJsonObject().getAsJsonObject("result").get("value").getAsInt());
|
||||
|
||||
cdpSession.detach();
|
||||
|
||||
PlaywrightException exception = assertThrows(PlaywrightException.class, () -> {
|
||||
cdpSession.send("Runtime.evaluate", params);
|
||||
});
|
||||
assertTrue(exception.getMessage().contains("Target page, context or browser has been closed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowNiceErrors() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
|
||||
PlaywrightException exception = assertThrows(PlaywrightException.class, () -> {
|
||||
cdpSession.send("ThisCommand.DoesNotExist");
|
||||
});
|
||||
assertTrue(exception.getMessage().contains("'ThisCommand.DoesNotExist' wasn't found"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithMainFrame() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page.mainFrame());
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("expression", "window.foo = 'bar'");
|
||||
cdpSession.send("Runtime.evaluate", params);
|
||||
|
||||
Object foo = page.evaluate("window['foo']");
|
||||
assertEquals("bar", foo);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowIfTargetIsPartOfMain() {
|
||||
page.navigate(server.PREFIX + "/frames/one-frame.html");
|
||||
assertEquals(server.PREFIX + "/frames/one-frame.html", page.frames().get(0).url());
|
||||
assertEquals(server.PREFIX + "/frames/frame.html", page.frames().get(1).url());
|
||||
|
||||
PlaywrightException exception = assertThrows(PlaywrightException.class, () -> {
|
||||
page.context().newCDPSession(page.frames().get(1));
|
||||
});
|
||||
assertTrue(exception.getMessage().contains("This frame does not have a separate CDP session, it is a part of the parent frame's session"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotBreakPageClose() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
CDPSession session = page.context().newCDPSession(page);
|
||||
session.detach();
|
||||
page.close();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDetachWhenPageCloses() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
CDPSession session = page.context().newCDPSession(page);
|
||||
page.close();
|
||||
|
||||
PlaywrightException exception = assertThrows(PlaywrightException.class, session::detach);
|
||||
assertTrue(exception.getMessage().contains("Target page, context or browser has been closed"));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAddMultipleEventListeners() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
cdpSession.send("Network.enable");
|
||||
|
||||
List<JsonObject> events = new ArrayList<>();
|
||||
cdpSession.on("Network.requestWillBeSent", events::add);
|
||||
cdpSession.on("Network.requestWillBeSent", events::add);
|
||||
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(2, events.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRemoveEventListeners() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
cdpSession.send("Network.enable");
|
||||
|
||||
List<JsonObject> events = new ArrayList<>();
|
||||
Consumer<JsonObject> listener1 = events::add;
|
||||
cdpSession.on("Network.requestWillBeSent", listener1);
|
||||
cdpSession.on("Network.requestWillBeSent", events::add);
|
||||
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(2, events.size());
|
||||
|
||||
cdpSession.off("Network.requestWillBeSent", listener1);
|
||||
events.clear();
|
||||
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(1, events.size());
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ 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
|
||||
@@ -156,4 +157,17 @@ 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -511,14 +511,18 @@ public class TestBrowserContextFetch extends TestBase {
|
||||
FormData.create()
|
||||
.set("firstName", "John")
|
||||
.set("lastName", "Doe")
|
||||
.set("age", 30)
|
||||
.set("isMale", true)
|
||||
.set("file", "f.js")));
|
||||
|
||||
assertEquals("POST", req.get().method);
|
||||
assertEquals(asList("application/x-www-form-urlencoded"), req.get().headers.get("content-type"));
|
||||
String body = new String(req.get().postBody);
|
||||
assertTrue(body.contains("firstName=John"));
|
||||
assertTrue(body.contains("lastName=Doe"));
|
||||
assertTrue(body.contains("file=f.js"));
|
||||
assertTrue(body.contains("firstName=John"), body);
|
||||
assertTrue(body.contains("lastName=Doe"), body);
|
||||
assertTrue(body.contains("age=30"), body);
|
||||
assertTrue(body.contains("isMale=true"), body);
|
||||
assertTrue(body.contains("file=f.js"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -526,6 +530,8 @@ public class TestBrowserContextFetch extends TestBase {
|
||||
Map<String, Object> data = mapOf(
|
||||
"firstName", "John",
|
||||
"lastName", "Doe",
|
||||
"age", 30,
|
||||
"isMale", true,
|
||||
"file", mapOf("name", "f.js")
|
||||
);
|
||||
Future<Server.Request> req = server.futureRequest("/empty.html");
|
||||
|
||||
@@ -175,17 +175,33 @@ 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());
|
||||
|
||||
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());
|
||||
|
||||
{
|
||||
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();
|
||||
}
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -116,4 +116,11 @@ 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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.microsoft.playwright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.time.*;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -115,6 +116,12 @@ public class TestPageEvaluate extends TestBase {
|
||||
assertEquals(true, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTransferBigint() {
|
||||
assertEquals(new BigInteger("42", 10), page.evaluate("() => 42n"));
|
||||
assertEquals(new BigInteger("17", 10), page.evaluate("a => a", new BigInteger("17", 10)));
|
||||
}
|
||||
|
||||
// @Test
|
||||
void shouldTransferMapsAsEmptyObjects() {
|
||||
// Not applicable.
|
||||
@@ -638,4 +645,14 @@ 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,17 +66,18 @@ 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", failedRequests.get(0).failure());
|
||||
assertEquals("net::ERR_EMPTY_RESPONSE", error);
|
||||
} else if (isWebKit()) {
|
||||
if (isMac)
|
||||
assertEquals("The network connection was lost.", failedRequests.get(0).failure());
|
||||
assertEquals("The network connection was lost.", error);
|
||||
else if (isWindows)
|
||||
assertEquals("Server returned nothing (no headers, no data)", failedRequests.get(0).failure());
|
||||
assertEquals("Server returned nothing (no headers, no data)", error);
|
||||
else
|
||||
assertEquals("Message Corrupt", failedRequests.get(0).failure());
|
||||
assertTrue("Message Corrupt".equals(error) || "Connection terminated unexpectedly".equals(error), error);
|
||||
} else {
|
||||
assertEquals("NS_ERROR_NET_RESET", failedRequests.get(0).failure());
|
||||
assertEquals("NS_ERROR_NET_RESET", error);
|
||||
}
|
||||
assertNotNull(failedRequests.get(0).frame());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -124,4 +124,15 @@ public class TestPageInterception extends TestBase {
|
||||
page.navigate(server.PREFIX + "/foo");
|
||||
assertTrue(page.content().contains("hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldProperlyHandleCharacterSetsInGlobs() {
|
||||
page.route("**/[a-z]*.html", route -> {
|
||||
APIResponse response = route.fetch(new Route.FetchOptions().setUrl(server.PREFIX + "/one-style.html"));
|
||||
route.fulfill(new Route.FulfillOptions().setResponse(response));
|
||||
});
|
||||
Response response = page.navigate(server.PREFIX + "/empty.html");
|
||||
assertEquals(200, response.status());
|
||||
assertTrue(response.text().contains("one-style.css"), response.text());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,11 +379,7 @@ public class TestPageKeyboard extends TestBase {
|
||||
} else {
|
||||
assertEquals("Meta", eventData.get("key"));
|
||||
}
|
||||
if (isFirefox()) {
|
||||
assertEquals("OSLeft", eventData.get("code"));
|
||||
} else {
|
||||
assertEquals("MetaLeft", eventData.get("code"));
|
||||
}
|
||||
assertEquals("MetaLeft", eventData.get("code"));
|
||||
if (isFirefox() && !isMac) {
|
||||
assertFalse((Boolean) eventData.get("metaKey"), eventData.toString());
|
||||
} else {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -106,6 +107,39 @@ 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>");
|
||||
@@ -207,4 +241,21 @@ public class TestPageLocatorQuery extends TestBase {
|
||||
assertThat(page.locator("div").or(page.locator("article"))).hasText("hello");
|
||||
assertThat(page.locator("span").or(page.locator("article"))).hasText("world");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportLocatorLocatorWithAndOr() {
|
||||
page.setContent("\n" +
|
||||
" <div>one <span>two</span> <button>three</button> </div>\n" +
|
||||
" <span>four</span>\n" +
|
||||
" <button>five</button>\n" +
|
||||
" ");
|
||||
|
||||
assertThat(page.locator("div").locator(page.locator("button"))).hasText(new String[] {"three"});
|
||||
assertThat(page.locator("div").locator(page.locator("button").or(page.locator("span")))).hasText(new String[]{"two", "three"});
|
||||
assertThat(page.locator("button").or(page.locator("span"))).hasText(new String[]{"two", "three", "four", "five"});
|
||||
|
||||
assertThat(page.locator("div").locator(page.locator("button").and(page.getByRole(AriaRole.BUTTON)))).hasText(new String[]{"three"});
|
||||
assertThat(page.locator("button").and(page.getByRole(AriaRole.BUTTON))).hasText(new String[]{"three", "five"});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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;
|
||||
@@ -113,4 +115,34 @@ 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());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowIfRequestWasGCed() {
|
||||
List<Request> requests = new ArrayList<>();
|
||||
page.onRequest(req -> requests.add(req));
|
||||
for (int i = 0; i < 1001; i++) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
}
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> requests.get(0).response());
|
||||
assertEquals("The object has been collected to prevent unbounded heap growth.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,42 @@ public class TestPageRoute extends TestBase {
|
||||
assertEquals(asList(1), intercepted);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportQuestionMarkInGlobPattern() {
|
||||
server.setRoute("/index", exchange -> {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("index-no-hello");
|
||||
}
|
||||
});
|
||||
server.setRoute("/index123hello", exchange -> {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("index123hello");
|
||||
}
|
||||
});
|
||||
|
||||
page.route("**/index?hello", route -> {
|
||||
route.fulfill(new Route.FulfillOptions().setBody("intercepted any character"));
|
||||
});
|
||||
|
||||
page.route("**/index\\?hello", route -> {
|
||||
route.fulfill(new Route.FulfillOptions().setBody("intercepted question mark"));
|
||||
});
|
||||
|
||||
page.navigate(server.PREFIX + "/index?hello");
|
||||
assertTrue(page.content().contains("intercepted question mark"), page.content());
|
||||
|
||||
page.navigate(server.PREFIX + "/index");
|
||||
assertTrue(page.content().contains("index-no-hello"), page.content());
|
||||
|
||||
page.navigate(server.PREFIX + "/index1hello");
|
||||
assertTrue(page.content().contains("intercepted any character"), page.content());
|
||||
|
||||
page.navigate(server.PREFIX + "/index123hello");
|
||||
assertTrue(page.content().contains("index123hello"), page.content());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUnroutePredicate() {
|
||||
List<Integer> intercepted = new ArrayList<>();
|
||||
@@ -353,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));
|
||||
assertTrue(r.url().contains(url), "actual: " + r.url() + "; expected: " + url);
|
||||
r = r.redirectedTo();
|
||||
}
|
||||
assertNull(r);
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.Arrays;
|
||||
import static com.microsoft.playwright.options.ScreenshotAnimations.DISABLED;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
// TODO: suite.skip(browserName === "firefox" && headful");
|
||||
public class TestPageScreenshot extends TestBase {
|
||||
@@ -233,4 +234,19 @@ public class TestPageScreenshot extends TestBase {
|
||||
}
|
||||
assertTrue(hasDifferentScreenshots);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWhenMaskColorIsNotPinkF0F() {
|
||||
page.setViewportSize(500, 500);
|
||||
page.navigate(server.PREFIX + "/grid.html");
|
||||
byte[] screenshot1 = page.screenshot(
|
||||
new Page.ScreenshotOptions()
|
||||
.setMask(asList(page.locator("div").nth(5)))
|
||||
.setMaskColor("#00FF00"));
|
||||
byte[] screenshot2 = page.screenshot(
|
||||
new Page.ScreenshotOptions()
|
||||
.setMask(asList(page.locator("div").nth(5))));
|
||||
assertThrows(AssertionError.class, () -> assertArrayEquals(screenshot1, screenshot2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,6 @@ public class TestPageSetExtraHttpHeaders extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
browser.newContext(new Browser.NewContextOptions().setExtraHTTPHeaders(mapOf("foo", null)));
|
||||
});
|
||||
assertTrue(e.getMessage().contains("expected string, got undefined"));
|
||||
assertTrue(e.getMessage().contains("Value cannot be null"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.platform.commons.support.AnnotationSupport;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
@@ -35,6 +37,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
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.*;
|
||||
|
||||
@@ -96,6 +99,34 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
assertEquals(200 * 1024 * 1024, fields.get(0).content.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUploadMultipleLargeFiles(@TempDir Path tmpDir) throws IOException, ExecutionException, InterruptedException {
|
||||
Assumptions.assumeTrue(3 <= (Runtime.getRuntime().maxMemory() >> 30), "Fails if max heap size is < 3Gb");
|
||||
int filesCount = 10;
|
||||
page.navigate(server.PREFIX + "/input/fileupload-multi.html");
|
||||
Path uploadFile = tmpDir.resolve("50MB_1.zip");
|
||||
String str = String.join("", Collections.nCopies(1024, "A"));
|
||||
|
||||
try (Writer stream = new OutputStreamWriter(Files.newOutputStream(uploadFile))) {
|
||||
for (int i = 0; i < 49 * 1024; i++) {
|
||||
stream.write(str);
|
||||
}
|
||||
}
|
||||
Locator input = page.locator("input[type='file']");
|
||||
List<Path> uploadFiles = new ArrayList<>();
|
||||
uploadFiles.add(uploadFile);
|
||||
for (int i = 1; i < filesCount; i++) {
|
||||
Path dstFile = tmpDir.resolve("50MB_" + i + ".zip");
|
||||
Files.copy(uploadFile, dstFile);
|
||||
uploadFiles.add(dstFile);
|
||||
}
|
||||
FileChooser fileChooser = page.waitForFileChooser(() -> input.click());
|
||||
fileChooser.setFiles(uploadFiles.toArray(new Path[0]));
|
||||
Object filesLen = page.getByRole(AriaRole.TEXTBOX).evaluate("e => e.files.length");
|
||||
assertTrue(fileChooser.isMultiple());
|
||||
assertEquals(filesCount, filesLen);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUploadLargeFileWithRelativePath(@TempDir Path tmpDir) throws IOException, ExecutionException, InterruptedException {
|
||||
Assumptions.assumeTrue(3 <= (Runtime.getRuntime().maxMemory() >> 30), "Fails if max heap size is < 3Gb");
|
||||
@@ -116,8 +147,7 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
" return events;\n" +
|
||||
" }");
|
||||
|
||||
Path cwd = Paths.get("").toAbsolutePath();
|
||||
Path relativeUploadPath = cwd.relativize(uploadFile);
|
||||
Path relativeUploadPath = relativePathOrSkipTest(uploadFile);
|
||||
assertFalse(relativeUploadPath.isAbsolute());
|
||||
input.setInputFiles(relativeUploadPath);
|
||||
assertEquals("200MB.zip", input.evaluate("e => e.files[0].name"));
|
||||
|
||||
@@ -52,6 +52,18 @@ public class TestPdf extends TestBase {
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
|
||||
void shouldThrowInNonChromium() {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
|
||||
assertTrue(e.getMessage().contains("Page.pdf only supported in headless Chromium"));
|
||||
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
|
||||
void correctExceptionWithPersistentContext(@TempDir Path tempDir) {
|
||||
Path profile = tempDir.resolve("profile");
|
||||
try (BrowserContext context = browserType.launchPersistentContext(profile)) {
|
||||
Page page = context.newPage();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
|
||||
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +153,25 @@ 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 >> 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
|
||||
|
||||
@@ -230,4 +230,13 @@ public class TestSelectorsMisc extends TestBase {
|
||||
assertEquals("hello", page.locator("div >> internal:or=\"article\"").textContent());
|
||||
assertEquals("world", page.locator("span >> internal:or=\"article\"").textContent());
|
||||
}
|
||||
@Test
|
||||
void shouldWorkWithInternalChain() {
|
||||
page.setContent("<div>one <span>two</span> <button>three</button> </div>\n" +
|
||||
" <span>four</span>\n" +
|
||||
" <button>five</button>");
|
||||
assertEquals(asList("three"), page.evalOnSelectorAll("div >> internal:chain=\"button\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("two", "three"), page.evalOnSelectorAll("div >> internal:chain=\"span >> internal:or=\\\"button\\\"\"", "els => els.map(e => e.textContent)"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,18 @@ 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>><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" +
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
@@ -28,6 +29,11 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestWorkers extends TestBase {
|
||||
|
||||
private int browserMajorVersion() {
|
||||
String version = browser.version();
|
||||
return Integer.parseInt(version.split("\\.")[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageWorkers() {
|
||||
Worker worker = page.waitForWorker(() -> page.navigate(server.PREFIX + "/worker/worker.html"));
|
||||
@@ -145,6 +151,7 @@ public class TestWorkers extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldReportNetworkActivity() {
|
||||
Assumptions.assumeFalse(isFirefox() && browserMajorVersion() < 114);
|
||||
Worker worker = page.waitForWorker(() -> page.navigate(server.PREFIX + "/worker/worker.html"));
|
||||
String url = server.PREFIX + "/one-style.css";
|
||||
Request[] request = {null};
|
||||
@@ -160,6 +167,7 @@ public class TestWorkers extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldReportNetworkActivityOnWorkerCreation() {
|
||||
Assumptions.assumeFalse(isFirefox() && browserMajorVersion() < 114);
|
||||
// Chromium needs waitForDebugger enabled for this one.
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
String url = server.PREFIX + "/one-style.css";
|
||||
|
||||
@@ -19,11 +19,13 @@ 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;
|
||||
@@ -214,4 +216,17 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>File upload test</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" multiple name="file1">
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Playwright Parent Project</name>
|
||||
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
|
||||
@@ -44,6 +44,7 @@
|
||||
<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
@@ -1 +1 @@
|
||||
1.34.2
|
||||
1.39.0
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>api-generator</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Playwright - API Generator</name>
|
||||
<description>
|
||||
This is an internal module used to generate Java API from the upstream Playwright
|
||||
|
||||
@@ -964,7 +964,7 @@ class Interface extends TypeDefinition {
|
||||
if (asList("Page", "Frame", "ElementHandle", "Locator", "APIRequest", "Browser", "BrowserContext", "BrowserType", "Route", "Request", "Response", "JSHandle", "ConsoleMessage", "APIResponse", "Playwright").contains(jsonName)) {
|
||||
output.add("import java.util.*;");
|
||||
}
|
||||
if (asList("Page", "Browser", "BrowserContext", "WebSocket", "Worker").contains(jsonName)) {
|
||||
if (asList("Page", "Browser", "BrowserContext", "WebSocket", "Worker", "CDPSession").contains(jsonName)) {
|
||||
output.add("import java.util.function.Consumer;");
|
||||
}
|
||||
if (asList("Page", "BrowserContext").contains(jsonName)) {
|
||||
@@ -977,6 +977,9 @@ class Interface extends TypeDefinition {
|
||||
if (asList("Page", "Frame", "FrameLocator", "Locator", "Browser", "BrowserType", "BrowserContext", "PageAssertions", "LocatorAssertions").contains(jsonName)) {
|
||||
output.add("import java.util.regex.Pattern;");
|
||||
}
|
||||
if ("CDPSession".equals(jsonName)) {
|
||||
output.add("import com.google.gson.JsonObject;");
|
||||
}
|
||||
if ("PlaywrightAssertions".equals(jsonName)) {
|
||||
output.add("import com.microsoft.playwright.APIResponse;");
|
||||
output.add("import com.microsoft.playwright.Locator;");
|
||||
@@ -1153,13 +1156,18 @@ 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());
|
||||
generate(api, assertionsDir, "com.microsoft.playwright.assertions", isAssertion().and(isSoftAssertion().negate()));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>test-cli-fatjar</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Test Playwright Command Line FatJar</name>
|
||||
<properties>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>test-cli-version</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Test Playwright Command Line Version</name>
|
||||
<properties>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>test-local-installation</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Test local installation</name>
|
||||
<description>Runs Playwright test suite (copied from playwright module) against locally cached Playwright</description>
|
||||
<properties>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>test-spring-boot-starter</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Test Playwright With Spring Boot</name>
|
||||
<properties>
|
||||
<spring.version>2.4.3</spring.version>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>update-version</artifactId>
|
||||
<version>1.34.0-SNAPSHOT</version>
|
||||
<version>1.39.0</version>
|
||||
<name>Playwright - Update Version in Documentation</name>
|
||||
<description>
|
||||
This is an internal module used to update versions in the documentation based on
|
||||
|
||||
@@ -24,7 +24,7 @@ RUN apt-get update && \
|
||||
# Create the pwuser
|
||||
adduser pwuser
|
||||
|
||||
RUN VERSION=3.8.8 && \
|
||||
RUN VERSION=3.9.4 && \
|
||||
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/
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ RUN apt-get update && \
|
||||
# Create the pwuser
|
||||
adduser pwuser
|
||||
|
||||
RUN VERSION=3.8.8 && \
|
||||
RUN VERSION=3.9.4 && \
|
||||
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/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user