Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5de3898ad |
@@ -46,17 +46,15 @@ steps:
|
||||
done
|
||||
displayName: 'Create .sha256 files'
|
||||
|
||||
- task: EsrpRelease@4
|
||||
- task: EsrpRelease@2
|
||||
inputs:
|
||||
ConnectedServiceName: 'Playwright-ESRP'
|
||||
ConnectedServiceName: 'Playwright-Java-ESRP'
|
||||
Intent: 'PackageDistribution'
|
||||
ContentType: 'Maven'
|
||||
ContentSource: 'Folder'
|
||||
FolderLocation: './local-build'
|
||||
WaitForReleaseCompletion: true
|
||||
PackageLocation: './local-build'
|
||||
Owners: 'yurys@microsoft.com'
|
||||
Approvers: 'maxschmitt@microsoft.com'
|
||||
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
|
||||
MainPublisher: 'Playwright'
|
||||
MainPublisher: 'PlaywrightJava'
|
||||
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
|
||||
displayName: 'ESRP Release to Maven'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Docker
|
||||
name: Test Docker
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
@@ -18,18 +18,13 @@ on:
|
||||
- release-*
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
timeout-minutes: 120
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
flavor: [focal, jammy]
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build Docker image
|
||||
run: bash utils/docker/build.sh --amd64 ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
|
||||
run: bash utils/docker/build.sh --amd64 focal playwright-java:localbuild-focal
|
||||
- name: Test
|
||||
run: |
|
||||
CONTAINER_ID="$(docker run --rm --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash)"
|
||||
CONTAINER_ID="$(docker run --rm --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-focal /bin/bash)"
|
||||
docker exec "${CONTAINER_ID}" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh
|
||||
|
||||
@@ -11,11 +11,11 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->120.0.6099.28<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->119.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->112.0.5615.29<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->111.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/intro#system-requirements) for details.
|
||||
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/next/intro/#system-requirements) for details.
|
||||
|
||||
* [Usage](#usage)
|
||||
- [Add Maven dependency](#add-maven-dependency)
|
||||
@@ -65,7 +65,7 @@ You can find Maven project with the examples [here](./examples).
|
||||
|
||||
#### Page screenshot
|
||||
|
||||
This code snippet navigates to Playwright homepage in Chromium, Firefox and WebKit, and saves 3 screenshots.
|
||||
This code snippet navigates to whatsmyuseragent.org in Chromium, Firefox and WebKit, and saves 3 screenshots.
|
||||
|
||||
```java
|
||||
import com.microsoft.playwright.*;
|
||||
@@ -86,7 +86,7 @@ public class PageScreenshot {
|
||||
try (Browser browser = browserType.launch()) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate("https://playwright.dev/");
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,8 @@
|
||||
* regenerate API: `./scripts/download_driver_for_all_platforms.sh -f && ./scripts/generate_api.sh && ./scripts/update_readme.sh`
|
||||
* commit & send PR with the roll
|
||||
|
||||
### Finding driver version
|
||||
|
||||
For development versions of Playwright, you can find the latest version by looking at [publish_canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) workflow -> `publish canary NPM & Publish canary Docker` -> `build & publish driver` step -> `PACKAGE_VERSION`
|
||||
<img width="960" alt="image" src="https://github.com/microsoft/playwright-java/assets/9798949/4f33a7f1-b39a-4179-8ae7-fb1d84094c75">
|
||||
|
||||
|
||||
# Updating Version
|
||||
|
||||
```bash
|
||||
./scripts/set_maven_version.sh 1.15.0
|
||||
```
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.40.0</version>
|
||||
<version>1.32.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
|
||||
@@ -194,11 +194,7 @@ public class DriverJar extends Driver {
|
||||
}
|
||||
}
|
||||
if (name.contains("mac os x")) {
|
||||
if (arch.equals("aarch64")) {
|
||||
return "mac-arm64";
|
||||
} else {
|
||||
return "mac";
|
||||
}
|
||||
return "mac";
|
||||
}
|
||||
throw new RuntimeException("Unexpected os.name value: " + name);
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.40.0</version>
|
||||
<version>1.32.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver</artifactId>
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>1.40.0</version>
|
||||
<version>1.32.0</version>
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PageScreenshot {
|
||||
try (Browser browser = browserType.launch()) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate("https://playwright.dev/");
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class WebKitScreenshot {
|
||||
try (Playwright playwright = Playwright.create()) {
|
||||
Browser browser = playwright.webkit().launch();
|
||||
Page page = browser.newPage();
|
||||
page.navigate("https://playwright.dev/");
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("example.png")));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.40.0</version>
|
||||
<version>1.32.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>playwright</artifactId>
|
||||
|
||||
@@ -42,12 +42,11 @@ public interface APIRequest {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -100,22 +99,20 @@ public interface APIRequest {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
|
||||
@@ -80,8 +80,8 @@ public interface APIRequestContext {
|
||||
APIResponse delete(String url, RequestOptions params);
|
||||
/**
|
||||
* All responses returned by {@link APIRequestContext#get APIRequestContext.get()} and similar methods are stored in the
|
||||
* memory, so that you can later call {@link APIResponse#body APIResponse.body()}.This method discards all its resources,
|
||||
* calling any method on disposed {@code APIRequestContext} will throw an exception.
|
||||
* memory, so that you can later call {@link APIResponse#body APIResponse.body()}. This method discards all stored
|
||||
* responses, and makes {@link APIResponse#body APIResponse.body()} throw "Response disposed" error.
|
||||
*
|
||||
* @since v1.16
|
||||
*/
|
||||
|
||||
@@ -56,20 +56,6 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
void offDisconnected(Consumer<Browser> handler);
|
||||
|
||||
class CloseOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the browser closure.
|
||||
*/
|
||||
public String reason;
|
||||
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the browser closure.
|
||||
*/
|
||||
public CloseOptions setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class NewContextOptions {
|
||||
/**
|
||||
* Whether to automatically download all the attachments. Defaults to {@code true} where all the downloads are accepted.
|
||||
@@ -80,7 +66,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -92,7 +78,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -102,12 +88,11 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -118,13 +103,11 @@ public interface Browser extends AutoCloseable {
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -132,35 +115,30 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* 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>.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
* Network proxy settings to use with this context.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -235,14 +213,13 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -251,8 +228,7 @@ 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
|
||||
* emulation</a>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -271,7 +247,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -286,7 +262,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public NewContextOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -302,15 +278,14 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public NewContextOptions setDeviceScaleFactor(double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -333,23 +308,20 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public NewContextOptions setHasTouch(boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
@@ -363,17 +335,15 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public NewContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public NewContextOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
@@ -381,17 +351,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public NewContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public NewContextOptions setOffline(boolean offline) {
|
||||
this.offline = offline;
|
||||
@@ -399,14 +366,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
*/
|
||||
public NewContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
* Network proxy settings to use with this context.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -416,7 +383,7 @@ public interface Browser extends AutoCloseable {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
* Network proxy settings to use with this context.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -549,8 +516,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -559,7 +525,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
*/
|
||||
public NewContextOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -574,8 +540,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -585,8 +550,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -606,7 +570,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -618,7 +582,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -628,12 +592,11 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -644,13 +607,11 @@ public interface Browser extends AutoCloseable {
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -658,35 +619,30 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* 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>.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
* Network proxy settings to use with this context.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -761,14 +717,13 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -777,8 +732,7 @@ 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
|
||||
* emulation</a>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -797,7 +751,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -812,7 +766,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public NewPageOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -828,15 +782,14 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public NewPageOptions setDeviceScaleFactor(double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public NewPageOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -859,23 +812,20 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public NewPageOptions setHasTouch(boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public NewPageOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public NewPageOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
@@ -889,17 +839,15 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public NewPageOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public NewPageOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
@@ -907,17 +855,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public NewPageOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public NewPageOptions setOffline(boolean offline) {
|
||||
this.offline = offline;
|
||||
@@ -925,14 +870,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
*/
|
||||
public NewPageOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
* Network proxy settings to use with this context.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -942,7 +887,7 @@ public interface Browser extends AutoCloseable {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
* Network proxy settings to use with this context.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -1075,8 +1020,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1085,7 +1029,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
*/
|
||||
public NewPageOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -1100,8 +1044,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -1111,8 +1054,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -1179,25 +1121,7 @@ public interface Browser extends AutoCloseable {
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
default void close() {
|
||||
close(null);
|
||||
}
|
||||
/**
|
||||
* In case this browser is obtained using {@link BrowserType#launch BrowserType.launch()}, closes the browser and all of
|
||||
* its pages (if any were opened).
|
||||
*
|
||||
* <p> In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
|
||||
* browser server.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> This is similar to force quitting the browser. Therefore, you should call {@link BrowserContext#close
|
||||
* BrowserContext.close()} on any {@code BrowserContext}'s you explicitly created earlier with {@link Browser#newContext
|
||||
* Browser.newContext()} **before** calling {@link Browser#close Browser.close()}.
|
||||
*
|
||||
* <p> The {@code Browser} object itself is considered to be disposed and cannot be used anymore.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void close(CloseOptions options);
|
||||
void close();
|
||||
/**
|
||||
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
||||
*
|
||||
@@ -1218,14 +1142,6 @@ 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.
|
||||
*
|
||||
|
||||
@@ -58,51 +58,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offClose(Consumer<BrowserContext> handler);
|
||||
|
||||
/**
|
||||
* Emitted when JavaScript within the page calls one of console API methods, e.g. {@code console.log} or {@code
|
||||
* console.dir}. Also emitted if the page throws an error or a warning.
|
||||
*
|
||||
* <p> The arguments passed into {@code console.log} and the page are available on the {@code ConsoleMessage} event handler
|
||||
* argument.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.onConsoleMessage(msg -> {
|
||||
* for (int i = 0; i < msg.args().size(); ++i)
|
||||
* System.out.println(i + ": " + msg.args().get(i).jsonValue());
|
||||
* });
|
||||
* page.evaluate("() => console.log('hello', 5, { foo: 'bar' })");
|
||||
* }</pre>
|
||||
*/
|
||||
void onConsoleMessage(Consumer<ConsoleMessage> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onConsoleMessage onConsoleMessage(handler)}.
|
||||
*/
|
||||
void offConsoleMessage(Consumer<ConsoleMessage> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a JavaScript dialog appears, such as {@code alert}, {@code prompt}, {@code confirm} or {@code
|
||||
* beforeunload}. Listener **must** either {@link Dialog#accept Dialog.accept()} or {@link Dialog#dismiss Dialog.dismiss()}
|
||||
* the dialog - otherwise the page will <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking">freeze</a> waiting for the
|
||||
* dialog, and actions like click will never finish.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.onDialog(dialog -> {
|
||||
* dialog.accept();
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} or {@link BrowserContext#onDialog BrowserContext.onDialog()} listeners are
|
||||
* present, all dialogs are automatically dismissed.
|
||||
*/
|
||||
void onDialog(Consumer<Dialog> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onDialog onDialog(handler)}.
|
||||
*/
|
||||
void offDialog(Consumer<Dialog> handler);
|
||||
|
||||
/**
|
||||
* The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
|
||||
* also fire for popup pages. See also {@link Page#onPopup Page.onPopup()} to receive events about popups relevant to a
|
||||
@@ -127,16 +82,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offPage(Consumer<Page> handler);
|
||||
|
||||
/**
|
||||
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular page,
|
||||
* use {@link Page#onPageError Page.onPageError()} instead.
|
||||
*/
|
||||
void onWebError(Consumer<WebError> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onWebError onWebError(handler)}.
|
||||
*/
|
||||
void offWebError(Consumer<WebError> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only
|
||||
* listen for requests from a particular page, use {@link Page#onRequest Page.onRequest()}.
|
||||
@@ -186,20 +131,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offResponse(Consumer<Response> handler);
|
||||
|
||||
class CloseOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context closure.
|
||||
*/
|
||||
public String reason;
|
||||
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context closure.
|
||||
*/
|
||||
public CloseOptions setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
@@ -364,33 +295,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class WaitForConsoleMessageOptions {
|
||||
/**
|
||||
* Receives the {@code ConsoleMessage} object and resolves to truthy value when the waiting should resolve.
|
||||
*/
|
||||
public Predicate<ConsoleMessage> predicate;
|
||||
/**
|
||||
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
|
||||
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Receives the {@code ConsoleMessage} object and resolves to truthy value when the waiting should resolve.
|
||||
*/
|
||||
public WaitForConsoleMessageOptions setPredicate(Predicate<ConsoleMessage> predicate) {
|
||||
this.predicate = predicate;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
|
||||
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForConsoleMessageOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class WaitForPageOptions {
|
||||
/**
|
||||
* Receives the {@code Page} object and resolves to truthy value when the waiting should resolve.
|
||||
@@ -427,9 +331,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
|
||||
* }</pre>
|
||||
*
|
||||
* @param cookies Adds cookies to the browser context.
|
||||
*
|
||||
* <p> For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com".
|
||||
* @since v1.8
|
||||
*/
|
||||
void addCookies(List<Cookie> cookies);
|
||||
@@ -518,17 +419,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
default void close() {
|
||||
close(null);
|
||||
}
|
||||
/**
|
||||
* Closes the browser context. All the pages that belong to the browser context will be closed.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The default browser context cannot be closed.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void close(CloseOptions options);
|
||||
void close();
|
||||
/**
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
||||
* are returned.
|
||||
@@ -786,26 +677,6 @@ 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.
|
||||
*
|
||||
@@ -1150,7 +1021,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/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/network#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
|
||||
@@ -1165,7 +1036,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/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/network#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
|
||||
@@ -1371,28 +1242,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.32
|
||||
*/
|
||||
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
|
||||
/**
|
||||
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the pages in the context. If predicate is
|
||||
* provided, it passes {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code
|
||||
* predicate(message)} to return a truthy value. Will throw an error if the page is closed before the {@link
|
||||
* BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
|
||||
*
|
||||
* @param callback Callback that performs the action triggering the event.
|
||||
* @since v1.34
|
||||
*/
|
||||
default ConsoleMessage waitForConsoleMessage(Runnable callback) {
|
||||
return waitForConsoleMessage(null, callback);
|
||||
}
|
||||
/**
|
||||
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the pages in the context. If predicate is
|
||||
* provided, it passes {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code
|
||||
* predicate(message)} to return a truthy value. Will throw an error if the page is closed before the {@link
|
||||
* BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
|
||||
*
|
||||
* @param callback Callback that performs the action triggering the event.
|
||||
* @since v1.34
|
||||
*/
|
||||
ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable callback);
|
||||
/**
|
||||
* Performs action and waits for a new {@code Page} to be created in the context. If predicate is provided, it passes
|
||||
* {@code Page} value into the {@code predicate} function and waits for {@code predicate(event)} to return a truthy value.
|
||||
|
||||
@@ -43,26 +43,6 @@ 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.
|
||||
*/
|
||||
@@ -77,29 +57,6 @@ 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.
|
||||
*/
|
||||
@@ -425,7 +382,7 @@ public interface BrowserType {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -437,7 +394,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -457,8 +414,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
@@ -483,14 +439,9 @@ public interface BrowserType {
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Firefox user preferences. Learn more about the Firefox user preferences at <a
|
||||
* href="https://support.mozilla.org/en-US/kb/about-config-editor-firefox">{@code about:config}</a>.
|
||||
*/
|
||||
public Map<String, Object> firefoxUserPrefs;
|
||||
/**
|
||||
* Emulates {@code "forced-colors"} media feature, supported values are {@code "active"}, {@code "none"}. See {@link
|
||||
* Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
@@ -511,8 +462,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean handleSIGTERM;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
@@ -523,8 +473,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -542,31 +491,26 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* 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>.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
@@ -634,8 +578,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
@@ -646,7 +589,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -659,8 +602,7 @@ 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
|
||||
* emulation</a>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -687,7 +629,7 @@ public interface BrowserType {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -702,7 +644,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -744,8 +686,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setDeviceScaleFactor(double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
@@ -785,20 +726,12 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Firefox user preferences. Learn more about the Firefox user preferences at <a
|
||||
* href="https://support.mozilla.org/en-US/kb/about-config-editor-firefox">{@code about:config}</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setFirefoxUserPrefs(Map<String, Object> firefoxUserPrefs) {
|
||||
this.firefoxUserPrefs = firefoxUserPrefs;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "forced-colors"} media feature, supported values are {@code "active"}, {@code "none"}. See {@link
|
||||
* Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
@@ -837,8 +770,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHasTouch(boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
@@ -855,15 +787,13 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
@@ -893,17 +823,15 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
@@ -911,17 +839,14 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setOffline(boolean offline) {
|
||||
this.offline = offline;
|
||||
@@ -929,7 +854,7 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
@@ -1061,8 +986,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1079,7 +1003,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -1101,8 +1025,7 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -1112,8 +1035,7 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* 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>.
|
||||
* viewport emulation.
|
||||
*
|
||||
* <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
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -56,12 +56,6 @@ public interface ConsoleMessage {
|
||||
* @since v1.8
|
||||
*/
|
||||
String location();
|
||||
/**
|
||||
* The page that produced this console message, if any.
|
||||
*
|
||||
* @since v1.34
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* The text of the console message.
|
||||
*
|
||||
|
||||
@@ -81,12 +81,6 @@ public interface Dialog {
|
||||
* @since v1.8
|
||||
*/
|
||||
String message();
|
||||
/**
|
||||
* The page that initiated this dialog, if available.
|
||||
*
|
||||
* @since v1.34
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Returns dialog's type, can be one of {@code alert}, {@code beforeunload}, {@code confirm} or {@code prompt}.
|
||||
*
|
||||
|
||||
@@ -24,16 +24,14 @@ import java.nio.file.Path;
|
||||
*
|
||||
* <p> All the downloaded files belonging to the browser context are deleted when the browser context is closed.
|
||||
*
|
||||
* <p> Download event is emitted once the download starts. Download path becomes available once download completes.
|
||||
* <p> Download event is emitted once the download starts. Download path becomes available once download completes:
|
||||
* <pre>{@code
|
||||
* // Wait for the download to start
|
||||
* // wait for download to start
|
||||
* Download download = page.waitForDownload(() -> {
|
||||
* // Perform the action that initiates download
|
||||
* page.getByText("Download file").click();
|
||||
* page.getByText("Download file").click();
|
||||
* });
|
||||
*
|
||||
* // Wait for the download process to complete and save the downloaded file somewhere
|
||||
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
|
||||
* // wait for download to complete
|
||||
* Path path = download.path();
|
||||
* }</pre>
|
||||
*/
|
||||
public interface Download {
|
||||
@@ -45,7 +43,7 @@ public interface Download {
|
||||
*/
|
||||
void cancel();
|
||||
/**
|
||||
* Returns a readable stream for a successful download, or throws for a failed/canceled download.
|
||||
* Returns readable stream for current download or {@code null} if download failed.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -69,8 +67,8 @@ public interface Download {
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will
|
||||
* wait for the download to finish if necessary. The method throws when connected remotely.
|
||||
* Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if
|
||||
* necessary. The method throws when connected remotely.
|
||||
*
|
||||
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()}
|
||||
* to get suggested file name.
|
||||
@@ -82,11 +80,6 @@ public interface Download {
|
||||
* Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will
|
||||
* wait for the download to finish if necessary.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
|
||||
* }</pre>
|
||||
*
|
||||
* @param path Path where the download should be copied.
|
||||
* @since v1.8
|
||||
*/
|
||||
|
||||
@@ -602,15 +602,9 @@ public interface ElementHandle extends JSHandle {
|
||||
public ScreenshotCaret caret;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -669,21 +663,12 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -1411,17 +1396,13 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -1455,17 +1436,13 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -1590,7 +1567,7 @@ public interface ElementHandle extends JSHandle {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link ElementHandle#type ElementHandle.type()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.8
|
||||
@@ -1608,7 +1585,7 @@ public interface ElementHandle extends JSHandle {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link ElementHandle#type ElementHandle.type()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.8
|
||||
@@ -1886,7 +1863,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1917,7 +1894,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1946,7 +1923,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1977,7 +1954,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2006,7 +1983,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2037,7 +2014,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2066,7 +2043,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2097,7 +2074,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2126,7 +2103,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2157,7 +2134,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2186,7 +2163,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2217,7 +2194,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2458,9 +2435,24 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
String textContent();
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link ElementHandle#press
|
||||
* ElementHandle.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* elementHandle.type("Hello"); // Types instantly
|
||||
* elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* ElementHandle elementHandle = page.querySelector("input");
|
||||
* elementHandle.type("some text");
|
||||
* elementHandle.press("Enter");
|
||||
* }</pre>
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.8
|
||||
@@ -2469,9 +2461,24 @@ public interface ElementHandle extends JSHandle {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link ElementHandle#press
|
||||
* ElementHandle.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* elementHandle.type("Hello"); // Types instantly
|
||||
* elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* ElementHandle elementHandle = page.querySelector("input");
|
||||
* elementHandle.type("some text");
|
||||
* elementHandle.press("Enter");
|
||||
* }</pre>
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.8
|
||||
|
||||
@@ -1046,8 +1046,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1076,8 +1076,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1476,19 +1476,6 @@ public interface Frame {
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator has;
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator hasNot;
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public Object hasNotText;
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -1506,33 +1493,6 @@ public interface Frame {
|
||||
this.has = has;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public LocatorOptions setHasNot(Locator hasNot) {
|
||||
this.hasNot = hasNot;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(String hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(Pattern hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -1791,8 +1751,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1813,8 +1773,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2228,8 +2188,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2277,8 +2237,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2358,8 +2318,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2380,8 +2340,8 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2582,17 +2542,13 @@ public interface Frame {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -2628,17 +2584,13 @@ public interface Frame {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -2673,17 +2625,13 @@ public interface Frame {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -2999,7 +2947,7 @@ public interface Frame {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Frame#type Frame.type()}.
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
@@ -3018,7 +2966,7 @@ public interface Frame {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Frame#type Frame.type()}.
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
@@ -4070,7 +4018,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4103,7 +4051,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4134,7 +4082,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4167,7 +4115,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4198,7 +4146,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4231,7 +4179,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4262,7 +4210,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4295,7 +4243,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4326,7 +4274,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4359,7 +4307,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4390,7 +4338,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4423,7 +4371,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* frame.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -4485,9 +4433,7 @@ 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
|
||||
@@ -4496,9 +4442,7 @@ 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
|
||||
@@ -4689,9 +4633,19 @@ public interface Frame {
|
||||
*/
|
||||
String title();
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
|
||||
* frame.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Frame#fill
|
||||
* Frame.fill()}.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* frame.type("#mytextarea", "Hello");
|
||||
* // Types slower, like a user
|
||||
* frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
|
||||
* }</pre>
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param text A text to type into a focused element.
|
||||
@@ -4701,9 +4655,19 @@ public interface Frame {
|
||||
type(selector, text, null);
|
||||
}
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
|
||||
* frame.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Frame#fill
|
||||
* Frame.fill()}.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* frame.type("#mytextarea", "Hello");
|
||||
* // Types slower, like a user
|
||||
* frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
|
||||
* }</pre>
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param text A text to type into a focused element.
|
||||
@@ -4885,8 +4849,7 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "load"} - wait for the {@code load} event to be fired.</li>
|
||||
* <li> {@code "domcontentloaded"} - wait for the {@code DOMContentLoaded} event to be fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** wait until there are no network connections for at least {@code 500} ms. Don't
|
||||
* use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - wait until there are no network connections for at least {@code 500} ms.</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -4927,8 +4890,7 @@ public interface Frame {
|
||||
* <ul>
|
||||
* <li> {@code "load"} - wait for the {@code load} event to be fired.</li>
|
||||
* <li> {@code "domcontentloaded"} - wait for the {@code DOMContentLoaded} event to be fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** wait until there are no network connections for at least {@code 500} ms. Don't
|
||||
* use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - wait until there are no network connections for at least {@code 500} ms.</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
|
||||
@@ -291,19 +291,6 @@ public interface FrameLocator {
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator has;
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator hasNot;
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public Object hasNotText;
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -321,33 +308,6 @@ public interface FrameLocator {
|
||||
this.has = has;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public LocatorOptions setHasNot(Locator hasNot) {
|
||||
this.hasNot = hasNot;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(String hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(Pattern hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
|
||||
@@ -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,9 +132,7 @@ public interface Keyboard {
|
||||
*/
|
||||
void insertText(String text);
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@code key} can specify the intended <a
|
||||
* {@code key} can specify the intended <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
@@ -177,9 +175,7 @@ public interface Keyboard {
|
||||
press(key, null);
|
||||
}
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@code key} can specify the intended <a
|
||||
* {@code key} can specify the intended <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
@@ -220,11 +216,7 @@ public interface Keyboard {
|
||||
*/
|
||||
void press(String key, PressOptions options);
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
*
|
||||
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
@@ -247,11 +239,7 @@ public interface Keyboard {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
*
|
||||
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
|
||||
@@ -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. A locator can be created with the {@link Page#locator Page.locator()}
|
||||
* to find element(s) on the page at any moment. 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>.
|
||||
@@ -662,19 +662,6 @@ public interface Locator {
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator has;
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator hasNot;
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public Object hasNotText;
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -692,33 +679,6 @@ public interface Locator {
|
||||
this.has = has;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public FilterOptions setHasNot(Locator hasNot) {
|
||||
this.hasNot = hasNot;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public FilterOptions setHasNotText(String hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public FilterOptions setHasNotText(Pattern hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -1268,19 +1228,6 @@ public interface Locator {
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator has;
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator hasNot;
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public Object hasNotText;
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -1298,33 +1245,6 @@ public interface Locator {
|
||||
this.has = has;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public LocatorOptions setHasNot(Locator hasNot) {
|
||||
this.hasNot = hasNot;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(String hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(Pattern hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -1388,50 +1308,6 @@ public interface Locator {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class PressSequentiallyOptions {
|
||||
/**
|
||||
* Time to wait between key presses in milliseconds. Defaults to 0.
|
||||
*/
|
||||
public Double delay;
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to wait between key presses in milliseconds. Defaults to 0.
|
||||
*/
|
||||
public PressSequentiallyOptions setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
*/
|
||||
public PressSequentiallyOptions setNoWaitAfter(boolean noWaitAfter) {
|
||||
this.noWaitAfter = noWaitAfter;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public PressSequentiallyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ScreenshotOptions {
|
||||
/**
|
||||
* When set to {@code "disabled"}, stops CSS animations, CSS transitions and Web Animations. Animations get different
|
||||
@@ -1451,15 +1327,9 @@ public interface Locator {
|
||||
public ScreenshotCaret caret;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -1518,21 +1388,12 @@ public interface Locator {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -2077,12 +1938,11 @@ public interface Locator {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* When the locator points to a list of elements, this returns an array of locators, pointing to their respective elements.
|
||||
* When locator points to a list of elements, returns array of locators, pointing to 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
|
||||
* produce unpredictable and flaky results. When the list of elements is stable, but loaded dynamically, wait for the full
|
||||
* list to finish loading before calling {@link Locator#all Locator.all()}.
|
||||
* <p> Note that {@link Locator#all Locator.all()} does not wait for elements to match the locator, and instead immediately
|
||||
* returns whatever is present in the page. To avoid flakiness when elements are loaded dynamically, wait for the loading
|
||||
* to finish before calling {@link Locator#all Locator.all()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -2096,10 +1956,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns an array of {@code node.innerText} values for all matching nodes.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} with {@code
|
||||
* useInnerText} option to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions
|
||||
* guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* String[] texts = page.getByRole(AriaRole.LINK).allInnerTexts();
|
||||
@@ -2111,9 +1967,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns an array of {@code node.textContent} values for all matching nodes.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} to avoid
|
||||
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* String[] texts = page.getByRole(AriaRole.LINK).allTextContents();
|
||||
@@ -2122,20 +1975,6 @@ public interface Locator {
|
||||
* @since v1.14
|
||||
*/
|
||||
List<String> allTextContents();
|
||||
/**
|
||||
* Creates a locator that matches both this locator and the argument locator.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> The following example finds a button with a specific title.
|
||||
* <pre>{@code
|
||||
* Locator button = page.getByRole(AriaRole.BUTTON).and(page.getByTitle("Subscribe"));
|
||||
* }</pre>
|
||||
*
|
||||
* @param locator Additional locator to match.
|
||||
* @since v1.34
|
||||
*/
|
||||
Locator and(Locator locator);
|
||||
/**
|
||||
* Calls <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur">blur</a> on the element.
|
||||
*
|
||||
@@ -2387,10 +2226,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns the number of elements matching the locator.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert the number of elements on the page, prefer {@link LocatorAssertions#hasCount
|
||||
* LocatorAssertions.hasCount()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* int count = page.getByRole(AriaRole.LISTITEM).count();
|
||||
@@ -2471,17 +2306,13 @@ public interface Locator {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -2520,17 +2351,13 @@ public interface Locator {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -2568,17 +2395,13 @@ public interface Locator {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -2899,7 +2722,7 @@ public interface Locator {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#type Locator.type()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.14
|
||||
@@ -2926,7 +2749,7 @@ public interface Locator {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#type Locator.type()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.14
|
||||
@@ -3009,10 +2832,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns the matching element's attribute value.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert an element's attribute, prefer {@link LocatorAssertions#hasAttribute
|
||||
* LocatorAssertions.hasAttribute()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* @param name Attribute name to get the value for.
|
||||
* @since v1.14
|
||||
*/
|
||||
@@ -3022,10 +2841,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns the matching element's attribute value.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert an element's attribute, prefer {@link LocatorAssertions#hasAttribute
|
||||
* LocatorAssertions.hasAttribute()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* @param name Attribute name to get the value for.
|
||||
* @since v1.14
|
||||
*/
|
||||
@@ -3665,10 +3480,6 @@ public interface Locator {
|
||||
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText">{@code
|
||||
* element.innerText}</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} with {@code
|
||||
* useInnerText} option to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions
|
||||
* guide</a> for more details.
|
||||
*
|
||||
* @since v1.14
|
||||
*/
|
||||
default String innerText() {
|
||||
@@ -3678,19 +3489,12 @@ public interface Locator {
|
||||
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText">{@code
|
||||
* element.innerText}</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} with {@code
|
||||
* useInnerText} option to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions
|
||||
* guide</a> for more details.
|
||||
*
|
||||
* @since v1.14
|
||||
*/
|
||||
String innerText(InnerTextOptions options);
|
||||
/**
|
||||
* Returns the value for the matching {@code <input>} or {@code <textarea>} or {@code <select>} element.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert input value, prefer {@link LocatorAssertions#hasValue LocatorAssertions.hasValue()} to avoid
|
||||
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* String value = page.getByRole(AriaRole.TEXTBOX).inputValue();
|
||||
@@ -3711,9 +3515,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns the value for the matching {@code <input>} or {@code <textarea>} or {@code <select>} element.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert input value, prefer {@link LocatorAssertions#hasValue LocatorAssertions.hasValue()} to avoid
|
||||
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* String value = page.getByRole(AriaRole.TEXTBOX).inputValue();
|
||||
@@ -3732,10 +3533,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that checkbox is checked, prefer {@link LocatorAssertions#isChecked LocatorAssertions.isChecked()}
|
||||
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
|
||||
* details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean checked = page.getByRole(AriaRole.CHECKBOX).isChecked();
|
||||
@@ -3749,10 +3546,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that checkbox is checked, prefer {@link LocatorAssertions#isChecked LocatorAssertions.isChecked()}
|
||||
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
|
||||
* details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean checked = page.getByRole(AriaRole.CHECKBOX).isChecked();
|
||||
@@ -3765,10 +3558,6 @@ public interface Locator {
|
||||
* Returns whether the element is disabled, the opposite of <a
|
||||
* href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that an element is disabled, prefer {@link LocatorAssertions#isDisabled
|
||||
* LocatorAssertions.isDisabled()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean disabled = page.getByRole(AriaRole.BUTTON).isDisabled();
|
||||
@@ -3783,10 +3572,6 @@ public interface Locator {
|
||||
* Returns whether the element is disabled, the opposite of <a
|
||||
* href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that an element is disabled, prefer {@link LocatorAssertions#isDisabled
|
||||
* LocatorAssertions.isDisabled()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean disabled = page.getByRole(AriaRole.BUTTON).isDisabled();
|
||||
@@ -3798,10 +3583,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#editable">editable</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that an element is editable, prefer {@link LocatorAssertions#isEditable
|
||||
* LocatorAssertions.isEditable()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean editable = page.getByRole(AriaRole.TEXTBOX).isEditable();
|
||||
@@ -3815,10 +3596,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#editable">editable</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that an element is editable, prefer {@link LocatorAssertions#isEditable
|
||||
* LocatorAssertions.isEditable()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean editable = page.getByRole(AriaRole.TEXTBOX).isEditable();
|
||||
@@ -3830,10 +3607,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that an element is enabled, prefer {@link LocatorAssertions#isEnabled
|
||||
* LocatorAssertions.isEnabled()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean enabled = page.getByRole(AriaRole.BUTTON).isEnabled();
|
||||
@@ -3847,10 +3620,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#enabled">enabled</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that an element is enabled, prefer {@link LocatorAssertions#isEnabled
|
||||
* LocatorAssertions.isEnabled()} to avoid flakiness. See <a
|
||||
* href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean enabled = page.getByRole(AriaRole.BUTTON).isEnabled();
|
||||
@@ -3863,9 +3632,6 @@ public interface Locator {
|
||||
* Returns whether the element is hidden, the opposite of <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that element is hidden, prefer {@link LocatorAssertions#isHidden LocatorAssertions.isHidden()} to
|
||||
* avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean hidden = page.getByRole(AriaRole.BUTTON).isHidden();
|
||||
@@ -3880,9 +3646,6 @@ public interface Locator {
|
||||
* Returns whether the element is hidden, the opposite of <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that element is hidden, prefer {@link LocatorAssertions#isHidden LocatorAssertions.isHidden()} to
|
||||
* avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean hidden = page.getByRole(AriaRole.BUTTON).isHidden();
|
||||
@@ -3894,10 +3657,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that element is visible, prefer {@link LocatorAssertions#isVisible LocatorAssertions.isVisible()}
|
||||
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
|
||||
* details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean visible = page.getByRole(AriaRole.BUTTON).isVisible();
|
||||
@@ -3911,10 +3670,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns whether the element is <a href="https://playwright.dev/java/docs/actionability#visible">visible</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert that element is visible, prefer {@link LocatorAssertions#isVisible LocatorAssertions.isVisible()}
|
||||
* to avoid flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more
|
||||
* details.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* boolean visible = page.getByRole(AriaRole.BUTTON).isVisible();
|
||||
@@ -3989,26 +3744,6 @@ public interface Locator {
|
||||
* @since v1.14
|
||||
*/
|
||||
Locator nth(int index);
|
||||
/**
|
||||
* Creates a locator that matches either of the two locators.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider a scenario where you'd like to click on a "New email" button, but sometimes a security settings dialog shows up
|
||||
* instead. In this case, you can wait for either a "New email" button, or a dialog and act accordingly.
|
||||
* <pre>{@code
|
||||
* Locator newEmail = page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("New"));
|
||||
* Locator dialog = page.getByText("Confirm security settings");
|
||||
* assertThat(newEmail.or(dialog)).isVisible();
|
||||
* if (dialog.isVisible())
|
||||
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Dismiss")).click();
|
||||
* newEmail.click();
|
||||
* }</pre>
|
||||
*
|
||||
* @param locator Alternative locator to match.
|
||||
* @since v1.33
|
||||
*/
|
||||
Locator or(Locator locator);
|
||||
/**
|
||||
* A page this locator belongs to.
|
||||
*
|
||||
@@ -4091,60 +3826,6 @@ public interface Locator {
|
||||
* @since v1.14
|
||||
*/
|
||||
void press(String key, PressOptions options);
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page.
|
||||
*
|
||||
* <p> Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* locator.pressSequentially("Hello"); // Types instantly
|
||||
* locator.pressSequentially("World", new Locator.pressSequentiallyOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByLabel("Password");
|
||||
* locator.pressSequentially("my password");
|
||||
* locator.press("Enter");
|
||||
* }</pre>
|
||||
*
|
||||
* @param text String of characters to sequentially press into a focused element.
|
||||
* @since v1.38
|
||||
*/
|
||||
default void pressSequentially(String text) {
|
||||
pressSequentially(text, null);
|
||||
}
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page.
|
||||
*
|
||||
* <p> Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* locator.pressSequentially("Hello"); // Types instantly
|
||||
* locator.pressSequentially("World", new Locator.pressSequentiallyOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByLabel("Password");
|
||||
* locator.pressSequentially("my password");
|
||||
* locator.press("Enter");
|
||||
* }</pre>
|
||||
*
|
||||
* @param text String of characters to sequentially press into a focused element.
|
||||
* @since v1.38
|
||||
*/
|
||||
void pressSequentially(String text, PressSequentiallyOptions options);
|
||||
/**
|
||||
* Take a screenshot of the element matching the locator.
|
||||
*
|
||||
@@ -5042,9 +4723,6 @@ public interface Locator {
|
||||
/**
|
||||
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent">{@code node.textContent}</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} to avoid
|
||||
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* @since v1.14
|
||||
*/
|
||||
default String textContent() {
|
||||
@@ -5053,16 +4731,27 @@ public interface Locator {
|
||||
/**
|
||||
* Returns the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent">{@code node.textContent}</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If you need to assert text on the page, prefer {@link LocatorAssertions#hasText LocatorAssertions.hasText()} to avoid
|
||||
* flakiness. See <a href="https://playwright.dev/java/docs/test-assertions">assertions guide</a> for more details.
|
||||
*
|
||||
* @since v1.14
|
||||
*/
|
||||
String textContent(TextContentOptions options);
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* element.type("Hello"); // Types instantly
|
||||
* element.type("World", new Locator.TypeOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* Locator element = page.getByLabel("Password");
|
||||
* element.type("my password");
|
||||
* element.press("Enter");
|
||||
* }</pre>
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.14
|
||||
@@ -5071,9 +4760,23 @@ public interface Locator {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Locator#press Locator.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* element.type("Hello"); // Types instantly
|
||||
* element.type("World", new Locator.TypeOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* Locator element = page.getByLabel("Password");
|
||||
* element.type("my password");
|
||||
* element.press("Enter");
|
||||
* }</pre>
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.14
|
||||
|
||||
@@ -82,15 +82,15 @@ public interface Page extends AutoCloseable {
|
||||
* Emitted when JavaScript within the page calls one of console API methods, e.g. {@code console.log} or {@code
|
||||
* console.dir}. Also emitted if the page throws an error or a warning.
|
||||
*
|
||||
* <p> The arguments passed into {@code console.log} are available on the {@code ConsoleMessage} event handler argument.
|
||||
* <p> The arguments passed into {@code console.log} appear as arguments on the event handler.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> An example of handling {@code console} event:
|
||||
* <pre>{@code
|
||||
* page.onConsoleMessage(msg -> {
|
||||
* for (int i = 0; i < msg.args().size(); ++i)
|
||||
* System.out.println(i + ": " + msg.args().get(i).jsonValue());
|
||||
* });
|
||||
* page.evaluate("() => console.log('hello', 5, { foo: 'bar' })");
|
||||
* page.evaluate("() => console.log('hello', 5, {foo: 'bar'})");
|
||||
* }</pre>
|
||||
*/
|
||||
void onConsoleMessage(Consumer<ConsoleMessage> handler);
|
||||
@@ -127,16 +127,13 @@ public interface Page extends AutoCloseable {
|
||||
* the dialog - otherwise the page will <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking">freeze</a> waiting for the
|
||||
* dialog, and actions like click will never finish.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.onDialog(dialog -> {
|
||||
* dialog.accept();
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} or {@link BrowserContext#onDialog BrowserContext.onDialog()} listeners are
|
||||
* present, all dialogs are automatically dismissed.
|
||||
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} listeners are present, all dialogs are automatically dismissed.
|
||||
*/
|
||||
void onDialog(Consumer<Dialog> handler);
|
||||
/**
|
||||
@@ -650,23 +647,12 @@ public interface Page extends AutoCloseable {
|
||||
}
|
||||
}
|
||||
class CloseOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the page closure.
|
||||
*/
|
||||
public String reason;
|
||||
/**
|
||||
* Defaults to {@code false}. Whether to run the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload">before unload</a> page handlers.
|
||||
*/
|
||||
public Boolean runBeforeUnload;
|
||||
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the page closure.
|
||||
*/
|
||||
public CloseOptions setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Defaults to {@code false}. Whether to run the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload">before unload</a> page handlers.
|
||||
@@ -1405,8 +1391,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1427,8 +1413,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1450,8 +1436,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1472,8 +1458,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1500,8 +1486,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1530,8 +1516,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -1930,19 +1916,6 @@ public interface Page extends AutoCloseable {
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator has;
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator hasNot;
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public Object hasNotText;
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -1960,33 +1933,6 @@ public interface Page extends AutoCloseable {
|
||||
this.has = has;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public LocatorOptions setHasNot(Locator hasNot) {
|
||||
this.hasNot = hasNot;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(String hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(Pattern hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -2258,8 +2204,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2280,8 +2226,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2408,7 +2354,7 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
public ScreenshotCaret caret;
|
||||
/**
|
||||
* An object which specifies clipping of the resulting image.
|
||||
* An object which specifies clipping of the resulting image. Should have the following fields:
|
||||
*/
|
||||
public Clip clip;
|
||||
/**
|
||||
@@ -2418,15 +2364,9 @@ public interface Page extends AutoCloseable {
|
||||
public Boolean fullPage;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -2484,13 +2424,13 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object which specifies clipping of the resulting image.
|
||||
* An object which specifies clipping of the resulting image. Should have the following fields:
|
||||
*/
|
||||
public ScreenshotOptions setClip(double x, double y, double width, double height) {
|
||||
return setClip(new Clip(x, y, width, height));
|
||||
}
|
||||
/**
|
||||
* An object which specifies clipping of the resulting image.
|
||||
* An object which specifies clipping of the resulting image. Should have the following fields:
|
||||
*/
|
||||
public ScreenshotOptions setClip(Clip clip) {
|
||||
this.clip = clip;
|
||||
@@ -2506,21 +2446,12 @@ public interface Page extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -2739,8 +2670,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -2761,8 +2692,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -3273,8 +3204,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -3322,8 +3253,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -3509,8 +3440,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -3531,8 +3462,8 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "domcontentloaded"} - consider operation to be finished when the {@code DOMContentLoaded} event is fired.</li>
|
||||
* <li> {@code "load"} - consider operation to be finished when the {@code load} event is fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** consider operation to be finished when there are no network connections for at
|
||||
* least {@code 500} ms. Don't use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - consider operation to be finished when there are no network connections for at least {@code 500}
|
||||
* ms.</li>
|
||||
* <li> {@code "commit"} - consider operation to be finished when network response is received and the document started loading.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -3869,17 +3800,13 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -3915,17 +3842,13 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -3960,17 +3883,13 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -4558,7 +4477,7 @@ public interface Page extends AutoCloseable {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Page#type Page.type()}.
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
@@ -4577,7 +4496,7 @@ public interface Page extends AutoCloseable {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Page#type Page.type()}.
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param value Value to fill for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
@@ -6224,7 +6143,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/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/network#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
|
||||
@@ -6239,7 +6158,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/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/network#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
|
||||
@@ -6280,7 +6199,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6313,7 +6232,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6344,7 +6263,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6377,7 +6296,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6408,7 +6327,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6441,7 +6360,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6472,7 +6391,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6505,7 +6424,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6536,7 +6455,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6569,7 +6488,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6600,7 +6519,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6633,7 +6552,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Single selection matching the value or label
|
||||
* // single selection matching the value
|
||||
* page.selectOption("select#colors", "blue");
|
||||
* // single selection matching both the value and the label
|
||||
* page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
|
||||
@@ -6695,9 +6614,7 @@ 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
|
||||
@@ -6706,9 +6623,7 @@ 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
|
||||
@@ -6965,9 +6880,19 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
Touchscreen touchscreen();
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
|
||||
* page.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Page#fill
|
||||
* Page.fill()}.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* page.type("#mytextarea", "Hello");
|
||||
* // Types slower, like a user
|
||||
* page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
|
||||
* }</pre>
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param text A text to type into a focused element.
|
||||
@@ -6977,9 +6902,19 @@ public interface Page extends AutoCloseable {
|
||||
type(selector, text, null);
|
||||
}
|
||||
/**
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text. {@code
|
||||
* page.type} can be used to send fine-grained keyboard events. To fill values in form fields, use {@link Page#fill
|
||||
* Page.fill()}.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* page.type("#mytextarea", "Hello");
|
||||
* // Types slower, like a user
|
||||
* page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
|
||||
* }</pre>
|
||||
*
|
||||
* @param selector A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
|
||||
* @param text A text to type into a focused element.
|
||||
@@ -7316,8 +7251,7 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "load"} - wait for the {@code load} event to be fired.</li>
|
||||
* <li> {@code "domcontentloaded"} - wait for the {@code DOMContentLoaded} event to be fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** wait until there are no network connections for at least {@code 500} ms. Don't
|
||||
* use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - wait until there are no network connections for at least {@code 500} ms.</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -7374,8 +7308,7 @@ public interface Page extends AutoCloseable {
|
||||
* <ul>
|
||||
* <li> {@code "load"} - wait for the {@code load} event to be fired.</li>
|
||||
* <li> {@code "domcontentloaded"} - wait for the {@code DOMContentLoaded} event to be fired.</li>
|
||||
* <li> {@code "networkidle"} - **DISCOURAGED** wait until there are no network connections for at least {@code 500} ms. Don't
|
||||
* use this method for testing, rely on web assertions to assess readiness instead.</li>
|
||||
* <li> {@code "networkidle"} - wait until there are no network connections for at least {@code 500} ms.</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -7841,8 +7774,8 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
ElementHandle waitForSelector(String selector, WaitForSelectorOptions options);
|
||||
/**
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
* The method will block until the codition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the codition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
@@ -7854,15 +7787,15 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForCondition(() -> messages.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Condition to wait for.
|
||||
* @param condition Codition to wait for.
|
||||
* @since v1.32
|
||||
*/
|
||||
default void waitForCondition(BooleanSupplier condition) {
|
||||
waitForCondition(condition, null);
|
||||
}
|
||||
/**
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
* The method will block until the codition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the codition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
@@ -7874,7 +7807,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForCondition(() -> messages.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Condition to wait for.
|
||||
* @param condition Codition to wait for.
|
||||
* @since v1.32
|
||||
*/
|
||||
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
|
||||
|
||||
@@ -62,22 +62,6 @@ public interface Request {
|
||||
/**
|
||||
* Returns the {@code Frame} that initiated this request.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* String frameUrl = request.frame().url();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Note that in some cases the frame is not available, and this method will throw.
|
||||
* <ul>
|
||||
* <li> When request originates in the Service Worker. You can use {@code request.serviceWorker()} to check that.</li>
|
||||
* <li> When navigation request is issued before the corresponding frame is created. You can use {@link
|
||||
* Request#isNavigationRequest Request.isNavigationRequest()} to check that.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Here is an example that handles all the cases:
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
Frame frame();
|
||||
@@ -107,9 +91,6 @@ public interface Request {
|
||||
/**
|
||||
* Whether this request is driving frame's navigation.
|
||||
*
|
||||
* <p> Some navigation requests are issued before the corresponding frame is created, and therefore do not have {@link
|
||||
* Request#frame Request.frame()} available.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
boolean isNavigationRequest();
|
||||
|
||||
@@ -154,10 +154,6 @@ public interface Route {
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public Object postData;
|
||||
/**
|
||||
* Request timeout in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
@@ -199,13 +195,6 @@ public interface Route {
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Request timeout in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
|
||||
*/
|
||||
public FetchOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
|
||||
/**
|
||||
* {@code WebError} class represents an unhandled exception thrown in the page. It is dispatched via the {@link
|
||||
* BrowserContext#onWebError BrowserContext.onWebError()} event.
|
||||
* <pre>{@code
|
||||
* // Log all uncaught errors to the terminal
|
||||
* context.onWebError(webError -> {
|
||||
* System.out.println("Uncaught exception: " + webError.error());
|
||||
* });
|
||||
*
|
||||
* // Navigate to a page with an exception.
|
||||
* page.navigate("data:text/html,<script>throw new Error('Test')</script>");
|
||||
* }</pre>
|
||||
*/
|
||||
public interface WebError {
|
||||
/**
|
||||
* The page that produced this unhandled exception, if any.
|
||||
*
|
||||
* @since v1.38
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Unhandled error that was thrown.
|
||||
*
|
||||
* @since v1.38
|
||||
*/
|
||||
String error();
|
||||
}
|
||||
|
||||
+40
-204
@@ -37,29 +37,10 @@ import java.util.regex.Pattern;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface LocatorAssertions {
|
||||
class IsAttachedOptions {
|
||||
public Boolean attached;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
public IsAttachedOptions setAttached(boolean attached) {
|
||||
this.attached = attached;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsAttachedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class IsCheckedOptions {
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -68,7 +49,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsCheckedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -77,12 +58,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsDisabledOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsDisabledOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -92,7 +73,7 @@ public interface LocatorAssertions {
|
||||
class IsEditableOptions {
|
||||
public Boolean editable;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -101,7 +82,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsEditableOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -110,12 +91,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsEmptyOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsEmptyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -125,7 +106,7 @@ public interface LocatorAssertions {
|
||||
class IsEnabledOptions {
|
||||
public Boolean enabled;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -134,7 +115,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsEnabledOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -143,12 +124,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsFocusedOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsFocusedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -157,12 +138,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsHiddenOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsHiddenOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -176,7 +157,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Double ratio;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -189,7 +170,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsInViewportOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -198,13 +179,13 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsVisibleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
public Boolean visible;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public IsVisibleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -222,7 +203,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -239,7 +220,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public ContainsTextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -255,25 +236,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasAttributeOptions {
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public HasAttributeOptions setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasAttributeOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -282,12 +250,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasClassOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasClassOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -296,12 +264,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasCountOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasCountOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -310,12 +278,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasCSSOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasCSSOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -324,12 +292,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasIdOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasIdOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -338,12 +306,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasJSPropertyOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasJSPropertyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -357,7 +325,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -374,7 +342,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasTextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -390,12 +358,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasValueOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasValueOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -404,12 +372,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasValuesOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasValuesOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -426,32 +394,6 @@ public interface LocatorAssertions {
|
||||
* @since v1.20
|
||||
*/
|
||||
LocatorAssertions not();
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
|
||||
* DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.33
|
||||
*/
|
||||
default void isAttached() {
|
||||
isAttached(null);
|
||||
}
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
|
||||
* DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.33
|
||||
*/
|
||||
void isAttached(IsAttachedOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
@@ -674,22 +616,9 @@ 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();
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.20
|
||||
@@ -701,22 +630,9 @@ 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();
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.20
|
||||
@@ -726,11 +642,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -771,11 +682,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -814,11 +720,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -859,11 +760,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -902,11 +798,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -947,11 +838,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -990,11 +876,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -1035,11 +916,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
@@ -1458,11 +1334,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1503,11 +1374,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1546,11 +1412,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1591,11 +1452,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1634,11 +1490,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1679,11 +1530,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1722,11 +1568,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
@@ -1767,11 +1608,6 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
|
||||
@@ -39,12 +39,12 @@ import java.util.regex.Pattern;
|
||||
public interface PageAssertions {
|
||||
class HasTitleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasTitleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -53,12 +53,12 @@ public interface PageAssertions {
|
||||
}
|
||||
class HasURLOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
* Time to retry the assertion for.
|
||||
*/
|
||||
public HasURLOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.APIRequestContext;
|
||||
import com.microsoft.playwright.APIResponse;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
@@ -10,7 +11,6 @@ import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.RequestOptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Base64;
|
||||
@@ -85,14 +85,11 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
byte[] bytes = null;
|
||||
if (options.data instanceof byte[]) {
|
||||
bytes = (byte[]) options.data;
|
||||
} else if (options.data instanceof String) {
|
||||
String stringData = (String) options.data;
|
||||
if (!isJsonContentType(options.headers) || isJsonParsable(stringData)) {
|
||||
bytes = (stringData).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
} else if (options.data instanceof String && !isJsonContentType(options.headers)) {
|
||||
bytes = ((String) options.data).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
if (bytes == null) {
|
||||
params.addProperty("jsonData", gson().toJson(options.data));
|
||||
params.add("jsonData", gson().toJsonTree(options.data));
|
||||
} else {
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
params.addProperty("postData", base64);
|
||||
@@ -205,21 +202,4 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
return impl;
|
||||
}
|
||||
|
||||
private static boolean isJsonParsable(String value) {
|
||||
try {
|
||||
JsonElement result = JsonParser.parseString(value);
|
||||
if (result != null && result.isJsonPrimitive()) {
|
||||
JsonPrimitive primitive = result.getAsJsonPrimitive();
|
||||
if (primitive.isString() && value.equals(primitive.getAsString())) {
|
||||
// Gson parses unquoted strings too, but we don't want to treat them
|
||||
// as valid JSON.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (JsonSyntaxException error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ 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;
|
||||
@@ -34,24 +32,13 @@ class ArtifactImpl extends ChannelOwner {
|
||||
|
||||
public InputStream createReadStream() {
|
||||
JsonObject result = sendMessage("stream").getAsJsonObject();
|
||||
if (!result.has("stream")) {
|
||||
return null;
|
||||
}
|
||||
Stream stream = connection.getExistingObject(result.getAsJsonObject("stream").get("guid").getAsString());
|
||||
return stream.stream();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -51,12 +51,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
private final WaitableEvent<EventType, ?> closePromise;
|
||||
final Map<String, BindingCallback> bindings = new HashMap<>();
|
||||
PageImpl ownerPage;
|
||||
private String closeReason;
|
||||
|
||||
private static final Map<EventType, String> eventSubscriptions() {
|
||||
Map<EventType, String> result = new HashMap<>();
|
||||
result.put(EventType.CONSOLE, "console");
|
||||
result.put(EventType.DIALOG, "dialog");
|
||||
result.put(EventType.REQUEST, "request");
|
||||
result.put(EventType.RESPONSE, "response");
|
||||
result.put(EventType.REQUESTFINISHED, "requestFinished");
|
||||
@@ -81,10 +77,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
CONSOLE,
|
||||
DIALOG,
|
||||
PAGE,
|
||||
WEBERROR,
|
||||
REQUEST,
|
||||
REQUESTFAILED,
|
||||
REQUESTFINISHED,
|
||||
@@ -117,16 +110,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
}
|
||||
|
||||
String effectiveCloseReason() {
|
||||
if (closeReason != null) {
|
||||
return closeReason;
|
||||
}
|
||||
if (browser != null) {
|
||||
return browser.closeReason;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<BrowserContext> handler) {
|
||||
listeners.add(EventType.CLOSE, handler);
|
||||
@@ -137,26 +120,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.remove(EventType.CLOSE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsoleMessage(Consumer<ConsoleMessage> handler) {
|
||||
listeners.add(EventType.CONSOLE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offConsoleMessage(Consumer<ConsoleMessage> handler) {
|
||||
listeners.remove(EventType.CONSOLE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Consumer<Dialog> handler) {
|
||||
listeners.add(EventType.DIALOG, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offDialog(Consumer<Dialog> handler) {
|
||||
listeners.remove(EventType.DIALOG, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPage(Consumer<Page> handler) {
|
||||
listeners.add(EventType.PAGE, handler);
|
||||
@@ -167,16 +130,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.remove(EventType.PAGE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebError(Consumer<WebError> handler) {
|
||||
listeners.add(EventType.WEBERROR, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offWebError(Consumer<WebError> handler) {
|
||||
listeners.remove(EventType.WEBERROR, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequest(Consumer<Request> handler) {
|
||||
listeners.add(EventType.REQUEST, handler);
|
||||
@@ -238,24 +191,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@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(CloseOptions options) {
|
||||
withLogging("BrowserContext.close", () -> closeImpl(options));
|
||||
public void close() {
|
||||
withLogging("BrowserContext.close", () -> closeImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -263,13 +200,9 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
|
||||
}
|
||||
|
||||
private void closeImpl(CloseOptions options) {
|
||||
private void closeImpl() {
|
||||
if (!closeWasCalled) {
|
||||
closeWasCalled = true;
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
for (Map.Entry<String, HarRecorder> entry : harRecorders.entrySet()) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("harId", entry.getKey());
|
||||
@@ -291,8 +224,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
artifact.delete();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("close", params);
|
||||
sendMessage("close");
|
||||
}
|
||||
runUntil(() -> {}, closePromise);
|
||||
}
|
||||
@@ -489,10 +421,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public void setDefaultNavigationTimeout(double timeout) {
|
||||
setDefaultNavigationTimeoutImpl(timeout);
|
||||
}
|
||||
|
||||
void setDefaultNavigationTimeoutImpl(Double timeout) {
|
||||
withLogging("BrowserContext.setDefaultNavigationTimeout", () -> {
|
||||
timeoutSettings.setDefaultNavigationTimeout(timeout);
|
||||
JsonObject params = new JsonObject();
|
||||
@@ -503,10 +431,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public void setDefaultTimeout(double timeout) {
|
||||
setDefaultTimeoutImpl(timeout);
|
||||
}
|
||||
|
||||
void setDefaultTimeoutImpl(Double timeout) {
|
||||
withLogging("BrowserContext.setDefaultTimeout", () -> {
|
||||
timeoutSettings.setDefaultTimeout(timeout);
|
||||
JsonObject params = new JsonObject();
|
||||
@@ -592,18 +516,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
runUntil(() -> {}, new WaitableRace<>(waitables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable code) {
|
||||
return withWaitLogging("BrowserContext.waitForConsoleMessage", logger -> waitForConsoleMessageImpl(options, code));
|
||||
}
|
||||
|
||||
private ConsoleMessage waitForConsoleMessageImpl(WaitForConsoleMessageOptions options, Runnable code) {
|
||||
if (options == null) {
|
||||
options = new WaitForConsoleMessageOptions();
|
||||
}
|
||||
return waitForEventWithTimeout(EventType.CONSOLE, code, options.predicate, options.timeout);
|
||||
}
|
||||
|
||||
private class WaitableContextClose<R> extends WaitableEvent<EventType, R> {
|
||||
WaitableContextClose() {
|
||||
super(BrowserContextImpl.this.listeners, EventType.CLOSE);
|
||||
@@ -611,7 +523,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public R get() {
|
||||
throw new TargetClosedError(effectiveCloseReason());
|
||||
throw new PlaywrightException("Context closed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,7 +544,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
updateInterceptionPatterns();
|
||||
}
|
||||
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
|
||||
route.resume(null, true);
|
||||
route.resume();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,38 +554,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
protected void handleEvent(String event, JsonObject params) {
|
||||
if ("dialog".equals(event)) {
|
||||
String guid = params.getAsJsonObject("dialog").get("guid").getAsString();
|
||||
DialogImpl dialog = connection.getExistingObject(guid);
|
||||
boolean hasListeners = false;
|
||||
if (listeners.hasListeners(EventType.DIALOG)) {
|
||||
hasListeners = true;
|
||||
listeners.notify(EventType.DIALOG, dialog);
|
||||
}
|
||||
PageImpl page = dialog.page();
|
||||
if (page != null) {
|
||||
if (page.listeners.hasListeners(PageImpl.EventType.DIALOG)) {
|
||||
hasListeners = true;
|
||||
page.listeners.notify(PageImpl.EventType.DIALOG, dialog);
|
||||
}
|
||||
}
|
||||
// Although we do similar handling on the server side, we still need this logic
|
||||
// on the client side due to a possible race condition between two async calls:
|
||||
// a) removing "dialog" listener subscription (client->server)
|
||||
// b) actual "dialog" event (server->client)
|
||||
if (!hasListeners) {
|
||||
if ("beforeunload".equals(dialog.type())) {
|
||||
try {
|
||||
dialog.accept();
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
} else if ("route".equals(event)) {
|
||||
if ("route".equals(event)) {
|
||||
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
|
||||
route.browserContext = this;
|
||||
handleRoute(route);
|
||||
} else if ("page".equals(event)) {
|
||||
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
@@ -688,13 +570,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
if (binding != null) {
|
||||
bindingCall.call(binding);
|
||||
}
|
||||
} else if ("console".equals(event)) {
|
||||
ConsoleMessageImpl message = new ConsoleMessageImpl(connection, params);
|
||||
listeners.notify(BrowserContextImpl.EventType.CONSOLE, message);
|
||||
PageImpl page = message.page();
|
||||
if (page != null) {
|
||||
page.listeners.notify(PageImpl.EventType.CONSOLE, message);
|
||||
}
|
||||
} else if ("request".equals(event)) {
|
||||
String guid = params.getAsJsonObject("request").get("guid").getAsString();
|
||||
RequestImpl request = connection.getExistingObject(guid);
|
||||
@@ -738,25 +613,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
page.listeners.notify(PageImpl.EventType.RESPONSE, response);
|
||||
}
|
||||
} else if ("pageError".equals(event)) {
|
||||
SerializedError error = gson().fromJson(params.getAsJsonObject("error"), SerializedError.class);
|
||||
String errorStr = "";
|
||||
if (error.error != null) {
|
||||
errorStr = error.error.name + ": " + error.error.message;
|
||||
if (error.error.stack != null && !error.error.stack.isEmpty()) {
|
||||
errorStr += "\n" + error.error.stack;
|
||||
}
|
||||
}
|
||||
PageImpl page;
|
||||
try {
|
||||
page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
} catch (PlaywrightException e) {
|
||||
page = null;
|
||||
}
|
||||
listeners.notify(BrowserContextImpl.EventType.WEBERROR, new WebErrorImpl(page, errorStr));
|
||||
if (page != null) {
|
||||
page.listeners.notify(PageImpl.EventType.PAGEERROR, errorStr);
|
||||
}
|
||||
} else if ("close".equals(event)) {
|
||||
didClose();
|
||||
}
|
||||
@@ -769,10 +625,9 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
|
||||
WritableStream createTempFile(String name, long lastModifiedMs) {
|
||||
WritableStream createTempFile(String name) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("name", name);
|
||||
params.addProperty("lastModifiedMs", lastModifiedMs);
|
||||
JsonObject json = sendMessage("createTempFile", params).getAsJsonObject();
|
||||
return connection.getExistingObject(json.getAsJsonObject("writableStream").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ 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;
|
||||
@@ -41,8 +42,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
private boolean isConnected = true;
|
||||
BrowserTypeImpl browserType;
|
||||
BrowserType.LaunchOptions launchOptions;
|
||||
private Path tracePath;
|
||||
String closeReason;
|
||||
|
||||
enum EventType {
|
||||
DISCONNECTED,
|
||||
@@ -68,15 +67,11 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
withLogging("Browser.close", () -> closeImpl(options));
|
||||
public void close() {
|
||||
withLogging("Browser.close", () -> closeImpl());
|
||||
}
|
||||
|
||||
private void closeImpl(CloseOptions options) {
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
private void closeImpl() {
|
||||
if (isConnectedOverWebSocket) {
|
||||
try {
|
||||
connection.close();
|
||||
@@ -188,7 +183,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
if (options.recordVideoDir != null) {
|
||||
JsonObject recordVideo = new JsonObject();
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toString());
|
||||
if (options.recordVideoSize != null) {
|
||||
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
|
||||
}
|
||||
@@ -208,10 +203,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
params.addProperty("noDefaultViewport", true);
|
||||
}
|
||||
}
|
||||
params.remove("acceptDownloads");
|
||||
if (options.acceptDownloads != null) {
|
||||
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
|
||||
}
|
||||
JsonElement result = sendMessage("newContext", params);
|
||||
BrowserContextImpl context = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("context").get("guid").getAsString());
|
||||
context.videosDir = options.recordVideoDir;
|
||||
@@ -240,7 +231,6 @@ 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());
|
||||
@@ -255,20 +245,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
|
||||
private byte[] stopTracingImpl() {
|
||||
JsonObject json = sendMessage("stopTracing").getAsJsonObject();
|
||||
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;
|
||||
return Base64.getDecoder().decode(json.get("binary").getAsString());
|
||||
}
|
||||
|
||||
private Page newPageImpl(NewPageOptions options) {
|
||||
@@ -299,13 +276,6 @@ 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,6 +33,8 @@ import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
|
||||
class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
LocalUtils localUtils;
|
||||
|
||||
BrowserTypeImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
@@ -201,7 +203,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
}
|
||||
if (options.recordVideoDir != null) {
|
||||
JsonObject recordVideo = new JsonObject();
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toString());
|
||||
if (options.recordVideoSize != null) {
|
||||
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
|
||||
}
|
||||
@@ -221,10 +223,6 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
params.addProperty("noDefaultViewport", true);
|
||||
}
|
||||
}
|
||||
params.remove("acceptDownloads");
|
||||
if (options.acceptDownloads != null) {
|
||||
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
|
||||
}
|
||||
JsonObject json = sendMessage("launchPersistentContext", params).getAsJsonObject();
|
||||
BrowserContextImpl context = connection.getExistingObject(json.getAsJsonObject("context").get("guid").getAsString());
|
||||
context.videosDir = options.recordVideoDir;
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
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,7 +34,6 @@ class ChannelOwner extends LoggingSupport {
|
||||
final String type;
|
||||
final String guid;
|
||||
final JsonObject initializer;
|
||||
private boolean wasCollected;
|
||||
|
||||
protected ChannelOwner(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
this(parent.connection, parent, type, guid, initializer);
|
||||
@@ -58,16 +57,15 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
}
|
||||
|
||||
void disposeChannelOwner(boolean wasGarbageCollected) {
|
||||
void disconnect() {
|
||||
// Clean up from parent and connection.
|
||||
if (parent != null) {
|
||||
parent.objects.remove(guid);
|
||||
}
|
||||
connection.unregisterObject(guid);
|
||||
wasCollected = wasGarbageCollected;
|
||||
// Dispose all children.
|
||||
for (ChannelOwner child : new ArrayList<>(objects.values())) {
|
||||
child.disposeChannelOwner(wasGarbageCollected);
|
||||
child.disconnect();
|
||||
}
|
||||
objects.clear();
|
||||
}
|
||||
@@ -93,7 +91,6 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
|
||||
WaitableResult<JsonElement> sendMessageAsync(String method, JsonObject params) {
|
||||
checkNotCollected();
|
||||
return connection.sendMessageAsync(guid, method, params);
|
||||
}
|
||||
|
||||
@@ -102,15 +99,9 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
|
||||
JsonElement sendMessage(String method, JsonObject params) {
|
||||
checkNotCollected();
|
||||
return connection.sendMessage(guid, method, params);
|
||||
}
|
||||
|
||||
private void checkNotCollected() {
|
||||
if (wasCollected)
|
||||
throw new PlaywrightException("The object has been collected to prevent unbounded heap growth.");
|
||||
}
|
||||
|
||||
<T> T runUntil(Runnable code, Waitable<T> waitable) {
|
||||
try {
|
||||
code.run();
|
||||
|
||||
@@ -25,9 +25,7 @@ import com.microsoft.playwright.TimeoutError;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
@@ -40,7 +38,6 @@ class Message {
|
||||
JsonObject params;
|
||||
JsonElement result;
|
||||
SerializedError error;
|
||||
JsonArray log;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -209,30 +206,6 @@ public class Connection {
|
||||
dispatch(messageObj);
|
||||
}
|
||||
|
||||
private static String formatCallLog(JsonArray log) {
|
||||
if (log == null) {
|
||||
return "";
|
||||
}
|
||||
boolean allEmpty = true;
|
||||
for (JsonElement e: log) {
|
||||
if (!e.getAsString().isEmpty()) {
|
||||
allEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allEmpty) {
|
||||
return "";
|
||||
}
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add("");
|
||||
lines.add("Call log:");
|
||||
for (JsonElement e: log) {
|
||||
lines.add("- " + e.getAsString());
|
||||
}
|
||||
lines.add("");
|
||||
return String.join("\n", lines);
|
||||
}
|
||||
|
||||
private void dispatch(Message message) {
|
||||
// System.out.println("Message: " + message.method + " " + message.id);
|
||||
if (message.id != 0) {
|
||||
@@ -245,16 +218,12 @@ public class Connection {
|
||||
if (message.error == null) {
|
||||
callback.complete(message.result);
|
||||
} else {
|
||||
String callLog = formatCallLog(message.log);
|
||||
if (message.error.error == null) {
|
||||
callback.completeExceptionally(new PlaywrightException(message.error + callLog));
|
||||
callback.completeExceptionally(new PlaywrightException(message.error.toString()));
|
||||
} else if ("TimeoutError".equals(message.error.error.name)) {
|
||||
callback.completeExceptionally(new TimeoutError(message.error.error + callLog));
|
||||
} else if ("TargetClosedError".equals(message.error.error.name)) {
|
||||
callback.completeExceptionally(new TargetClosedError(message.error.error + callLog));
|
||||
|
||||
callback.completeExceptionally(new TimeoutError(message.error.error.toString()));
|
||||
} else {
|
||||
callback.completeExceptionally(new DriverException(message.error.error + callLog));
|
||||
callback.completeExceptionally(new DriverException(message.error.error));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -283,8 +252,7 @@ public class Connection {
|
||||
return;
|
||||
}
|
||||
if (message.method.equals("__dispose__")) {
|
||||
boolean wasCollected = message.params.has("reason") && "gc".equals(message.params.get("reason").getAsString());
|
||||
object.disposeChannelOwner(wasCollected);
|
||||
object.disconnect();
|
||||
return;
|
||||
}
|
||||
object.handleEvent(message.method, message.params);
|
||||
@@ -325,6 +293,9 @@ public class Connection {
|
||||
case "BrowserContext":
|
||||
result = new BrowserContextImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "ConsoleMessage":
|
||||
result = new ConsoleMessageImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "Dialog":
|
||||
result = new DialogImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
@@ -388,9 +359,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -20,27 +20,15 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.ConsoleMessage;
|
||||
import com.microsoft.playwright.JSHandle;
|
||||
import com.microsoft.playwright.Page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
public class ConsoleMessageImpl implements ConsoleMessage {
|
||||
private final Connection connection;
|
||||
private PageImpl page;
|
||||
private final JsonObject 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 class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
|
||||
public ConsoleMessageImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
public String type() {
|
||||
@@ -67,9 +55,4 @@ public class ConsoleMessageImpl implements ConsoleMessage {
|
||||
location.get("lineNumber").getAsNumber() + ":" +
|
||||
location.get("columnNumber").getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,10 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Dialog;
|
||||
import com.microsoft.playwright.Page;
|
||||
|
||||
class DialogImpl extends ChannelOwner implements Dialog {
|
||||
private PageImpl page;
|
||||
|
||||
DialogImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
// Note: dialogs that open early during page initialization block it.
|
||||
// Therefore, we must report the dialog without a page to be able to handle it.
|
||||
if (initializer.has("page")) {
|
||||
page = connection.getExistingObject(initializer.getAsJsonObject("page").get("guid").getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,11 +50,6 @@ class DialogImpl extends ChannelOwner implements Dialog {
|
||||
return initializer.get("message").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return initializer.get("type").getAsString();
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
class DriverException extends PlaywrightException {
|
||||
DriverException(String error) {
|
||||
super(error);
|
||||
DriverException(SerializedError.Error error) {
|
||||
super(error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,13 @@ import com.microsoft.playwright.options.SelectOption;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.*;
|
||||
import static com.microsoft.playwright.impl.Utils.*;
|
||||
import static com.microsoft.playwright.impl.Utils.addFilePathUploadParams;
|
||||
import static com.microsoft.playwright.impl.Utils.addLargeFileUploadParams;
|
||||
import static com.microsoft.playwright.options.ScreenshotType.JPEG;
|
||||
import static com.microsoft.playwright.options.ScreenshotType.PNG;
|
||||
|
||||
@@ -466,12 +467,16 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
|
||||
if (frame == null) {
|
||||
throw new Error("Cannot set input files to detached element");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
if (hasLargeFile(files)) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addLargeFileUploadParams(files, params, frame.page().context());
|
||||
sendMessage("setInputFilePaths", params);
|
||||
} else {
|
||||
setInputFilesImpl(Utils.toFilePayloads(files), options);
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addFilePathUploadParams(files, params, frame.page().context());
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -761,13 +761,17 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
}
|
||||
|
||||
void setInputFilesImpl(String selector, Path[] files, SetInputFilesOptions options) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
if (hasLargeFile(files)) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addLargeFileUploadParams(files, params, page.context());
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("setInputFilePaths", params);
|
||||
} else {
|
||||
setInputFilesImpl(selector, Utils.toFilePayloads(files), options);
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addFilePathUploadParams(files, params, page.context());
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -787,7 +791,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
params.add("payloads", toJsonArray(files));
|
||||
params.add("files", toJsonArray(files));
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,14 +86,12 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void hasAttribute(String name, String text, HasAttributeOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
expected.string = text;
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
hasAttribute(name, expected, text, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAttribute(String name, Pattern pattern, HasAttributeOptions options) {
|
||||
ExpectedTextValue expected = expectedRegex(pattern);
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
hasAttribute(name, expected, pattern, options);
|
||||
}
|
||||
|
||||
@@ -107,7 +105,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
if (expectedValue instanceof Pattern) {
|
||||
message += " matching regex";
|
||||
}
|
||||
expectImpl("to.have.attribute.value", expectedText, expectedValue, message, commonOptions);
|
||||
expectImpl("to.have.attribute", expectedText, expectedValue, message, commonOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,14 +357,6 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
return new LocatorAssertionsImpl(actualLocator, !isNot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isAttached(IsAttachedOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean attached = options == null || options.attached == null || options.attached == true;
|
||||
String message = "Locator expected to be " + (attached ? "attached" : "detached");
|
||||
expectTrue(attached ? "to.be.attached" : "to.be.detached", message, frameOptions);
|
||||
}
|
||||
|
||||
private static Boolean shouldIgnoreCase(Object options) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
|
||||
@@ -29,21 +29,12 @@ class LocatorImpl implements Locator {
|
||||
if (options.hasText != null) {
|
||||
selector += " >> internal:has-text=" + escapeForTextSelector(options.hasText, false);
|
||||
}
|
||||
if (options.hasNotText != null) {
|
||||
selector += " >> internal:has-not-text=" + escapeForTextSelector(options.hasNotText, false);
|
||||
}
|
||||
if (options.has != null) {
|
||||
LocatorImpl locator = (LocatorImpl) options.has;
|
||||
if (locator.frame != frame)
|
||||
throw new Error("Inner 'has' locator must belong to the same frame.");
|
||||
selector += " >> internal:has=" + gson().toJson(locator.selector);
|
||||
}
|
||||
if (options.hasNot != null) {
|
||||
LocatorImpl locator = (LocatorImpl) options.hasNot;
|
||||
if (locator.frame != frame)
|
||||
throw new Error("Inner 'hasNot' locator must belong to the same frame.");
|
||||
selector += " >> internal:has-not=" + gson().toJson(locator.selector);
|
||||
}
|
||||
}
|
||||
this.selector = selector;
|
||||
}
|
||||
@@ -91,14 +82,6 @@ class LocatorImpl implements Locator {
|
||||
return (List<String>) frame.evalOnSelectorAll(selector, "ee => ee.map(e => e.textContent || '')");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator and(Locator locator) {
|
||||
LocatorImpl other = (LocatorImpl) locator;
|
||||
if (other.frame != frame)
|
||||
throw new Error("Locators must belong to the same frame.");
|
||||
return new LocatorImpl(frame, selector + " >> internal:and=" + gson().toJson(other.selector), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blur(BlurOptions options) {
|
||||
frame.withLogging("Locator.blur", () -> blurImpl(options));
|
||||
@@ -407,7 +390,7 @@ class LocatorImpl implements Locator {
|
||||
if (other.frame != frame) {
|
||||
throw new PlaywrightException("Locators must belong to the same frame.");
|
||||
}
|
||||
return new LocatorImpl(frame, this.selector + " >> internal:chain=" + gson().toJson(other.selector), options);
|
||||
return locator(other.selector, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -415,14 +398,6 @@ class LocatorImpl implements Locator {
|
||||
return new LocatorImpl(frame, selector + " >> nth=" + index, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator or(Locator locator) {
|
||||
LocatorImpl other = (LocatorImpl) locator;
|
||||
if (other.frame != frame)
|
||||
throw new Error("Locators must belong to the same frame.");
|
||||
return new LocatorImpl(frame, selector + " >> internal:or=" + gson().toJson(other.selector), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page page() {
|
||||
return frame.page();
|
||||
@@ -436,11 +411,6 @@ class LocatorImpl implements Locator {
|
||||
frame.press(selector, key, convertType(options, Frame.PressOptions.class).setStrict(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pressSequentially(String text, PressSequentiallyOptions options) {
|
||||
type(text, convertType(options, TypeOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] screenshot(ScreenshotOptions options) {
|
||||
return withElement((h, o) -> h.screenshot(o), convertType(options, ElementHandle.ScreenshotOptions.class));
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.microsoft.playwright.options.AriaRole;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.toJsRegexFlags;
|
||||
|
||||
public class LocatorUtils {
|
||||
@@ -26,7 +25,10 @@ public class LocatorUtils {
|
||||
}
|
||||
|
||||
private static String getByAttributeTextSelector(String attrName, Object value, boolean exact) {
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector(value, exact) + "]";
|
||||
if (value instanceof Pattern) {
|
||||
return "internal:attr=[" + attrName + "=" + toJsRegExp((Pattern) value) + "]";
|
||||
}
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector((String) value, exact) + "]";
|
||||
}
|
||||
|
||||
static String getByTestIdSelector(Object testId) {
|
||||
@@ -69,7 +71,14 @@ public class LocatorUtils {
|
||||
if (options.level != null)
|
||||
addAttr(result, "level", options.level.toString());
|
||||
if (options.name != null) {
|
||||
String name = escapeForAttributeSelector(options.name, options.exact != null && options.exact);
|
||||
String name;
|
||||
if (options.name instanceof String) {
|
||||
name = escapeForAttributeSelector((String) options.name, options.exact != null && options.exact);
|
||||
} else if (options.name instanceof Pattern) {
|
||||
name = toJsRegExp((Pattern) options.name);
|
||||
} else {
|
||||
throw new IllegalArgumentException("options.name can be String or Pattern, found: " + options.name);
|
||||
}
|
||||
addAttr(result, "name", name);
|
||||
}
|
||||
if (options.pressed != null)
|
||||
@@ -78,33 +87,38 @@ public class LocatorUtils {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static String escapeRegexForSelector(Pattern re) {
|
||||
// Even number of backslashes followed by the quote -> insert a backslash.
|
||||
return toJsRegExp(re).replaceAll("(^|[^\\\\])(\\\\\\\\)*([\"'`])", "$1$2\\\\$3").replaceAll(">>", "\\\\>\\\\>");
|
||||
static String escapeForTextSelector(Object text, boolean exact) {
|
||||
return escapeForTextSelector(text, exact, false);
|
||||
}
|
||||
|
||||
static String escapeForTextSelector(Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return escapeRegexForSelector((Pattern) value);
|
||||
private static String escapeForTextSelector(Object param, boolean exact, boolean caseSensitive) {
|
||||
if (param instanceof Pattern) {
|
||||
return toJsRegExp((Pattern) param);
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return gson().toJson(value) + (exact ? "s" : "i");
|
||||
if (!(param instanceof String)) {
|
||||
throw new IllegalArgumentException("text parameter must be Pattern or String: " + param);
|
||||
}
|
||||
throw new IllegalArgumentException("text parameter must be Pattern or String: " + value);
|
||||
String text = (String) param;
|
||||
if (exact) {
|
||||
return '"' + text.replace("\"", "\\\"") + '"';
|
||||
}
|
||||
|
||||
if (text.contains("\"") || text.contains(">>") || text.startsWith("/")) {
|
||||
return "/" + escapeForRegex(text).replaceAll("\\s+", "\\\\s+") + "/" + (caseSensitive ? "" : "i");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static String escapeForAttributeSelector(Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return escapeRegexForSelector((Pattern) value);
|
||||
}
|
||||
if (value instanceof String) {
|
||||
// TODO: this should actually be
|
||||
// cssEscape(value).replace(/\\ /g, ' ')
|
||||
// However, our attribute selectors do not conform to CSS parsing spec,
|
||||
// so we escape them differently.
|
||||
return '"' + ((String) value).replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i");
|
||||
}
|
||||
throw new IllegalArgumentException("Attribute can be String or Pattern, found: " + value);
|
||||
private static String escapeForRegex(String text) {
|
||||
return text.replaceAll("[.*+?^>${}()|\\[\\]\\\\]", "\\\\\\\\$0");
|
||||
}
|
||||
|
||||
private static String escapeForAttributeSelector(String value, boolean exact) {
|
||||
// TODO: this should actually be
|
||||
// cssEscape(value).replace(/\\ /g, ' ')
|
||||
// However, our attribute selectors do not conform to CSS parsing spec,
|
||||
// so we escape them differently.
|
||||
return '"' + value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i");
|
||||
}
|
||||
|
||||
private static String toJsRegExp(Pattern pattern) {
|
||||
|
||||
@@ -51,8 +51,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private final Set<FrameImpl> frames = new LinkedHashSet<>();
|
||||
private static final Map<EventType, String> eventSubscriptions() {
|
||||
Map<EventType, String> result = new HashMap<>();
|
||||
result.put(EventType.CONSOLE, "console");
|
||||
result.put(EventType.DIALOG, "dialog");
|
||||
result.put(EventType.REQUEST, "request");
|
||||
result.put(EventType.RESPONSE, "response");
|
||||
result.put(EventType.REQUESTFINISHED, "requestFinished");
|
||||
@@ -68,7 +66,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private final TimeoutSettings timeoutSettings;
|
||||
private VideoImpl video;
|
||||
private final PageImpl opener;
|
||||
private String closeReason;
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
@@ -116,7 +113,22 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
protected void handleEvent(String event, JsonObject params) {
|
||||
if ("worker".equals(event)) {
|
||||
if ("dialog".equals(event)) {
|
||||
String guid = params.getAsJsonObject("dialog").get("guid").getAsString();
|
||||
DialogImpl dialog = connection.getExistingObject(guid);
|
||||
if (listeners.hasListeners(EventType.DIALOG)) {
|
||||
listeners.notify(EventType.DIALOG, dialog);
|
||||
} else {
|
||||
if ("beforeunload".equals(dialog.type())) {
|
||||
try {
|
||||
dialog.accept();
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
} else if ("worker".equals(event)) {
|
||||
String guid = params.getAsJsonObject("worker").get("guid").getAsString();
|
||||
WorkerImpl worker = connection.getExistingObject(guid);
|
||||
worker.page = this;
|
||||
@@ -126,6 +138,10 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
String guid = params.getAsJsonObject("webSocket").get("guid").getAsString();
|
||||
WebSocketImpl webSocket = connection.getExistingObject(guid);
|
||||
listeners.notify(EventType.WEBSOCKET, webSocket);
|
||||
} else if ("console".equals(event)) {
|
||||
String guid = params.getAsJsonObject("message").get("guid").getAsString();
|
||||
ConsoleMessageImpl message = connection.getExistingObject(guid);
|
||||
listeners.notify(EventType.CONSOLE, message);
|
||||
} else if ("download".equals(event)) {
|
||||
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
@@ -172,7 +188,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
listeners.notify(EventType.FRAMEDETACHED, frame);
|
||||
} else if ("route".equals(event)) {
|
||||
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
|
||||
route.browserContext = browserContext;
|
||||
Router.HandleResult handled = routes.handle(route);
|
||||
if (handled != Router.HandleResult.NoMatchingHandler) {
|
||||
updateInterceptionPatterns();
|
||||
@@ -184,6 +199,16 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
forceVideo().setArtifact(artifact);
|
||||
} else if ("pageError".equals(event)) {
|
||||
SerializedError error = gson().fromJson(params.getAsJsonObject("error"), SerializedError.class);
|
||||
String errorStr = "";
|
||||
if (error.error != null) {
|
||||
errorStr = error.error.name + ": " + error.error.message;
|
||||
if (error.error.stack != null && !error.error.stack.isEmpty()) {
|
||||
errorStr += "\n" + error.error.stack;
|
||||
}
|
||||
}
|
||||
listeners.notify(EventType.PAGEERROR, errorStr);
|
||||
} else if ("crash".equals(event)) {
|
||||
listeners.notify(EventType.CRASH, this);
|
||||
} else if ("close".equals(event)) {
|
||||
@@ -201,13 +226,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
|
||||
private String effectiveCloseReason() {
|
||||
if (closeReason != null) {
|
||||
return closeReason;
|
||||
}
|
||||
return browserContext.effectiveCloseReason();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<Page> handler) {
|
||||
listeners.add(EventType.CLOSE, handler);
|
||||
@@ -496,7 +514,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
try {
|
||||
if (ownedContext != null) {
|
||||
ownedContext.close();
|
||||
@@ -936,16 +953,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
@Override
|
||||
public void pause() {
|
||||
withLogging("Page.pause", () -> {
|
||||
Double defaultNavigationTimeout = browserContext.timeoutSettings.defaultNavigationTimeout();
|
||||
Double defaultTimeout = browserContext.timeoutSettings.defaultTimeout();
|
||||
browserContext.setDefaultNavigationTimeoutImpl(0.0);
|
||||
browserContext.setDefaultTimeoutImpl(0.0);
|
||||
try {
|
||||
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
|
||||
} finally {
|
||||
browserContext.setDefaultNavigationTimeoutImpl(defaultNavigationTimeout);
|
||||
browserContext.setDefaultTimeoutImpl(defaultTimeout);
|
||||
}
|
||||
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -955,6 +963,9 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
private byte[] pdfImpl(PdfOptions options) {
|
||||
if (!browserContext.browser().isChromium()) {
|
||||
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new PdfOptions();
|
||||
}
|
||||
@@ -1350,7 +1361,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new TargetClosedError(effectiveCloseReason());
|
||||
throw new PlaywrightException("Page closed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1361,7 +1372,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new TargetClosedError("Page crashed");
|
||||
throw new PlaywrightException("Page crashed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
private final BrowserTypeImpl webkit;
|
||||
private final SelectorsImpl selectors;
|
||||
private final APIRequestImpl apiRequest;
|
||||
private final LocalUtils localUtils;
|
||||
private SharedSelectors sharedSelectors;
|
||||
|
||||
PlaywrightImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
@@ -73,6 +74,10 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
|
||||
selectors = connection.getExistingObject(initializer.getAsJsonObject("selectors").get("guid").getAsString());
|
||||
apiRequest = new APIRequestImpl(this);
|
||||
localUtils = connection.getExistingObject(initializer.getAsJsonObject("utils").get("guid").getAsString());
|
||||
chromium.localUtils = localUtils;
|
||||
firefox.localUtils = localUtils;
|
||||
webkit.localUtils = localUtils;
|
||||
}
|
||||
|
||||
void initSharedSelectors(PlaywrightImpl parent) {
|
||||
|
||||
@@ -32,7 +32,6 @@ class SerializedValue{
|
||||
String v;
|
||||
String d;
|
||||
String u;
|
||||
String bi;
|
||||
public static class R {
|
||||
String p;
|
||||
String f;
|
||||
@@ -47,10 +46,6 @@ class SerializedValue{
|
||||
Number h;
|
||||
Integer id;
|
||||
Integer ref;
|
||||
// JS representation of Map: [[key1, value1], [key2, value2], ...].
|
||||
SerializedValue m;
|
||||
// JS representation of Set: [item1, item2, ...].
|
||||
SerializedValue se;
|
||||
}
|
||||
|
||||
class SerializedArgument{
|
||||
|
||||
@@ -78,13 +78,7 @@ public class RequestImpl extends ChannelOwner implements Request {
|
||||
|
||||
@Override
|
||||
public FrameImpl frame() {
|
||||
FrameImpl frame = connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
|
||||
if (frame.page == null) {
|
||||
throw new PlaywrightException("Frame for this navigation request is not available, because the request\n" +
|
||||
"was issued before the frame is created. You can check whether the request\n" +
|
||||
"is a navigation request by calling isNavigationRequest() method.");
|
||||
}
|
||||
return frame;
|
||||
return connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
public class RouteImpl extends ChannelOwner implements Route {
|
||||
private final RequestImpl request;
|
||||
private boolean handled;
|
||||
BrowserContextImpl browserContext;
|
||||
|
||||
boolean fallbackCalled;
|
||||
boolean shouldResumeIfFallbackIsCalled;
|
||||
|
||||
@@ -47,7 +47,6 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
withLogging("Route.abort", () -> {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("errorCode", errorCode);
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
sendMessageAsync("abort", params);
|
||||
});
|
||||
}
|
||||
@@ -58,13 +57,9 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
|
||||
@Override
|
||||
public void resume(ResumeOptions options) {
|
||||
resume(options, false);
|
||||
}
|
||||
|
||||
void resume(ResumeOptions options, boolean isFallback) {
|
||||
startHandling();
|
||||
applyOverrides(convertType(options, FallbackOptions.class));
|
||||
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume(), isFallback));
|
||||
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +70,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
}
|
||||
applyOverrides(options);
|
||||
if (shouldResumeIfFallbackIsCalled) {
|
||||
resume(null, true);
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,14 +91,11 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
} else {
|
||||
options.data = request.postDataBuffer();
|
||||
}
|
||||
if (fetchOptions != null && fetchOptions.timeout != null) {
|
||||
options.timeout = fetchOptions.timeout;
|
||||
}
|
||||
APIRequestContextImpl apiRequest = browserContext.request();
|
||||
APIRequestContextImpl apiRequest = request.frame().page().context().request();
|
||||
String url = (fetchOptions == null || fetchOptions.url == null) ? request().url() : fetchOptions.url;
|
||||
return apiRequest.fetch(url, options);
|
||||
}
|
||||
|
||||
|
||||
private void applyOverrides(FallbackOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
@@ -118,7 +110,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
request().applyFallbackOverrides(overrides);
|
||||
}
|
||||
|
||||
private void resumeImpl(RequestImpl.FallbackOverrides options, boolean isFallback) {
|
||||
private void resumeImpl(RequestImpl.FallbackOverrides options) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (options != null) {
|
||||
if (options.url != null) {
|
||||
@@ -135,8 +127,6 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
params.addProperty("postData", base64);
|
||||
}
|
||||
}
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
params.addProperty("isFallback", isFallback);
|
||||
sendMessageAsync("continue", params);
|
||||
}
|
||||
|
||||
@@ -231,7 +221,6 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
if (fetchResponseUid != null) {
|
||||
params.addProperty("fetchResponseUid", fetchResponseUid);
|
||||
}
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
sendMessageAsync("fulfill", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ 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;
|
||||
@@ -163,8 +162,6 @@ 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();
|
||||
@@ -239,9 +236,6 @@ 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)
|
||||
@@ -280,16 +274,6 @@ class Serialization {
|
||||
}
|
||||
return (T) map;
|
||||
}
|
||||
if (value.m != null) {
|
||||
Map<?, ?> map = new LinkedHashMap<>();
|
||||
idToValue.put(value.id, map);
|
||||
return (T) map;
|
||||
}
|
||||
if (value.se != null) {
|
||||
Map<?, ?> map = new LinkedHashMap<>();
|
||||
idToValue.put(value.id, map);
|
||||
return (T) map;
|
||||
}
|
||||
throw new PlaywrightException("Unexpected result: " + gson().toJson(value));
|
||||
}
|
||||
|
||||
@@ -346,11 +330,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -369,11 +348,7 @@ class Serialization {
|
||||
for (Map.Entry<String, ?> e : map.entrySet()) {
|
||||
JsonObject item = new JsonObject();
|
||||
item.addProperty("name", e.getKey());
|
||||
if (e.getValue() instanceof FilePayload) {
|
||||
item.add("value", gson().toJsonTree(e.getValue()));
|
||||
} else {
|
||||
item.addProperty("value", "" + e.getValue());
|
||||
}
|
||||
item.add("value", gson().toJsonTree(e.getValue()));
|
||||
array.add(item);
|
||||
}
|
||||
return array;
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
public class TargetClosedError extends PlaywrightException {
|
||||
public TargetClosedError() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public TargetClosedError(String message) {
|
||||
super(message != null ? message : "Target page, context or browser has been closed");
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,11 @@ class TimeoutSettings {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
Double defaultTimeout() {
|
||||
return defaultTimeout;
|
||||
}
|
||||
Double defaultNavigationTimeout() {
|
||||
return defaultNavigationTimeout;
|
||||
}
|
||||
|
||||
void setDefaultTimeout(Double timeout) {
|
||||
void setDefaultTimeout(double timeout) {
|
||||
defaultTimeout = timeout;
|
||||
}
|
||||
|
||||
void setDefaultNavigationTimeout(Double timeout) {
|
||||
void setDefaultNavigationTimeout(double timeout) {
|
||||
defaultNavigationTimeout = timeout;
|
||||
}
|
||||
|
||||
@@ -80,4 +73,5 @@ class TimeoutSettings {
|
||||
}
|
||||
return new WaitableTimeout<>(timeout(timeout));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,8 +77,19 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
connection.localUtils.zip(path, new JsonArray(), stacksId, true, includeSources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(StartOptions options) {
|
||||
withLogging("Tracing.start", () -> startImpl(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startChunk(StartChunkOptions options) {
|
||||
withLogging("Tracing.startChunk", () -> {
|
||||
startChunkImpl(options);
|
||||
});
|
||||
}
|
||||
|
||||
private void startChunkImpl(StartChunkOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartChunkOptions();
|
||||
}
|
||||
@@ -105,8 +116,7 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
stacksId = connection.localUtils().tracingStarted(tracesDir == null ? null : tracesDir.toString(), traceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(StartOptions options) {
|
||||
private void startImpl(StartOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartOptions();
|
||||
}
|
||||
@@ -121,13 +131,17 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
|
||||
@Override
|
||||
public void stop(StopOptions options) {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
sendMessage("tracingStop");
|
||||
withLogging("Tracing.stop", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
sendMessage("tracingStop");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopChunk(StopChunkOptions options) {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
withLogging("Tracing.stopChunk", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
});
|
||||
}
|
||||
|
||||
void setTracesDir(Path tracesDir) {
|
||||
|
||||
@@ -90,11 +90,6 @@ class UrlMatcher {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
UrlMatcher that = (UrlMatcher) o;
|
||||
if (rawSource instanceof Pattern && that.rawSource instanceof Pattern) {
|
||||
Pattern a = (Pattern) rawSource;
|
||||
Pattern b = (Pattern) that.rawSource;
|
||||
return a.pattern().equals(b.pattern()) && a.flags() == b.flags();
|
||||
}
|
||||
return Objects.equals(rawSource, that.rawSource);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.ElementHandle;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.HttpHeader;
|
||||
import com.microsoft.playwright.options.SelectOption;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -30,7 +32,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -88,8 +89,7 @@ class Utils {
|
||||
}
|
||||
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('$', '^', '+', '.', '*', '(', ')', '|', '\\', '?', '{', '}', '[', ']'));
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('/', '$', '^', '+', '.', '(', ')', '=', '!', '|'));
|
||||
|
||||
static String globToRegex(String glob) {
|
||||
StringBuilder tokens = new StringBuilder();
|
||||
@@ -97,12 +97,8 @@ class Utils {
|
||||
boolean inGroup = false;
|
||||
for (int i = 0; i < glob.length(); ++i) {
|
||||
char c = glob.charAt(i);
|
||||
if (c == '\\' && i + 1 < glob.length()) {
|
||||
char nextChar = glob.charAt(++i);
|
||||
if (escapeGlobChars.contains(nextChar)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(nextChar);
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append("\\").append(c);
|
||||
continue;
|
||||
}
|
||||
if (c == '*') {
|
||||
@@ -127,12 +123,6 @@ class Utils {
|
||||
case '?':
|
||||
tokens.append('.');
|
||||
break;
|
||||
case '[':
|
||||
tokens.append('[');
|
||||
break;
|
||||
case ']':
|
||||
tokens.append(']');
|
||||
break;
|
||||
case '{':
|
||||
inGroup = true;
|
||||
tokens.append('(');
|
||||
@@ -149,11 +139,7 @@ class Utils {
|
||||
tokens.append("\\").append(c);
|
||||
break;
|
||||
default:
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokens.append('$');
|
||||
@@ -173,21 +159,27 @@ class Utils {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
static void addFilePathUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
|
||||
if (files.length == 0) {
|
||||
// FIXME: shouldBeAbleToResetSelectedFilesWithEmptyFileList tesst hangs in Chromium if we pass empty paths list.
|
||||
params.add("payloads", new JsonArray());
|
||||
} else if (context.connection.isRemote) {
|
||||
static final int maxUplodBufferSize = 50 * 1024 * 1024;
|
||||
|
||||
static boolean hasLargeFile(Path[] files) {
|
||||
for (Path file: files) {
|
||||
try {
|
||||
if (Files.size(file)> maxUplodBufferSize) {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot get file size.", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
|
||||
if (context.connection.isRemote) {
|
||||
List<WritableStream> streams = new ArrayList<>();
|
||||
JsonArray jsonStreams = new JsonArray();
|
||||
for (Path path : files) {
|
||||
long lastModifiedMs;
|
||||
try {
|
||||
lastModifiedMs = Files.getLastModifiedTime(path).toMillis();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot read file timestamp: " + path, e);
|
||||
}
|
||||
WritableStream temp = context.createTempFile(path.getFileName().toString(), lastModifiedMs);
|
||||
WritableStream temp = context.createTempFile(path.getFileName().toString());
|
||||
streams.add(temp);
|
||||
try (OutputStream out = temp.stream()) {
|
||||
Files.copy(path, out);
|
||||
@@ -210,12 +202,10 @@ class Utils {
|
||||
}
|
||||
|
||||
static void checkFilePayloadSize(FilePayload[] files) {
|
||||
long totalSize = 0;
|
||||
for (FilePayload file: files) {
|
||||
totalSize += file.buffer.length;
|
||||
}
|
||||
if (totalSize > 50 * 1024 * 1024) {
|
||||
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +252,7 @@ class Utils {
|
||||
static void writeToFile(InputStream inputStream, Path path) {
|
||||
mkParentDirs(path);
|
||||
try (FileOutputStream out = new FileOutputStream(path.toFile())) {
|
||||
byte[] buf = new byte[1024 * 1024];
|
||||
byte[] buf = new byte[8192];
|
||||
int length;
|
||||
while ((length = inputStream.read(buf)) > 0) {
|
||||
out.write(buf, 0, length);
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.WebError;
|
||||
|
||||
public class WebErrorImpl implements WebError {
|
||||
private final PageImpl page;
|
||||
private final String error;
|
||||
|
||||
WebErrorImpl(PageImpl page, String error) {
|
||||
this.page = page;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,6 @@ class WritableStream extends ChannelOwner {
|
||||
params.addProperty("binary", new String(encoded.array(), StandardCharsets.UTF_8));
|
||||
sendMessage("write", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
sendMessage("close");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,9 @@ package com.microsoft.playwright.options;
|
||||
public class HttpCredentials {
|
||||
public String username;
|
||||
public String password;
|
||||
/**
|
||||
* Restrain sending http credentials on specific origin (scheme://host:port).
|
||||
*/
|
||||
public String origin;
|
||||
|
||||
public HttpCredentials(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
/**
|
||||
* Restrain sending http credentials on specific origin (scheme://host:port).
|
||||
*/
|
||||
public HttpCredentials setOrigin(String origin) {
|
||||
this.origin = origin;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -52,8 +52,8 @@ public class Timing {
|
||||
*/
|
||||
public double requestStart;
|
||||
/**
|
||||
* Time immediately after the browser receives the first byte of the response from the server, cache, or local resource.
|
||||
* The value is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
* Time immediately after the browser starts requesting the resource from the server, cache, or local resource. The value
|
||||
* is given in milliseconds relative to {@code startTime}, -1 if not available.
|
||||
*/
|
||||
public double responseStart;
|
||||
/**
|
||||
|
||||
@@ -20,17 +20,10 @@ import org.junit.jupiter.api.*;
|
||||
|
||||
import com.microsoft.playwright.options.SameSiteAttribute;
|
||||
|
||||
import javax.sql.rowset.Predicate;
|
||||
import java.io.IOException;
|
||||
import java.security.Provider;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.microsoft.playwright.Utils.getBrowserNameFromEnv;
|
||||
import static com.microsoft.playwright.Utils.nextFreePort;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TestBase {
|
||||
@@ -157,13 +150,6 @@ public class TestBase {
|
||||
}
|
||||
}
|
||||
|
||||
void waitForCondition(BooleanSupplier predicate) {
|
||||
waitForCondition(predicate, 5_000);
|
||||
}
|
||||
void waitForCondition(BooleanSupplier predicate, int timeoutMs) {
|
||||
page.waitForCondition(predicate, new Page.WaitForConditionOptions().setTimeout(timeoutMs));
|
||||
}
|
||||
|
||||
private static SameSiteAttribute initSameSiteAttribute() {
|
||||
if (isChromium()) return SameSiteAttribute.LAX;
|
||||
if (isWebKit()) return SameSiteAttribute.NONE;
|
||||
|
||||
@@ -16,14 +16,10 @@
|
||||
|
||||
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.*;
|
||||
@@ -102,40 +98,4 @@ 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();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPropagateCloseReasonToPendingActions() {
|
||||
Browser browser = browserType.launch();
|
||||
BrowserContext context = browser.newContext();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> context.waitForPage(() -> {
|
||||
browser.close(new Browser.CloseOptions().setReason("The reason."));
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,14 +38,6 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
assertEquals("password=123456", page.evaluate("document.cookie"));
|
||||
}
|
||||
|
||||
// Slightly different rounding on chromium win.
|
||||
private static List<Cookie> normalizeExpires(List<Cookie> cookies) {
|
||||
for (Cookie cookie: cookies) {
|
||||
cookie.expires = (double) Math.round(cookie.expires);
|
||||
}
|
||||
return cookies;
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRoundtripCookie() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
@@ -61,7 +53,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
context.clearCookies();
|
||||
assertEquals(0, context.cookies().size());
|
||||
context.addCookies(cookies);
|
||||
assertJsonEquals(normalizeExpires(cookies), normalizeExpires(context.cookies()));
|
||||
assertJsonEquals(cookies, context.cookies());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -144,7 +144,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
context.waitForPage(() -> context.close());
|
||||
});
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Context closed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,16 +281,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
context.close();
|
||||
return false;
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Context closed"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPropagateCloseReasonToPendingActions() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.waitForPopup(() -> {
|
||||
context.close(new BrowserContext.CloseOptions().setReason("The reason."));
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.HttpCredentials;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
|
||||
@@ -75,66 +74,4 @@ public class TestBrowserContextCredentials extends TestBase {
|
||||
assertTrue(new String(response.body()).contains("Playground"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithCorrectCredentialsAndMatchingOrigin() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(server.PREFIX);
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setHttpCredentials(httpCredentials))) {
|
||||
Page page = context.newPage();
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(200, response.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithCorrectCredentialsAndMatchingOriginCaseInsensitive() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(server.PREFIX.toUpperCase());
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setHttpCredentials(httpCredentials))) {
|
||||
Page page = context.newPage();
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(200, response.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithCorrectCredentialsAndWrongOriginScheme() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginScheme(server));
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
Page page = context.newPage();
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithCorrectCredentialsAndWrongOriginHostname() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginHostname(server));
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
Page page = context.newPage();
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithCorrectCredentialsAndWrongOriginPort() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginPort(server));
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
Page page = context.newPage();
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestBrowserContextEvents extends TestBase {
|
||||
@Test
|
||||
void consoleEventShouldWorkSmoke() {
|
||||
ConsoleMessage message = context.waitForConsoleMessage(() -> {
|
||||
page.evaluate("console.log('hello')");
|
||||
});
|
||||
assertEquals("hello", message.text());
|
||||
assertEquals(page, message.page());
|
||||
}
|
||||
|
||||
@Test
|
||||
void consoleEventShouldWorkInPopup() {
|
||||
Page[] popup = { null };
|
||||
ConsoleMessage message = context.waitForConsoleMessage(() -> {
|
||||
popup[0] = page.waitForPopup(() -> {
|
||||
page.evaluate("const win = window.open('');\n" +
|
||||
"win.console.log('hello');\n");
|
||||
});
|
||||
});
|
||||
assertEquals("hello", message.text());
|
||||
assertEquals(popup[0], message.page());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="console message from javascript: url is not reported at all")
|
||||
void consoleEventShouldWorkInPopup2() {
|
||||
Page[] popup = { null };
|
||||
ConsoleMessage message = context.waitForConsoleMessage(
|
||||
new BrowserContext.WaitForConsoleMessageOptions().setPredicate(msg -> "log".equals(msg.type())),
|
||||
() -> {
|
||||
popup[0] = context.waitForPage(() -> {
|
||||
page.evaluate("async () => {\n" +
|
||||
" const win = window.open('javascript:console.log(\"hello\")');\n" +
|
||||
" await new Promise(f => setTimeout(f, 0));\n" +
|
||||
" win.close();\n" +
|
||||
"}");
|
||||
});
|
||||
});
|
||||
assertEquals("hello", message.text());
|
||||
assertEquals(popup[0], message.page());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="console message is not reported at all")
|
||||
void consoleEventShouldWorkInImmediatelyClosedPopup() {
|
||||
Page[] popup = { null };
|
||||
ConsoleMessage message = context.waitForConsoleMessage(() -> {
|
||||
popup[0] = page.waitForPopup(() -> {
|
||||
page.evaluate("async () => {\n" +
|
||||
" const win = window.open();\n" +
|
||||
" win.console.log('hello');\n" +
|
||||
" win.close();\n" +
|
||||
" }\n");
|
||||
});
|
||||
});
|
||||
assertEquals("hello", message.text());
|
||||
assertEquals(popup[0], message.page());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dialogEventShouldWorkSmoke() {
|
||||
Dialog[] dialog = { null };
|
||||
context.onDialog(d -> {
|
||||
dialog[0] = d;
|
||||
dialog[0].accept("hello");
|
||||
});
|
||||
Object result = page.evaluate("prompt('hey?')");
|
||||
assertEquals("hello", result);
|
||||
context.waitForCondition(() -> dialog[0] != null);
|
||||
assertEquals("hey?", dialog[0].message());
|
||||
assertEquals(page, dialog[0].page());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dialogEventShouldWorkInPopup() {
|
||||
Dialog[] dialog = { null };
|
||||
context.onDialog(d -> {
|
||||
dialog[0] = d;
|
||||
d.accept("hello");
|
||||
});
|
||||
Page popup = page.waitForPopup(() -> {
|
||||
Object result = page.evaluate("() => {\n" +
|
||||
" const win = window.open('');\n" +
|
||||
" return win.prompt('hey?');\n" +
|
||||
" }");
|
||||
assertEquals("hello", result);
|
||||
});
|
||||
assertEquals("hey?", dialog[0].message());
|
||||
assertEquals(popup, dialog[0].page());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="dialog from javascript: url is not reported at all")
|
||||
void dialogEventShouldWorkInPopup2() {
|
||||
Dialog[] dialog = { null };
|
||||
context.onDialog(d -> {
|
||||
dialog[0] = d;
|
||||
d.accept("hello");
|
||||
});
|
||||
page.evaluate("window.open('javascript:prompt(\"hey?\")');");
|
||||
context.waitForCondition(() -> dialog[0] != null);
|
||||
assertEquals("hey?", dialog[0].message());
|
||||
assertEquals(null, dialog[0].page());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dialogEventShouldWorkInImmdiatelyClosedPopup() {
|
||||
Dialog[] dialog = { null };
|
||||
context.onDialog(d -> {
|
||||
dialog[0] = d;
|
||||
d.accept("hello");
|
||||
});
|
||||
Page popup = page.waitForPopup(() -> {
|
||||
Object result = page.evaluate("async () => {\n" +
|
||||
" const win = window.open();\n" +
|
||||
" const result = win.prompt('hey?');\n" +
|
||||
" win.close();\n" +
|
||||
" return result;\n" +
|
||||
" }");
|
||||
assertEquals("hello", result);
|
||||
});
|
||||
assertEquals("hey?", dialog[0].message());
|
||||
assertEquals(popup, dialog[0].page());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dialogEventShouldWorkWithInlineScriptTag() {
|
||||
server.setRoute("/popup.html", exchange -> {
|
||||
exchange.getResponseHeaders().add("content-type", "text/html");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("<script>window.result = prompt('hey?')</script>");
|
||||
}
|
||||
});
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.setContent("<a href='popup.html' target=_blank>Click me</a>");
|
||||
Dialog[] dialog = { null };
|
||||
context.onDialog(d -> {
|
||||
dialog[0] = d;
|
||||
d.accept("hello");
|
||||
});
|
||||
Page popup = context.waitForPage(() -> page.click("a"));
|
||||
page.waitForCondition(() -> dialog[0] != null);
|
||||
assertEquals("hey?", dialog[0].message());
|
||||
assertEquals(popup, dialog[0].page());
|
||||
page.waitForCondition(() -> "hello".equals(popup.evaluate("window.result")),
|
||||
new Page.WaitForConditionOptions().setTimeout(5_000));
|
||||
}
|
||||
|
||||
@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,18 +511,14 @@ 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"), 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);
|
||||
assertTrue(body.contains("firstName=John"));
|
||||
assertTrue(body.contains("lastName=Doe"));
|
||||
assertTrue(body.contains("file=f.js"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -530,8 +526,6 @@ 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");
|
||||
@@ -672,72 +666,9 @@ public class TestBrowserContextFetch extends TestBase {
|
||||
});
|
||||
page.evaluate("() => setTimeout(closeContext, 1000);");
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> context.request().get(server.EMPTY_PAGE));
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Request context disposed"), e.getMessage());
|
||||
|
||||
e = assertThrows(PlaywrightException.class, () -> context.request().post(server.EMPTY_PAGE));
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithSetHTTPCredentialsAndMatchingOrigin() throws ExecutionException, InterruptedException {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
APIResponse response1 = context.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response1.status());
|
||||
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(server.PREFIX);
|
||||
try (BrowserContext context2 = browser.newContext(
|
||||
new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
APIResponse response2 = context2.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(200, response2.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithSetHTTPCredentialsAndMatchingOriginCaseInsensitive() throws ExecutionException, InterruptedException {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
APIResponse response1 = context.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response1.status());
|
||||
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(server.PREFIX.toUpperCase());
|
||||
try (BrowserContext context2 = browser.newContext(
|
||||
new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
APIResponse response2 = context2.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(200, response2.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnErrorWithCorrectCredentialsAndWrongOriginScheme() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginScheme(server));
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
APIResponse response = context.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnErrorWithCorrectCredentialsAndWrongOriginHostname() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginHostname(server));
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
APIResponse response = context.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnErrorWithCorrectCredentialsAndWrongOriginPort() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginPort(server));
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setHttpCredentials(httpCredentials))) {
|
||||
APIResponse response = context.request().get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,33 +175,17 @@ public class TestBrowserContextProxy extends TestBase {
|
||||
// @see https://gist.github.com/CollinChaffin/24f6c9652efb3d6d5ef2f5502720ef00
|
||||
.setBypass("1.non.existent.domain.for.the.test, 2.non.existent.domain.for.the.test, .another.test")));
|
||||
|
||||
{
|
||||
Page page = context.newPage();
|
||||
page.navigate("http://0.non.existent.domain.for.the.test/target.html");
|
||||
assertEquals("Served by the proxy", page.title());
|
||||
page.close();
|
||||
}
|
||||
{
|
||||
Page page = context.newPage();
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate("http://1.non.existent.domain.for.the.test/target.html"));
|
||||
page.close();
|
||||
}
|
||||
{
|
||||
Page page = context.newPage();
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate("http://2.non.existent.domain.for.the.test/target.html"));
|
||||
page.close();
|
||||
}
|
||||
{
|
||||
Page page = context.newPage();
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate("http://foo.is.the.another.test/target.html"));
|
||||
page.close();
|
||||
}
|
||||
{
|
||||
Page page = context.newPage();
|
||||
page.navigate("http://3.non.existent.domain.for.the.test/target.html");
|
||||
assertEquals("Served by the proxy", page.title());
|
||||
page.close();
|
||||
}
|
||||
Page page = context.newPage();
|
||||
page.navigate("http://0.non.existent.domain.for.the.test/target.html");
|
||||
assertEquals("Served by the proxy", page.title());
|
||||
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate("http://1.non.existent.domain.for.the.test/target.html"));
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate("http://2.non.existent.domain.for.the.test/target.html"));
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate("http://foo.is.the.another.test/target.html"));
|
||||
|
||||
page.navigate("http://3.non.existent.domain.for.the.test/target.html");
|
||||
assertEquals("Served by the proxy", page.title());
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -40,8 +39,6 @@ import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBrowserTypeConnect extends TestBase {
|
||||
static Path FILE_TO_UPLOAD = Paths.get("src/test/resources/file-to-upload.txt");
|
||||
|
||||
private Process browserServer;
|
||||
private String wsEndpoint;
|
||||
|
||||
@@ -352,7 +349,7 @@ public class TestBrowserTypeConnect extends TestBase {
|
||||
}
|
||||
browser.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void shouldSaveAsVideosFromRemoteBrowser(@TempDir Path tempDir) {
|
||||
Path videosPath = tempDir.resolve("videosPath");
|
||||
@@ -504,17 +501,4 @@ public class TestBrowserTypeConnect extends TestBase {
|
||||
assertEquals("200MB.zip", fields.get(0).filename);
|
||||
assertEquals(200 * 1024 * 1024, fields.get(0).content.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setInputFilesDhouldPreserveLastModifiedTimestamp() throws IOException {
|
||||
page.setContent("<input type=file multiple=true/>");
|
||||
Locator input = page.locator("input");
|
||||
input.setInputFiles(FILE_TO_UPLOAD);
|
||||
assertEquals(asList("file-to-upload.txt"), input.evaluate("e => [...e.files].map(f => f.name)"));
|
||||
List<Double> timestamps = (List<Double>) input.evaluate("e => [...e.files].map(f => f.lastModified)");
|
||||
FileTime expected = Files.getLastModifiedTime(FILE_TO_UPLOAD);
|
||||
// On Linux browser sometimes reduces the timestamp by 1ms: 1696272058110.0715 -> 1696272058109 or even
|
||||
// rounds it to seconds in WebKit: 1696272058110 -> 1696272058000.
|
||||
assertTrue(Math.abs(timestamps.get(0) - expected.toMillis()) < 1000, "expected: " + expected.toMillis() + "; actual: " + timestamps.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
import com.microsoft.playwright.options.WaitUntilState;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.microsoft.playwright.options.KeyboardModifier.SHIFT;
|
||||
import static com.microsoft.playwright.options.MouseButton.RIGHT;
|
||||
@@ -405,12 +408,6 @@ public class TestClick extends TestBase {
|
||||
assertEquals(isWebKit() ? 1910 + 8 : 1910, page.evaluate("offsetY"));
|
||||
}
|
||||
|
||||
private static void expectCloseTo(double expected, double actual) {
|
||||
if (Math.abs(expected - actual) > 2)
|
||||
fail("Expected: " + expected + ", received: " + actual);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="skip")
|
||||
void shouldClickTheButtonWithOffsetWithPageScale() {
|
||||
@@ -425,10 +422,20 @@ public class TestClick extends TestBase {
|
||||
"}");
|
||||
page.click("button", new Page.ClickOptions().setPosition(20, 10));
|
||||
assertEquals("Clicked", page.evaluate("result"));
|
||||
// Expect 20;10 + 8px of border in each direction. Allow some delta as different
|
||||
// browsers round up or down differently during css -> dip -> css conversion.
|
||||
expectCloseTo(28, (Integer) page.evaluate("pageX"));
|
||||
expectCloseTo(18, (Integer) page.evaluate("pageY"));
|
||||
// 20;10 + 8px of border in each direction
|
||||
int expectedX = 28;
|
||||
int expectedY = 18;
|
||||
if (isWebKit()) {
|
||||
// WebKit rounds up during css -> dip -> css conversion.
|
||||
expectedX = 26;
|
||||
expectedY = 17;
|
||||
} else if (isChromium() && !headful) {
|
||||
// Headless Chromium rounds down during css -> dip -> css conversion.
|
||||
expectedX = 27;
|
||||
expectedY = 18;
|
||||
}
|
||||
assertEquals(expectedX, Math.round((Integer) page.evaluate("pageX") + 0.01));
|
||||
assertEquals(expectedY, Math.round((Integer) page.evaluate("pageY") + 0.01));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestElementHandleConvenience extends TestBase {
|
||||
@@ -37,17 +35,6 @@ public class TestElementHandleConvenience extends TestBase {
|
||||
assertEquals("JSHandle@<input checked id=\"check\" foo=\"bar\"\" type=\"checkbox\"/>", check.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveANicePreviewForNonAsciiAttributesChildren() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
String text = String.join("", Collections.nCopies(100, "😛"));
|
||||
page.setContent("<div title='" + text + "'>" + text + "</div>");
|
||||
ElementHandle handle = page.querySelector("div");
|
||||
context.waitForCondition(() -> "JSHandle@<div title=\"😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…>😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…</div>"
|
||||
.equals(handle.toString()), new BrowserContext.WaitForConditionOptions().setTimeout(5_000));
|
||||
assertEquals("JSHandle@<div title=\"😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…>😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛😛…</div>", handle.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAttributeShouldWork() {
|
||||
page.navigate(server.PREFIX + "/dom.html");
|
||||
|
||||
@@ -122,7 +122,7 @@ public class TestEvalOnSelector extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
page.evalOnSelector("section", "e => e.id");
|
||||
});
|
||||
assertTrue(e.getMessage().contains("Failed to find element matching selector \"section\""), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("failed to find element matching selector \"section\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,14 +19,10 @@ package com.microsoft.playwright;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static com.microsoft.playwright.Utils.mapOf;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@EnabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="skip")
|
||||
public class TestFirefoxLauncher extends TestBase {
|
||||
|
||||
@Override
|
||||
@@ -41,6 +37,7 @@ public class TestFirefoxLauncher extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledIf(value="com.microsoft.playwright.TestBase#isFirefox", disabledReason="skip")
|
||||
void shouldPassFirefoxUserPreferences() {
|
||||
BrowserType.LaunchOptions options = new BrowserType.LaunchOptions().setFirefoxUserPrefs(
|
||||
mapOf(
|
||||
@@ -52,19 +49,4 @@ public class TestFirefoxLauncher extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.navigate("http://example.com"));
|
||||
assertTrue(e.getMessage().contains("NS_ERROR_PROXY_CONNECTION_REFUSED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPassFirefoxUserPreferencesInPersistent(@TempDir Path tmpDir) {
|
||||
BrowserType.LaunchPersistentContextOptions options = new BrowserType.LaunchPersistentContextOptions().setFirefoxUserPrefs(
|
||||
mapOf(
|
||||
"network.proxy.type", 1,
|
||||
"network.proxy.http", "127.0.0.1",
|
||||
"network.proxy.http_port", 3333));
|
||||
initBrowserType();
|
||||
context = browserType.launchPersistentContext(tmpDir.resolve("user-data-dir"), options);
|
||||
assertNotNull(context);
|
||||
Page page = context.pages().get(0);
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.navigate("http://example.com"));
|
||||
assertTrue(e.getMessage().contains("NS_ERROR_PROXY_CONNECTION_REFUSED"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.microsoft.playwright.options.HttpCredentials;
|
||||
import com.microsoft.playwright.options.HttpHeader;
|
||||
import com.microsoft.playwright.options.RequestOptions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@@ -412,66 +411,4 @@ public class TestGlobalFetch extends TestBase {
|
||||
request.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportGlobalHttpCredentialsOptionAndMatchingOrigin() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
APIRequestContext request1 = playwright.request().newContext();
|
||||
APIResponse response1 = request1.get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response1.status());
|
||||
request1.dispose();
|
||||
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(server.PREFIX);
|
||||
APIRequestContext request2 = playwright.request().newContext(new APIRequest.NewContextOptions().setHttpCredentials(httpCredentials));
|
||||
APIResponse response2 = request2.get(server.EMPTY_PAGE);
|
||||
assertEquals(200, response2.status());
|
||||
request2.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportGlobalHttpCredentialsOptionAndMatchingOriginCaseInsensitive() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
APIRequestContext request1 = playwright.request().newContext();
|
||||
APIResponse response1 = request1.get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response1.status());
|
||||
request1.dispose();
|
||||
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(server.PREFIX.toUpperCase());
|
||||
APIRequestContext request2 = playwright.request().newContext(new APIRequest.NewContextOptions().setHttpCredentials(httpCredentials));
|
||||
APIResponse response2 = request2.get(server.EMPTY_PAGE);
|
||||
assertEquals(200, response2.status());
|
||||
request2.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnErrorWithCorrectCredentialsAndWrongOriginScheme() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginScheme(server));
|
||||
APIRequestContext request = playwright.request().newContext(new APIRequest.NewContextOptions().setHttpCredentials(httpCredentials));
|
||||
APIResponse response = request.get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnErrorWithCorrectCredentialsAndWrongOriginHostname() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginHostname(server));
|
||||
APIRequestContext request = playwright.request().newContext(new APIRequest.NewContextOptions().setHttpCredentials(httpCredentials));
|
||||
APIResponse response = request.get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnErrorWithCorrectCredentialsAndWrongOriginPort() {
|
||||
server.setAuth("/empty.html", "user", "pass");
|
||||
final HttpCredentials httpCredentials = new HttpCredentials("user", "pass");
|
||||
httpCredentials.setOrigin(Utils.generateDifferentOriginPort(server));
|
||||
APIRequestContext request = playwright.request().newContext(new APIRequest.NewContextOptions().setHttpCredentials(httpCredentials));
|
||||
APIResponse response = request.get(server.EMPTY_PAGE);
|
||||
assertEquals(401, response.status());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -246,14 +246,6 @@ public class TestLocatorAssertions extends TestBase {
|
||||
assertTrue(e.getMessage().contains("Locator expected to have text"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasAttributeTextIgnoreCase() {
|
||||
page.setContent("<div id=NoDe>Text content</div>");
|
||||
Locator locator = page.locator("#NoDe");
|
||||
assertThat(locator).hasAttribute("id", "node", new LocatorAssertions.HasAttributeOptions().setIgnoreCase(true));
|
||||
assertThat(locator).not().hasAttribute("id", "node");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasAttributeTextPass() {
|
||||
page.setContent("<div id=node>Text content</div>");
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.assertions.LocatorAssertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.AssertionFailedError;
|
||||
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestLocatorAssertions2 extends TestBase {
|
||||
@Test
|
||||
void isAttachedDefault() {
|
||||
page.setContent("<input></input>");
|
||||
Locator locator = page.locator("input");
|
||||
assertThat(locator).isAttached();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithHiddenElement() {
|
||||
page.setContent("<button style='display:none'>hello</button>");
|
||||
Locator locator = page.locator("button");
|
||||
assertThat(locator).isAttached();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithNot() {
|
||||
page.setContent("<button>hello</button>");
|
||||
Locator locator = page.locator("input");
|
||||
assertThat(locator).not().isAttached();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithAttachedTrue() {
|
||||
page.setContent("<button>hello</button>");
|
||||
Locator locator = page.locator("button");
|
||||
assertThat(locator).isAttached(new LocatorAssertions.IsAttachedOptions().setAttached(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithAttachedFalse() {
|
||||
page.setContent("<button>hello</button>");
|
||||
Locator locator = page.locator("input");
|
||||
assertThat(locator).isAttached(new LocatorAssertions.IsAttachedOptions().setAttached(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithNotAndAttachedFalse() {
|
||||
page.setContent("<button>hello</button>");
|
||||
Locator locator = page.locator("button");
|
||||
assertThat(locator).not().isAttached(new LocatorAssertions.IsAttachedOptions().setAttached(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedEventually() {
|
||||
page.setContent("<div></div>");
|
||||
Locator locator = page.locator("span");
|
||||
page.evalOnSelector("div", "div => setTimeout(() => {\n" +
|
||||
" div.innerHTML = '<span>Hello</span>'\n" +
|
||||
" }, 100)");
|
||||
assertThat(locator).isAttached();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedEventuallyWithNot() {
|
||||
page.setContent("<div><span>Hello</span></div>");
|
||||
Locator locator = page.locator("span");
|
||||
page.evalOnSelector("div", "div => setTimeout(() => {\n" +
|
||||
" div.textContent = '';\n" +
|
||||
" }, 0)");
|
||||
assertThat(locator).not().isAttached();
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedFail() {
|
||||
page.setContent("<button>Hello</button>");
|
||||
Locator locator = page.locator("input");
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(locator).isAttached(new LocatorAssertions.IsAttachedOptions().setTimeout(1000)));
|
||||
assertFalse(error.getMessage().contains("locator resolved to"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedFailWithNot() {
|
||||
page.setContent("<input></input>");
|
||||
Locator locator = page.locator("input");
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(locator).not().isAttached(new LocatorAssertions.IsAttachedOptions().setTimeout(1000)));
|
||||
assertTrue(error.getMessage().contains("locator resolved to <input/>"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithImpossibleTimeout() {
|
||||
page.setContent("<div id=node>Text content</div>");
|
||||
assertThat(page.locator("#node")).isAttached(new LocatorAssertions.IsAttachedOptions().setTimeout(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAttachedWithImpossibleTimeoutNot() {
|
||||
page.setContent("<div id=node>Text content</div>");
|
||||
assertThat(page.locator("no-such-thing")).not().isAttached(new LocatorAssertions.IsAttachedOptions().setTimeout(1));
|
||||
}
|
||||
}
|
||||
@@ -116,11 +116,4 @@ public class TestLocatorMisc extends TestBase{
|
||||
assertEquals("outer", divLocator.locator("input").inputValue());
|
||||
assertEquals("inner", page.frameLocator("iframe").locator(divLocator).locator("input").inputValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPressSequentially() {
|
||||
page.setContent("<input type='text' />");
|
||||
page.locator("input").pressSequentially("hello");
|
||||
assertEquals("hello", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,12 +112,12 @@ public class TestPageBasic extends TestBase {
|
||||
PlaywrightException e2 = assertThrows(PlaywrightException.class, () -> {
|
||||
newPage.waitForRequest(server.EMPTY_PAGE, () -> newPage.close());
|
||||
});
|
||||
assertTrue(e2.getMessage().contains("Target page, context or browser has been closed"), e2.getMessage());
|
||||
assertFalse(e2.getMessage().contains("Timeout"), e2.getMessage());
|
||||
assertTrue(e2.getMessage().contains("Page closed"));
|
||||
assertFalse(e2.getMessage().contains("Timeout"));
|
||||
});
|
||||
});
|
||||
assertTrue(e1.getMessage().contains("Target page, context or browser has been closed"), e1.getMessage());
|
||||
assertFalse(e1.getMessage().contains("Timeout"), e1.getMessage());
|
||||
assertTrue(e1.getMessage().contains("Page closed"));
|
||||
assertFalse(e1.getMessage().contains("Timeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,15 +336,6 @@ public class TestPageBasic extends TestBase {
|
||||
page.close();
|
||||
return false;
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPropagateCloseReasonToPendingActions() {
|
||||
Page page = context.newPage();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.waitForPopup(() -> {
|
||||
page.close(new Page.CloseOptions().setReason("The reason."));
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Page closed"), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ 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;
|
||||
@@ -116,12 +115,6 @@ 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.
|
||||
@@ -391,7 +384,7 @@ public class TestPageEvaluate extends TestBase {
|
||||
assertNotNull(element);
|
||||
element.dispose();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.evaluate("e => e.textContent", element));
|
||||
assertTrue(e.getMessage().contains("no object with guid"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("JSHandle is disposed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -645,14 +638,4 @@ public class TestPageEvaluate extends TestBase {
|
||||
assertTrue(object instanceof Date);
|
||||
assertEquals(Date.from(instant), object);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTransferMaps() {
|
||||
assertEquals(mapOf(), page.evaluate("() => new Map([[1, { test: 42n }]])"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTransferSets() {
|
||||
assertEquals(mapOf(), page.evaluate("() => new Set([1, { test: 42n }])"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,18 +66,17 @@ public class TestPageEventNetwork extends TestBase {
|
||||
assertTrue(failedRequests.get(0).url().contains("one-style.css"));
|
||||
assertNull(failedRequests.get(0).response());
|
||||
assertEquals("stylesheet", failedRequests.get(0).resourceType());
|
||||
String error = failedRequests.get(0).failure();
|
||||
if (isChromium()) {
|
||||
assertEquals("net::ERR_EMPTY_RESPONSE", error);
|
||||
assertEquals("net::ERR_EMPTY_RESPONSE", failedRequests.get(0).failure());
|
||||
} else if (isWebKit()) {
|
||||
if (isMac)
|
||||
assertEquals("The network connection was lost.", error);
|
||||
assertEquals("The network connection was lost.", failedRequests.get(0).failure());
|
||||
else if (isWindows)
|
||||
assertEquals("Server returned nothing (no headers, no data)", error);
|
||||
assertEquals("Server returned nothing (no headers, no data)", failedRequests.get(0).failure());
|
||||
else
|
||||
assertTrue("Message Corrupt".equals(error) || "Connection terminated unexpectedly".equals(error), error);
|
||||
assertEquals("Message Corrupt", failedRequests.get(0).failure());
|
||||
} else {
|
||||
assertEquals("NS_ERROR_NET_RESET", error);
|
||||
assertEquals("NS_ERROR_NET_RESET", failedRequests.get(0).failure());
|
||||
}
|
||||
assertNotNull(failedRequests.get(0).frame());
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestPageEventPopup extends TestBase {
|
||||
@Test
|
||||
void shouldWorkWithClickingTarget_blank() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.setContent("<a target=_blank rel='opener' href='/one-style.html'>yo</a>");
|
||||
Page popup = page.waitForPopup(() -> page.click("a"));
|
||||
assertEquals(false, page.evaluate("() => !!window.opener"));
|
||||
assertEquals(true, popup.evaluate("() => !!window.opener"));
|
||||
assertEquals(popup, popup.mainFrame().page());
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -73,23 +71,6 @@ public class TestPageInterception extends TestBase {
|
||||
assertTrue(response.headers().get("content-type").contains("text/html"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportTimeoutOptionInRouteFetch() {
|
||||
server.setRoute("/slow", exchange -> {
|
||||
exchange.getResponseHeaders().set("Content-type", "text/plain");
|
||||
exchange.sendResponseHeaders(200, 4096);
|
||||
});
|
||||
|
||||
page.route("**/*", route -> {
|
||||
PlaywrightException error = assertThrows(PlaywrightException.class,
|
||||
() -> route.fetch(new Route.FetchOptions().setTimeout(1000)));
|
||||
assertTrue(error.getMessage().contains("Request timed out after 1000ms"), error.getMessage());
|
||||
});
|
||||
PlaywrightException error = assertThrows(PlaywrightException.class,
|
||||
() -> page.navigate(server.PREFIX + "/slow", new Page.NavigateOptions().setTimeout(2000)));
|
||||
assertTrue(error.getMessage().contains("Timeout 2000ms exceeded"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInterceptWithUrlOverride() {
|
||||
page.route("**/*.html", route -> {
|
||||
@@ -124,15 +105,4 @@ 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,7 +379,11 @@ public class TestPageKeyboard extends TestBase {
|
||||
} else {
|
||||
assertEquals("Meta", eventData.get("key"));
|
||||
}
|
||||
assertEquals("MetaLeft", eventData.get("code"));
|
||||
if (isFirefox()) {
|
||||
assertEquals("OSLeft", eventData.get("code"));
|
||||
} else {
|
||||
assertEquals("MetaLeft", eventData.get("code"));
|
||||
}
|
||||
if (isFirefox() && !isMac) {
|
||||
assertFalse((Boolean) eventData.get("metaKey"), eventData.toString());
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -107,39 +106,6 @@ public class TestPageLocatorQuery extends TestBase {
|
||||
assertEquals("Hello \"world\"", page.locator("div", new Page.LocatorOptions().setHasText(Pattern.compile("Hello \"world\""))).textContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFilterByRegexWithASingleQuote() {
|
||||
page.setContent("<button>let's let's<span>hello</span></button>");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let['abc]s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let['abc]s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let's let\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let's let\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\'s let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\'s let's", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
|
||||
page.setContent("<button>let\\'s let\\'s<span>hello</span></button>");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\'s", Pattern.CASE_INSENSITIVE)))).not().isVisible();
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\'s let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\'s let\\\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.locator("button", new Page.LocatorOptions().setHasText(Pattern.compile("let\\\\\\'s let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("let\\\\\\'s let\\\\'s", Pattern.CASE_INSENSITIVE))).locator("span")).hasText("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFilterByRegexAndRegexpFlags() {
|
||||
page.setContent("<div>Hello \"world\"</div><div>Hello world</div>");
|
||||
@@ -206,56 +172,5 @@ public class TestPageLocatorQuery extends TestBase {
|
||||
assertThat(page.locator("div").filter(new Locator.FilterOptions()
|
||||
.setHas(page.locator("span"))
|
||||
.setHasText("world"))).hasCount(1);
|
||||
assertThat(page.locator("div").filter(new Locator.FilterOptions()
|
||||
.setHasNot(page.locator("span", new Page.LocatorOptions().setHasText("world"))))).hasCount(1);
|
||||
assertThat(page.locator("div").filter(new Locator.FilterOptions()
|
||||
.setHasNot(page.locator("section")))).hasCount(2);
|
||||
assertThat(page.locator("div").filter(new Locator.FilterOptions()
|
||||
.setHasNot(page.locator("span")))).hasCount(0);
|
||||
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHasNotText("hello"))).hasCount(1);
|
||||
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHasNotText("foo"))).hasCount(2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void shouldSupportLocatorAnd() {
|
||||
page.setContent("<div data-testid=foo>hello</div><div data-testid=bar>world</div>\n" +
|
||||
" <span data-testid=foo>hello2</span><span data-testid=bar>world2</span>");
|
||||
assertThat(page.locator("div").and(page.locator("div"))).hasCount(2);
|
||||
assertThat(page.locator("div").and(page.getByTestId("foo"))).hasText(new String[] { "hello" });
|
||||
assertThat(page.locator("div").and(page.getByTestId("bar"))).hasText(new String[] { "world" });
|
||||
assertThat(page.getByTestId("foo").and(page.locator("div"))).hasText(new String[] { "hello" });
|
||||
assertThat(page.getByTestId("bar").and(page.locator("span"))).hasText(new String[] { "world2" });
|
||||
assertThat(page.locator("span").and(page.getByTestId(Pattern.compile("bar|foo")))).hasCount(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportLocatorOr() {
|
||||
page.setContent("<div>hello</div><span>world</span>");
|
||||
assertThat(page.locator("div").or(page.locator("span"))).hasCount(2);
|
||||
assertThat(page.locator("div").or(page.locator("span"))).hasText(new String[]{"hello", "world"});
|
||||
assertThat(page.locator("span").or(page.locator("article")).or(page.locator("div"))).hasText(new String[]{"hello", "world"});
|
||||
assertThat(page.locator("article").or(page.locator("someting"))).hasCount(0);
|
||||
assertThat(page.locator("article").or(page.locator("div"))).hasText("hello");
|
||||
assertThat(page.locator("article").or(page.locator("span"))).hasText("world");
|
||||
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,8 +21,6 @@ import com.microsoft.playwright.options.HttpHeader;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -115,34 +113,4 @@ public class TestPageNetworkRequest extends TestBase {
|
||||
assertEquals("POST", request.method());
|
||||
assertEquals(403, request.response().status());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotAllowToAccessFrameOnPopupMainRequest() {
|
||||
page.setContent("<a target=_blank href='" + server.EMPTY_PAGE + "'>click me</a>");
|
||||
Request[] request = { null };
|
||||
PlaywrightException[] error = { null };
|
||||
page.context().onRequest(req -> {
|
||||
request[0] = req;
|
||||
try {
|
||||
req.frame();
|
||||
} catch (PlaywrightException e) {
|
||||
error[0] = e;
|
||||
}
|
||||
});
|
||||
page.getByText("click me").click();
|
||||
waitForCondition(() -> request[0] != null);
|
||||
assertTrue(request[0].isNavigationRequest());
|
||||
assertTrue(error[0].getMessage().contains("Frame for this navigation request is not available"), error[0].getMessage());
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
|
||||
public class TestPageRequestIntercept extends TestBase {
|
||||
@Test
|
||||
void shouldFulfillPopupMainRequestUsingAlias() {
|
||||
page.context().route("**/*", route -> {
|
||||
APIResponse response = route.fetch();
|
||||
route.fulfill(new Route.FulfillOptions().setResponse(response).setBody("hello" ));
|
||||
});
|
||||
page.setContent("<a target=_blank href='" + server.EMPTY_PAGE + "'>click me</a>");
|
||||
Page popup = page.waitForPopup(() -> page.getByText("click me").click());
|
||||
assertThat(popup.locator("body")).hasText("hello");
|
||||
}
|
||||
}
|
||||
@@ -82,12 +82,12 @@ public class TestPageRoute extends TestBase {
|
||||
intercepted.add(4);
|
||||
route.fallback();
|
||||
};
|
||||
page.route(Pattern.compile("empty.html"), handler4);
|
||||
page.route("**/empty.html", handler4);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(asList(4, 3, 2, 1), intercepted);
|
||||
|
||||
intercepted.clear();
|
||||
page.unroute(Pattern.compile("empty.html"), handler4);
|
||||
page.unroute("**/empty.html", handler4);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(asList(3, 2, 1), intercepted);
|
||||
|
||||
@@ -97,42 +97,6 @@ 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<>();
|
||||
@@ -389,7 +353,7 @@ public class TestPageRoute extends TestBase {
|
||||
Request r = intercepted.get(1);
|
||||
for (String url : asList("/one-style.css", "/two-style.css", "/three-style.css", "/four-style.css")) {
|
||||
assertEquals("stylesheet", r.resourceType());
|
||||
assertTrue(r.url().contains(url), "actual: " + r.url() + "; expected: " + url);
|
||||
assertTrue(r.url().contains(url));
|
||||
r = r.redirectedTo();
|
||||
}
|
||||
assertNull(r);
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.Arrays;
|
||||
import static com.microsoft.playwright.options.ScreenshotAnimations.DISABLED;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
// TODO: suite.skip(browserName === "firefox" && headful");
|
||||
public class TestPageScreenshot extends TestBase {
|
||||
@@ -234,19 +233,4 @@ public class TestPageScreenshot extends TestBase {
|
||||
}
|
||||
assertTrue(hasDifferentScreenshots);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWhenMaskColorIsNotPinkF0F() {
|
||||
page.setViewportSize(500, 500);
|
||||
page.navigate(server.PREFIX + "/grid.html");
|
||||
byte[] screenshot1 = page.screenshot(
|
||||
new Page.ScreenshotOptions()
|
||||
.setMask(asList(page.locator("div").nth(5)))
|
||||
.setMaskColor("#00FF00"));
|
||||
byte[] screenshot2 = page.screenshot(
|
||||
new Page.ScreenshotOptions()
|
||||
.setMask(asList(page.locator("div").nth(5))));
|
||||
assertThrows(AssertionError.class, () -> assertArrayEquals(screenshot1, screenshot2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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("Value cannot be null"));
|
||||
assertTrue(e.getMessage().contains("expected string, got undefined"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,15 @@
|
||||
|
||||
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;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
@@ -36,10 +33,8 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.microsoft.playwright.Utils.relativePathOrSkipTest;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -101,34 +96,6 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
assertEquals(200 * 1024 * 1024, fields.get(0).content.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUploadMultipleLargeFiles(@TempDir Path tmpDir) throws IOException, ExecutionException, InterruptedException {
|
||||
Assumptions.assumeTrue(3 <= (Runtime.getRuntime().maxMemory() >> 30), "Fails if max heap size is < 3Gb");
|
||||
int filesCount = 10;
|
||||
page.navigate(server.PREFIX + "/input/fileupload-multi.html");
|
||||
Path uploadFile = tmpDir.resolve("50MB_1.zip");
|
||||
String str = String.join("", Collections.nCopies(1024, "A"));
|
||||
|
||||
try (Writer stream = new OutputStreamWriter(Files.newOutputStream(uploadFile))) {
|
||||
for (int i = 0; i < 49 * 1024; i++) {
|
||||
stream.write(str);
|
||||
}
|
||||
}
|
||||
Locator input = page.locator("input[type='file']");
|
||||
List<Path> uploadFiles = new ArrayList<>();
|
||||
uploadFiles.add(uploadFile);
|
||||
for (int i = 1; i < filesCount; i++) {
|
||||
Path dstFile = tmpDir.resolve("50MB_" + i + ".zip");
|
||||
Files.copy(uploadFile, dstFile);
|
||||
uploadFiles.add(dstFile);
|
||||
}
|
||||
FileChooser fileChooser = page.waitForFileChooser(() -> input.click());
|
||||
fileChooser.setFiles(uploadFiles.toArray(new Path[0]));
|
||||
Object filesLen = page.getByRole(AriaRole.TEXTBOX).evaluate("e => e.files.length");
|
||||
assertTrue(fileChooser.isMultiple());
|
||||
assertEquals(filesCount, filesLen);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUploadLargeFileWithRelativePath(@TempDir Path tmpDir) throws IOException, ExecutionException, InterruptedException {
|
||||
Assumptions.assumeTrue(3 <= (Runtime.getRuntime().maxMemory() >> 30), "Fails if max heap size is < 3Gb");
|
||||
@@ -149,7 +116,8 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
" return events;\n" +
|
||||
" }");
|
||||
|
||||
Path relativeUploadPath = relativePathOrSkipTest(uploadFile);
|
||||
Path cwd = Paths.get("").toAbsolutePath();
|
||||
Path relativeUploadPath = cwd.relativize(uploadFile);
|
||||
assertFalse(relativeUploadPath.isAbsolute());
|
||||
input.setInputFiles(relativeUploadPath);
|
||||
assertEquals("200MB.zip", input.evaluate("e => e.files[0].name"));
|
||||
@@ -405,18 +373,5 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
FileChooser fileChooser = page.waitForFileChooser(() -> page.click("input"));
|
||||
assertTrue(fileChooser.isMultiple());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPreserveLastModifiedTimestamp() throws IOException {
|
||||
page.setContent("<input type=file multiple=true/>");
|
||||
Locator input = page.locator("input");
|
||||
input.setInputFiles(FILE_TO_UPLOAD);
|
||||
assertEquals(asList("file-to-upload.txt"), input.evaluate("e => [...e.files].map(f => f.name)"));
|
||||
List<Double> timestamps = (List<Double>) input.evaluate("e => [...e.files].map(f => f.lastModified)");
|
||||
FileTime expected = Files.getLastModifiedTime(FILE_TO_UPLOAD);
|
||||
// On Linux browser sometimes reduces the timestamp by 1ms: 1696272058110.0715 -> 1696272058109 or even
|
||||
// rounds it to seconds in WebKit: 1696272058110 -> 1696272058000.
|
||||
assertTrue(Math.abs(timestamps.get(0) - expected.toMillis()) < 1000, "expected: " + expected.toMillis() + "; actual: " + timestamps.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,18 +52,6 @@ public class TestPdf extends TestBase {
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
|
||||
void shouldThrowInNonChromium() {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
|
||||
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
|
||||
void correctExceptionWithPersistentContext(@TempDir Path tempDir) {
|
||||
Path profile = tempDir.resolve("profile");
|
||||
try (BrowserContext context = browserType.launchPersistentContext(profile)) {
|
||||
Page page = context.newPage();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
|
||||
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
|
||||
}
|
||||
assertTrue(e.getMessage().contains("Page.pdf only supported in headless Chromium"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,25 +153,6 @@ public class TestSelectorsGetBy extends TestBase {
|
||||
assertThat(page.getByTitle("my title", new Page.GetByTitleOptions().setExact(true))).hasCount(1, new LocatorAssertions.HasCountOptions().setTimeout(500));
|
||||
assertThat(page.getByTitle("my t\\itle", new Page.GetByTitleOptions().setExact(true))).hasCount(0, new LocatorAssertions.HasCountOptions().setTimeout(500));
|
||||
assertThat(page.getByTitle("my t\\\\itle", new Page.GetByTitleOptions().setExact(true))).hasCount(0, new LocatorAssertions.HasCountOptions().setTimeout(500));
|
||||
|
||||
page.setContent("<label for=target>foo >> 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
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestSelectorsMisc extends TestBase {
|
||||
@@ -195,48 +194,4 @@ public class TestSelectorsMisc extends TestBase {
|
||||
e = assertThrows(PlaywrightException.class, () -> page.querySelector("div >> left-of='span',3,4"));
|
||||
assertTrue(e.getMessage().contains("Malformed selector: left-of='span',3,4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithInternalHasNot() {
|
||||
page.setContent("<section><span></span><div></div></section><section><br></section>");
|
||||
assertEquals(1, page.evalOnSelectorAll("section >> internal:has-not=\"span\"", "els => els.length"));
|
||||
assertEquals(0, page.evalOnSelectorAll("section >> internal:has-not=\"span, div, br\"", "els => els.length"));
|
||||
assertEquals(1, page.evalOnSelectorAll("section >> internal:has-not=\"br\"", "els => els.length"));
|
||||
assertEquals(1, page.evalOnSelectorAll("section >> internal:has-not=\"span, div\"", "els => els.length"));
|
||||
assertEquals(2, page.evalOnSelectorAll("section >> internal:has-not=\"article\"", "els => els.length"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithInternalAnd() {
|
||||
page.setContent("<div class=foo>hello</div><div class=bar>world</div>\n" +
|
||||
" <span class=foo>hello2</span><span class=bar>world2</span>");
|
||||
assertEquals(asList(), page.evalOnSelectorAll("div >> internal:and=\"span\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("hello"), page.evalOnSelectorAll("div >> internal:and=\".foo\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("world"), page.evalOnSelectorAll("div >> internal:and=\".bar\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("hello2", "world2"), page.evalOnSelectorAll("span >> internal:and=\"span\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("hello"), page.evalOnSelectorAll(".foo >> internal:and=\"div\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("world2"), page.evalOnSelectorAll(".bar >> internal:and=\"span\"", "els => els.map(e => e.textContent)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithInternalOr() {
|
||||
page.setContent("<div>hello</div>\n" +
|
||||
" <span>world</span>");
|
||||
assertEquals(asList("hello", "world"), page.evalOnSelectorAll("div >> internal:or=\"span\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(asList("hello", "world"), page.evalOnSelectorAll("span >> internal:or=\"div\"", "els => els.map(e => e.textContent)"));
|
||||
assertEquals(0, page.evalOnSelectorAll("article >> internal:or=\"something\"", "els => els.length"));
|
||||
assertEquals("hello", page.locator("article >> internal:or=\"div\"").textContent());
|
||||
assertEquals("world", page.locator("article >> internal:or=\"span\"").textContent());
|
||||
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,18 +9,6 @@ import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestSelectorsText extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldWorkSmoke() {
|
||||
page.setContent("<div>Hi>><span></span></div>");
|
||||
assertEquals("<span></span>", page.evalOnSelector("text=\"Hi>>\">>span", "e => e.outerHTML"));
|
||||
assertEquals("<span></span>", page.evalOnSelector("text=/Hi\\>\\>/ >> span", "e => e.outerHTML"));
|
||||
|
||||
page.setContent("<div>let's<span>hello</span></div>");
|
||||
assertEquals("<span>hello</span>", page.evalOnSelector("text=/let's/i >> span", "e => e.outerHTML"));
|
||||
assertEquals("<span>hello</span>", page.evalOnSelector("text=/let\'s/i >> span", "e => e.outerHTML"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTextAndInternalTextShouldMatchFullNodeTextInStrictMode() {
|
||||
page.setContent("<div id=div1>hello<span>world</span></div>\n" +
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static com.microsoft.playwright.Utils.relativePathOrSkipTest;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestVideo extends TestBase {
|
||||
@Test
|
||||
void shouldWorkWithRelativePathForRecordVideoDir(@TempDir Path tmpDir) {
|
||||
Path relativeDir = relativePathOrSkipTest(tmpDir);
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setRecordVideoSize(320, 240).setRecordVideoDir(relativeDir));
|
||||
Page page = context.newPage();
|
||||
Path videoPath = page.video().path();
|
||||
context.close();
|
||||
assertTrue(videoPath.isAbsolute(), "videosPath = " + videoPath);
|
||||
assertTrue(Files.exists(videoPath), "videosPath = " + videoPath);
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class TestWebSocket extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
ws.waitForFrameSent(() -> page.evaluate("window.ws.close()"));
|
||||
});
|
||||
assertTrue(e.getMessage().matches("Socket closed|Socket error"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Socket closed"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,7 +199,7 @@ public class TestWebSocket extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
ws.waitForFrameSent(() -> page.close());
|
||||
});
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Page closed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user