Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96cc9e6e62 |
@@ -1,8 +1,5 @@
|
||||
trigger:
|
||||
none
|
||||
|
||||
# don't trigger for Pull Requests
|
||||
pr: none
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-22.04
|
||||
@@ -46,17 +43,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'
|
||||
|
||||
@@ -7,34 +7,19 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- ⚠️⚠️ Do not delete this template ⚠️⚠️ -->
|
||||
**Context:**
|
||||
- Playwright Version: [what Playwright version do you use?]
|
||||
- Operating System: [e.g. Windows, Linux or Mac]
|
||||
- Browser: [e.g. All, Chromium, Firefox, WebKit]
|
||||
- Extra: [any specific details about your environment]
|
||||
|
||||
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
|
||||
<!-- 🧪 Test using the latest Playwright release to see if your issue has already been fixed -->
|
||||
<!-- 💡 Provide enough information for us to be able to reproduce your issue locally -->
|
||||
<!-- CLI to auto-capture this info -->
|
||||
<!-- npx envinfo --preset playwright --markdown -->
|
||||
|
||||
### System info
|
||||
- Playwright Version: [v1.XX]
|
||||
- Operating System: [All, Windows 11, Ubuntu 20, macOS 13.2, etc.]
|
||||
- Browser: [All, Chromium, Firefox, WebKit]
|
||||
- Other info:
|
||||
**Code Snippet**
|
||||
|
||||
### Source code
|
||||
|
||||
- [ ] I provided exact source code that allows reproducing the issue locally.
|
||||
|
||||
<!-- For simple cases, please provide a self-contained test file along with the config file -->
|
||||
<!-- For larger cases, you can provide a GitHub repo you created for this issue -->
|
||||
<!-- If we can not reproduce the problem locally, we won't be able to act on it -->
|
||||
<!-- You can still file without the exact code and we will try to help, but if we can't repro, it will be closed -->
|
||||
|
||||
**Link to the GitHub repository with the repro**
|
||||
|
||||
[https://github.com/your_profile/playwright_issue_title]
|
||||
|
||||
or
|
||||
|
||||
**Test file (self-contained)**
|
||||
Help us help you! Put down a short code snippet that illustrates your bug and
|
||||
that we can run and debug locally. For example:
|
||||
|
||||
```java
|
||||
import com.microsoft.playwright.*;
|
||||
@@ -51,14 +36,6 @@ public class ExampleReproducible {
|
||||
}
|
||||
```
|
||||
|
||||
**Steps**
|
||||
- [Run the test]
|
||||
- [...]
|
||||
**Describe the bug**
|
||||
|
||||
**Expected**
|
||||
|
||||
[Describe expected behavior]
|
||||
|
||||
**Actual**
|
||||
|
||||
[Describe actual behavior]
|
||||
Add any other details about the problem here.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
contact_links:
|
||||
- name: Join our Discord Server
|
||||
url: https://aka.ms/playwright/discord
|
||||
about: Ask questions and discuss with other community members
|
||||
- name: Join our Slack community
|
||||
url: https://aka.ms/playwright-slack
|
||||
about: Ask questions and discuss with other community members
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: I have a question
|
||||
about: Feel free to ask us your questions!
|
||||
title: "[Question]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ jobs:
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Run tests
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
|
||||
run: mvn test --no-transfer-progress --fail-at-end
|
||||
env:
|
||||
BROWSER: ${{ matrix.browser }}
|
||||
- name: Run tracing tests w/ sources
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D test=*TestTracing* -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D test=*TestTracing*
|
||||
env:
|
||||
BROWSER: ${{ matrix.browser }}
|
||||
PLAYWRIGHT_JAVA_SRC: src/test/java
|
||||
@@ -79,7 +79,7 @@ jobs:
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Run tests
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
|
||||
run: mvn test --no-transfer-progress --fail-at-end
|
||||
env:
|
||||
BROWSER: chromium
|
||||
BROWSER_CHANNEL: ${{ matrix.browser-channel }}
|
||||
|
||||
@@ -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 -->121.0.6167.57<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->121.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->109.0.5414.46<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->107.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
|
||||
```
|
||||
|
||||
|
||||
+20
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.41.2</version>
|
||||
<version>1.29.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
@@ -16,6 +16,25 @@
|
||||
It is intended to be used on the systems where Playwright driver is not preinstalled.
|
||||
</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludeResources>true</excludeResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+17
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.41.2</version>
|
||||
<version>1.29.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver</artifactId>
|
||||
@@ -15,6 +15,22 @@
|
||||
This module provides API for discovery and launching of Playwright driver.
|
||||
</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>1.41.2</version>
|
||||
<version>1.29.0</version>
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -15,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>1.30.0</version>
|
||||
<version>1.22.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
@@ -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")));
|
||||
}
|
||||
}
|
||||
|
||||
+14
-2
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.41.2</version>
|
||||
<version>1.29.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>playwright</artifactId>
|
||||
@@ -21,14 +21,26 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration combine.self="append">
|
||||
<configuration>
|
||||
<subpackages>com.microsoft.playwright</subpackages>
|
||||
<excludePackageNames>com.microsoft.playwright.impl</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</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;
|
||||
/**
|
||||
@@ -250,12 +227,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public Optional<ViewportSize> viewportSize;
|
||||
|
||||
@@ -271,7 +244,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 +259,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 +275,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 +305,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 +332,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 +348,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 +363,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 +380,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 +513,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 +522,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;
|
||||
@@ -573,23 +536,15 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public NewContextOptions setViewportSize(int width, int height) {
|
||||
return setViewportSize(new ViewportSize(width, height));
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public NewContextOptions setViewportSize(ViewportSize viewportSize) {
|
||||
this.viewportSize = Optional.ofNullable(viewportSize);
|
||||
@@ -606,7 +561,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 +573,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 +583,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 +598,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 +610,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 +708,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;
|
||||
/**
|
||||
@@ -776,12 +722,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public Optional<ViewportSize> viewportSize;
|
||||
|
||||
@@ -797,7 +739,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 +754,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 +770,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 +800,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 +827,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 +843,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 +858,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 +875,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 +1008,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 +1017,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;
|
||||
@@ -1099,23 +1031,15 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public NewPageOptions setViewportSize(int width, int height) {
|
||||
return setViewportSize(new ViewportSize(width, height));
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public NewPageOptions setViewportSize(ViewportSize viewportSize) {
|
||||
this.viewportSize = Optional.ofNullable(viewportSize);
|
||||
@@ -1179,25 +1103,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 +1124,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.
|
||||
*
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -58,51 +57,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 +81,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 +130,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
|
||||
@@ -259,17 +189,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* written to disk when {@link BrowserContext#close BrowserContext.close()} is called.
|
||||
*/
|
||||
public Boolean update;
|
||||
/**
|
||||
* Optional setting to control resource content management. If {@code attach} is specified, resources are persisted as
|
||||
* separate files or entries in the ZIP archive. If {@code embed} is specified, content is stored inline the HAR file.
|
||||
*/
|
||||
public RouteFromHarUpdateContentPolicy updateContent;
|
||||
/**
|
||||
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
|
||||
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
|
||||
* minimal}.
|
||||
*/
|
||||
public HarMode updateMode;
|
||||
/**
|
||||
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
|
||||
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
|
||||
@@ -296,23 +215,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
this.update = update;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Optional setting to control resource content management. If {@code attach} is specified, resources are persisted as
|
||||
* separate files or entries in the ZIP archive. If {@code embed} is specified, content is stored inline the HAR file.
|
||||
*/
|
||||
public RouteFromHAROptions setUpdateContent(RouteFromHarUpdateContentPolicy updateContent) {
|
||||
this.updateContent = updateContent;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
|
||||
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
|
||||
* minimal}.
|
||||
*/
|
||||
public RouteFromHAROptions setUpdateMode(HarMode updateMode) {
|
||||
this.updateMode = updateMode;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
|
||||
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
|
||||
@@ -346,51 +248,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class WaitForConditionOptions {
|
||||
/**
|
||||
* 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()} or
|
||||
* {@link Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* 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()} or
|
||||
* {@link Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public WaitForConditionOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
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 +284,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 +372,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 +630,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 +974,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 +989,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
|
||||
@@ -1260,13 +1084,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.12
|
||||
*/
|
||||
Tracing tracing();
|
||||
/**
|
||||
* Removes all routes created with {@link BrowserContext#route BrowserContext.route()} and {@link
|
||||
* BrowserContext#routeFromHAR BrowserContext.routeFromHAR()}.
|
||||
*
|
||||
* @since v1.41
|
||||
*/
|
||||
void unrouteAll();
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
@@ -1330,76 +1147,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
void unroute(Predicate<String> url, Consumer<Route> handler);
|
||||
/**
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Use the method to wait for a condition that depends on page events:
|
||||
* <pre>{@code
|
||||
* List<String> failedUrls = new ArrayList<>();
|
||||
* context.onResponse(response -> {
|
||||
* if (!response.ok()) {
|
||||
* failedUrls.add(response.url());
|
||||
* }
|
||||
* });
|
||||
* page1.getByText("Create user").click();
|
||||
* page2.getByText("Submit button").click();
|
||||
* context.waitForCondition(() -> failedUrls.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Condition 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.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Use the method to wait for a condition that depends on page events:
|
||||
* <pre>{@code
|
||||
* List<String> failedUrls = new ArrayList<>();
|
||||
* context.onResponse(response -> {
|
||||
* if (!response.ok()) {
|
||||
* failedUrls.add(response.url());
|
||||
* }
|
||||
* });
|
||||
* page1.getByText("Create user").click();
|
||||
* page2.getByText("Submit button").click();
|
||||
* context.waitForCondition(() -> failedUrls.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Condition to wait for.
|
||||
* @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.
|
||||
*/
|
||||
@@ -165,10 +122,8 @@ public interface BrowserType {
|
||||
}
|
||||
class LaunchOptions {
|
||||
/**
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
@@ -255,10 +210,8 @@ public interface BrowserType {
|
||||
public Path tracesDir;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public LaunchOptions setArgs(List<String> args) {
|
||||
this.args = args;
|
||||
@@ -420,10 +373,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
@@ -431,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>
|
||||
@@ -443,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;
|
||||
/**
|
||||
@@ -463,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;
|
||||
/**
|
||||
@@ -489,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.
|
||||
@@ -517,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;
|
||||
/**
|
||||
@@ -529,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;
|
||||
/**
|
||||
@@ -548,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;
|
||||
/**
|
||||
@@ -640,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;
|
||||
/**
|
||||
@@ -652,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;
|
||||
/**
|
||||
@@ -664,12 +601,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public Optional<ViewportSize> viewportSize;
|
||||
|
||||
@@ -681,10 +614,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setArgs(List<String> args) {
|
||||
this.args = args;
|
||||
@@ -695,7 +626,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>
|
||||
@@ -710,7 +641,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;
|
||||
@@ -752,8 +683,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;
|
||||
@@ -793,20 +723,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.
|
||||
@@ -845,8 +767,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;
|
||||
@@ -863,15 +784,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;
|
||||
@@ -901,17 +820,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;
|
||||
@@ -919,17 +836,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;
|
||||
@@ -937,7 +851,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;
|
||||
@@ -1069,8 +983,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;
|
||||
@@ -1087,7 +1000,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;
|
||||
@@ -1108,23 +1021,15 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setViewportSize(int width, int height) {
|
||||
return setViewportSize(new ViewportSize(width, height));
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. {@code null} disables the default
|
||||
* viewport.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setViewportSize(ViewportSize viewportSize) {
|
||||
this.viewportSize = Optional.ofNullable(viewportSize);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -22,16 +22,16 @@ import java.util.*;
|
||||
* {@code ConsoleMessage} objects are dispatched by page via the {@link Page#onConsoleMessage Page.onConsoleMessage()}
|
||||
* event. For each console messages logged in the page there will be corresponding event in the Playwright context.
|
||||
* <pre>{@code
|
||||
* // Listen for all console messages and print them to the standard output.
|
||||
* // Listen for all System.out.printlns
|
||||
* page.onConsoleMessage(msg -> System.out.println(msg.text()));
|
||||
*
|
||||
* // Listen for all console messages and print errors to the standard output.
|
||||
* // Listen for all console events and handle errors
|
||||
* page.onConsoleMessage(msg -> {
|
||||
* if ("error".equals(msg.type()))
|
||||
* System.out.println("Error text: " + msg.text());
|
||||
* });
|
||||
*
|
||||
* // Get the next console message
|
||||
* // Get the next System.out.println
|
||||
* ConsoleMessage msg = page.waitForConsoleMessage(() -> {
|
||||
* // Issue console.log inside the page
|
||||
* page.evaluate("console.log('hello', 42, { foo: 'bar' });");
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -75,8 +75,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -120,8 +120,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 CheckOptions setTimeout(double timeout) {
|
||||
@@ -173,8 +173,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -247,8 +247,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 ClickOptions setTimeout(double timeout) {
|
||||
@@ -296,8 +296,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -363,8 +363,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 DblclickOptions setTimeout(double timeout) {
|
||||
@@ -394,8 +394,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -418,8 +418,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 FillOptions setTimeout(double timeout) {
|
||||
@@ -450,8 +450,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -503,8 +503,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 HoverOptions setTimeout(double timeout) {
|
||||
@@ -523,15 +523,15 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
class InputValueOptions {
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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 InputValueOptions setTimeout(double timeout) {
|
||||
@@ -551,8 +551,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -574,8 +574,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 PressOptions setTimeout(double timeout) {
|
||||
@@ -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}.
|
||||
@@ -635,14 +629,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public ScreenshotScale scale;
|
||||
/**
|
||||
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
|
||||
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
|
||||
* and applies to the inner frames.
|
||||
*/
|
||||
public String style;
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -675,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}.
|
||||
@@ -726,17 +705,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
|
||||
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
|
||||
* and applies to the inner frames.
|
||||
*/
|
||||
public ScreenshotOptions setStyle(String style) {
|
||||
this.style = style;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds, defaults to 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 ScreenshotOptions setTimeout(double timeout) {
|
||||
@@ -753,15 +723,15 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
class ScrollIntoViewIfNeededOptions {
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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 ScrollIntoViewIfNeededOptions setTimeout(double timeout) {
|
||||
@@ -782,8 +752,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -806,8 +776,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 SelectOptionOptions setTimeout(double timeout) {
|
||||
@@ -822,8 +792,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean force;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -837,8 +807,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 SelectTextOptions setTimeout(double timeout) {
|
||||
@@ -864,8 +834,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -909,8 +879,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 SetCheckedOptions setTimeout(double timeout) {
|
||||
@@ -935,8 +905,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -951,8 +921,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 SetInputFilesOptions setTimeout(double timeout) {
|
||||
@@ -983,8 +953,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -1036,8 +1006,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 TapOptions setTimeout(double timeout) {
|
||||
@@ -1066,8 +1036,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -1089,8 +1059,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 TypeOptions setTimeout(double timeout) {
|
||||
@@ -1116,8 +1086,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -1161,8 +1131,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 UncheckOptions setTimeout(double timeout) {
|
||||
@@ -1181,15 +1151,15 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
class WaitForElementStateOptions {
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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 WaitForElementStateOptions setTimeout(double timeout) {
|
||||
@@ -1216,8 +1186,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean strict;
|
||||
/**
|
||||
* 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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -1246,8 +1216,8 @@ public interface ElementHandle extends JSHandle {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 WaitForSelectorOptions setTimeout(double timeout) {
|
||||
@@ -1426,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:
|
||||
@@ -1470,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:
|
||||
@@ -1605,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
|
||||
@@ -1623,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
|
||||
@@ -1901,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"));
|
||||
@@ -1932,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"));
|
||||
@@ -1961,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"));
|
||||
@@ -1992,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"));
|
||||
@@ -2021,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"));
|
||||
@@ -2052,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"));
|
||||
@@ -2081,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"));
|
||||
@@ -2112,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"));
|
||||
@@ -2141,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"));
|
||||
@@ -2172,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"));
|
||||
@@ -2201,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"));
|
||||
@@ -2232,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"));
|
||||
@@ -2473,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
|
||||
@@ -2484,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
|
||||
@@ -2546,7 +2538,8 @@ public interface ElementHandle extends JSHandle {
|
||||
* <li> {@code "visible"} Wait until the element is <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.</li>
|
||||
* <li> {@code "hidden"} Wait until the element is <a href="https://playwright.dev/java/docs/actionability#visible">not
|
||||
* visible</a> or not attached. Note that waiting for hidden does not throw when the element detaches.</li>
|
||||
* visible</a> or <a href="https://playwright.dev/java/docs/actionability#attached">not attached</a>. Note that waiting for
|
||||
* hidden does not throw when the element detaches.</li>
|
||||
* <li> {@code "stable"} Wait until the element is both <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#stable">stable</a>.</li>
|
||||
@@ -2576,7 +2569,8 @@ public interface ElementHandle extends JSHandle {
|
||||
* <li> {@code "visible"} Wait until the element is <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.</li>
|
||||
* <li> {@code "hidden"} Wait until the element is <a href="https://playwright.dev/java/docs/actionability#visible">not
|
||||
* visible</a> or not attached. Note that waiting for hidden does not throw when the element detaches.</li>
|
||||
* visible</a> or <a href="https://playwright.dev/java/docs/actionability#attached">not attached</a>. Note that waiting for
|
||||
* hidden does not throw when the element detaches.</li>
|
||||
* <li> {@code "stable"} Wait until the element is both <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#stable">stable</a>.</li>
|
||||
|
||||
@@ -35,8 +35,8 @@ public interface FileChooser {
|
||||
*/
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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;
|
||||
@@ -51,8 +51,8 @@ public interface FileChooser {
|
||||
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
|
||||
* Maximum time in milliseconds, defaults to 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 SetFilesOptions setTimeout(double timeout) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -285,31 +285,12 @@ public interface FrameLocator {
|
||||
}
|
||||
class LocatorOptions {
|
||||
/**
|
||||
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
|
||||
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
|
||||
* document root. For example, you can find {@code content} that has {@code div} in {@code
|
||||
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
|
||||
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
|
||||
* content}.
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
|
||||
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
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
|
||||
@@ -318,14 +299,8 @@ public interface FrameLocator {
|
||||
public Object hasText;
|
||||
|
||||
/**
|
||||
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
|
||||
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
|
||||
* document root. For example, you can find {@code content} that has {@code div} in {@code
|
||||
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
|
||||
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
|
||||
* content}.
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
|
||||
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
@@ -333,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
|
||||
@@ -394,14 +342,7 @@ public interface FrameLocator {
|
||||
*/
|
||||
FrameLocator frameLocator(String selector);
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
* page.getByAltText("Playwright logo").click();
|
||||
* }</pre>
|
||||
* Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -410,28 +351,14 @@ public interface FrameLocator {
|
||||
return getByAltText(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
* page.getByAltText("Playwright logo").click();
|
||||
* }</pre>
|
||||
* Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByAltText(String text, GetByAltTextOptions options);
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
* page.getByAltText("Playwright logo").click();
|
||||
* }</pre>
|
||||
* Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -440,30 +367,15 @@ public interface FrameLocator {
|
||||
return getByAltText(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
* page.getByAltText("Playwright logo").click();
|
||||
* }</pre>
|
||||
* Allows locating elements by their alt text. For example, this method will find the image by alt text "Castle":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByAltText(Pattern text, GetByAltTextOptions options);
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
||||
* label text "Password" in the following DOM:
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -472,32 +384,16 @@ public interface FrameLocator {
|
||||
return getByLabel(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
||||
* label text "Password" in the following DOM:
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByLabel(String text, GetByLabelOptions options);
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
||||
* label text "Password" in the following DOM:
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -506,32 +402,16 @@ public interface FrameLocator {
|
||||
return getByLabel(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the text of the associated label. For example, this method will find the input by
|
||||
* label text "Password" in the following DOM:
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByLabel(Pattern text, GetByLabelOptions options);
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
* <p> You can fill the input after locating it by the placeholder text:
|
||||
* <pre>{@code
|
||||
* page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
||||
* "Country":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -540,32 +420,16 @@ public interface FrameLocator {
|
||||
return getByPlaceholder(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
* <p> You can fill the input after locating it by the placeholder text:
|
||||
* <pre>{@code
|
||||
* page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
||||
* "Country":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByPlaceholder(String text, GetByPlaceholderOptions options);
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
* <p> You can fill the input after locating it by the placeholder text:
|
||||
* <pre>{@code
|
||||
* page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
||||
* "Country":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -574,16 +438,8 @@ public interface FrameLocator {
|
||||
return getByPlaceholder(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
* <p> You can fill the input after locating it by the placeholder text:
|
||||
* <pre>{@code
|
||||
* page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");
|
||||
* }</pre>
|
||||
* Allows locating input elements by the placeholder text. For example, this method will find the input by placeholder
|
||||
* "Country":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -592,39 +448,14 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their <a href="https://www.w3.org/TR/wai-aria-1.2/#roles">ARIA role</a>, <a
|
||||
* href="https://www.w3.org/TR/wai-aria-1.2/#aria-attributes">ARIA attributes</a> and <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>.
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>. Note that role selector **does not
|
||||
* replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
* new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .isVisible();
|
||||
*
|
||||
* page.getByRole(AriaRole.CHECKBOX,
|
||||
* new Page.GetByRoleOptions().setName("Subscribe"))
|
||||
* .check();
|
||||
*
|
||||
* page.getByRole(AriaRole.BUTTON,
|
||||
* new Page.GetByRoleOptions().setName(
|
||||
* Pattern.compile("submit", Pattern.CASE_INSENSITIVE)))
|
||||
* .click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the
|
||||
* ARIA guidelines.
|
||||
*
|
||||
* <p> Many html elements have an implicitly <a href="https://w3c.github.io/html-aam/#html-element-role-mappings">defined
|
||||
* role</a> that is recognized by the role selector. You can find all the <a
|
||||
* href="https://www.w3.org/TR/wai-aria-1.2/#role_definitions">supported roles here</a>. ARIA guidelines **do not
|
||||
* recommend** duplicating implicit roles and attributes by setting {@code role} and/or {@code aria-*} attributes to
|
||||
* default values.
|
||||
* <p> Note that many html elements have an implicitly <a
|
||||
* href="https://w3c.github.io/html-aam/#html-element-role-mappings">defined role</a> that is recognized by the role
|
||||
* selector. You can find all the <a href="https://www.w3.org/TR/wai-aria-1.2/#role_definitions">supported roles here</a>.
|
||||
* ARIA guidelines **do not recommend** duplicating implicit roles and attributes by setting {@code role} and/or {@code
|
||||
* aria-*} attributes to default values.
|
||||
*
|
||||
* @param role Required aria role.
|
||||
* @since v1.27
|
||||
@@ -635,95 +466,37 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their <a href="https://www.w3.org/TR/wai-aria-1.2/#roles">ARIA role</a>, <a
|
||||
* href="https://www.w3.org/TR/wai-aria-1.2/#aria-attributes">ARIA attributes</a> and <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>.
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>. Note that role selector **does not
|
||||
* replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
* new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .isVisible();
|
||||
*
|
||||
* page.getByRole(AriaRole.CHECKBOX,
|
||||
* new Page.GetByRoleOptions().setName("Subscribe"))
|
||||
* .check();
|
||||
*
|
||||
* page.getByRole(AriaRole.BUTTON,
|
||||
* new Page.GetByRoleOptions().setName(
|
||||
* Pattern.compile("submit", Pattern.CASE_INSENSITIVE)))
|
||||
* .click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the
|
||||
* ARIA guidelines.
|
||||
*
|
||||
* <p> Many html elements have an implicitly <a href="https://w3c.github.io/html-aam/#html-element-role-mappings">defined
|
||||
* role</a> that is recognized by the role selector. You can find all the <a
|
||||
* href="https://www.w3.org/TR/wai-aria-1.2/#role_definitions">supported roles here</a>. ARIA guidelines **do not
|
||||
* recommend** duplicating implicit roles and attributes by setting {@code role} and/or {@code aria-*} attributes to
|
||||
* default values.
|
||||
* <p> Note that many html elements have an implicitly <a
|
||||
* href="https://w3c.github.io/html-aam/#html-element-role-mappings">defined role</a> that is recognized by the role
|
||||
* selector. You can find all the <a href="https://www.w3.org/TR/wai-aria-1.2/#role_definitions">supported roles here</a>.
|
||||
* ARIA guidelines **do not recommend** duplicating implicit roles and attributes by setting {@code role} and/or {@code
|
||||
* aria-*} attributes to default values.
|
||||
*
|
||||
* @param role Required aria role.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByRole(AriaRole role, GetByRoleOptions options);
|
||||
/**
|
||||
* Locate element by the test id.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> By default, the {@code data-testid} attribute is used as a test id. Use {@link Selectors#setTestIdAttribute
|
||||
* Selectors.setTestIdAttribute()} to configure a different test id attribute if necessary.
|
||||
* Locate element by the test id. By default, the {@code data-testid} attribute is used as a test id. Use {@link
|
||||
* Selectors#setTestIdAttribute Selectors.setTestIdAttribute()} to configure a different test id attribute if necessary.
|
||||
*
|
||||
* @param testId Id to locate the element by.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByTestId(String testId);
|
||||
/**
|
||||
* Locate element by the test id.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> By default, the {@code data-testid} attribute is used as a test id. Use {@link Selectors#setTestIdAttribute
|
||||
* Selectors.setTestIdAttribute()} to configure a different test id attribute if necessary.
|
||||
* Locate element by the test id. By default, the {@code data-testid} attribute is used as a test id. Use {@link
|
||||
* Selectors#setTestIdAttribute Selectors.setTestIdAttribute()} to configure a different test id attribute if necessary.
|
||||
*
|
||||
* @param testId Id to locate the element by.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByTestId(Pattern testId);
|
||||
/**
|
||||
* Allows locating elements that contain given text.
|
||||
*
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
* Allows locating elements that contain given text. Consider the following DOM structure:
|
||||
*
|
||||
* <p> You can locate by text substring, exact string, or a regular expression:
|
||||
* <pre>{@code
|
||||
@@ -743,12 +516,13 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* <p> <strong>NOTE:</strong> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* turns line breaks into spaces and ignores leading and trailing whitespace.
|
||||
*
|
||||
* <p> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* <p> <strong>NOTE:</strong> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* content. For example, locating by text {@code "Log in"} matches {@code <input type=button value="Log in">}.
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
@@ -758,14 +532,7 @@ public interface FrameLocator {
|
||||
return getByText(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating elements that contain given text.
|
||||
*
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
* Allows locating elements that contain given text. Consider the following DOM structure:
|
||||
*
|
||||
* <p> You can locate by text substring, exact string, or a regular expression:
|
||||
* <pre>{@code
|
||||
@@ -785,12 +552,13 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* <p> <strong>NOTE:</strong> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* turns line breaks into spaces and ignores leading and trailing whitespace.
|
||||
*
|
||||
* <p> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* <p> <strong>NOTE:</strong> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* content. For example, locating by text {@code "Log in"} matches {@code <input type=button value="Log in">}.
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
@@ -798,14 +566,7 @@ public interface FrameLocator {
|
||||
*/
|
||||
Locator getByText(String text, GetByTextOptions options);
|
||||
/**
|
||||
* Allows locating elements that contain given text.
|
||||
*
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
* Allows locating elements that contain given text. Consider the following DOM structure:
|
||||
*
|
||||
* <p> You can locate by text substring, exact string, or a regular expression:
|
||||
* <pre>{@code
|
||||
@@ -825,12 +586,13 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* <p> <strong>NOTE:</strong> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* turns line breaks into spaces and ignores leading and trailing whitespace.
|
||||
*
|
||||
* <p> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* <p> <strong>NOTE:</strong> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* content. For example, locating by text {@code "Log in"} matches {@code <input type=button value="Log in">}.
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
@@ -840,14 +602,7 @@ public interface FrameLocator {
|
||||
return getByText(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating elements that contain given text.
|
||||
*
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
* Allows locating elements that contain given text. Consider the following DOM structure:
|
||||
*
|
||||
* <p> You can locate by text substring, exact string, or a regular expression:
|
||||
* <pre>{@code
|
||||
@@ -867,12 +622,13 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> See also {@link Locator#filter Locator.filter()} that allows to match by another criteria, like an accessible role, and
|
||||
* then filter by the text content.
|
||||
*
|
||||
* <p> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* <p> <strong>NOTE:</strong> Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one,
|
||||
* turns line breaks into spaces and ignores leading and trailing whitespace.
|
||||
*
|
||||
* <p> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* <p> <strong>NOTE:</strong> Input elements of the type {@code button} and {@code submit} are matched by their {@code value} instead of the text
|
||||
* content. For example, locating by text {@code "Log in"} matches {@code <input type=button value="Log in">}.
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
@@ -880,16 +636,7 @@ public interface FrameLocator {
|
||||
*/
|
||||
Locator getByText(Pattern text, GetByTextOptions options);
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can check the issues count after locating it by the title text:
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByTitle("Issues count")).hasText("25 issues");
|
||||
* }</pre>
|
||||
* Allows locating elements by their title. For example, this method will find the button by its title "Place the order":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -898,32 +645,14 @@ public interface FrameLocator {
|
||||
return getByTitle(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can check the issues count after locating it by the title text:
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByTitle("Issues count")).hasText("25 issues");
|
||||
* }</pre>
|
||||
* Allows locating elements by their title. For example, this method will find the button by its title "Place the order":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByTitle(String text, GetByTitleOptions options);
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can check the issues count after locating it by the title text:
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByTitle("Issues count")).hasText("25 issues");
|
||||
* }</pre>
|
||||
* Allows locating elements by their title. For example, this method will find the button by its title "Place the order":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -932,16 +661,7 @@ public interface FrameLocator {
|
||||
return getByTitle(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can check the issues count after locating it by the title text:
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByTitle("Issues count")).hasText("25 issues");
|
||||
* }</pre>
|
||||
* Allows locating elements by their title. For example, this method will find the button by its title "Place the order":
|
||||
*
|
||||
* @param text Text to locate the element for.
|
||||
* @since v1.27
|
||||
@@ -959,11 +679,11 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
default Locator locator(String selectorOrLocator) {
|
||||
return locator(selectorOrLocator, null);
|
||||
default Locator locator(String selector) {
|
||||
return locator(selector, null);
|
||||
}
|
||||
/**
|
||||
* The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
||||
@@ -971,32 +691,10 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
Locator locator(String selectorOrLocator, LocatorOptions options);
|
||||
/**
|
||||
* The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
||||
* similar to {@link Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
default Locator locator(Locator selectorOrLocator) {
|
||||
return locator(selectorOrLocator, null);
|
||||
}
|
||||
/**
|
||||
* The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
||||
* similar to {@link Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
Locator locator(Locator selectorOrLocator, LocatorOptions options);
|
||||
Locator locator(String selector, LocatorOptions options);
|
||||
/**
|
||||
* Returns locator to the n-th matching frame. It's zero based, {@code nth(0)} selects the first frame.
|
||||
*
|
||||
|
||||
@@ -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()}.
|
||||
*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -97,7 +97,7 @@ public interface Playwright extends AutoCloseable {
|
||||
* Launches new Playwright driver process and connects to it. {@link Playwright#close Playwright.close()} should be called
|
||||
* when the instance is no longer needed.
|
||||
* <pre>{@code
|
||||
* Playwright playwright = Playwright.create();
|
||||
* Playwright playwright = Playwright.create()) {
|
||||
* Browser browser = playwright.webkit().launch();
|
||||
* Page page = browser.newPage();
|
||||
* page.navigate("https://www.w3.org/");
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -141,11 +141,6 @@ public interface Route {
|
||||
* If set changes the request HTTP headers. Header values will be converted to a string.
|
||||
*/
|
||||
public Map<String, String> headers;
|
||||
/**
|
||||
* Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is
|
||||
* exceeded. Defaults to {@code 20}. Pass {@code 0} to not follow redirects.
|
||||
*/
|
||||
public Integer maxRedirects;
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
@@ -154,10 +149,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.
|
||||
*/
|
||||
@@ -170,14 +161,6 @@ public interface Route {
|
||||
this.headers = headers;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is
|
||||
* exceeded. Defaults to {@code 20}. Pass {@code 0} to not follow redirects.
|
||||
*/
|
||||
public FetchOptions setMaxRedirects(int maxRedirects) {
|
||||
this.maxRedirects = maxRedirects;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
@@ -199,13 +182,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.
|
||||
*/
|
||||
@@ -345,13 +321,6 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Note that any overrides such as {@code url} or {@code headers} only apply to the request being routed. If this request
|
||||
* results in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header
|
||||
* through redirects, use the combination of {@link Route#fetch Route.fetch()} and {@link Route#fulfill Route.fulfill()}
|
||||
* instead.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
default void resume() {
|
||||
@@ -371,13 +340,6 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Note that any overrides such as {@code url} or {@code headers} only apply to the request being routed. If this request
|
||||
* results in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header
|
||||
* through redirects, use the combination of {@link Route#fetch Route.fetch()} and {@link Route#fulfill Route.fulfill()}
|
||||
* instead.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void resume(ResumeOptions options);
|
||||
@@ -526,12 +488,6 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Note that {@code headers} option will apply to the fetched request as well as any redirects initiated by it. If you want
|
||||
* to only apply {@code headers} to the original request, but not to redirects, look into {@link Route#resume
|
||||
* Route.resume()} instead.
|
||||
*
|
||||
* @since v1.29
|
||||
*/
|
||||
default APIResponse fetch() {
|
||||
@@ -554,12 +510,6 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Note that {@code headers} option will apply to the fetched request as well as any redirects initiated by it. If you want
|
||||
* to only apply {@code headers} to the original request, but not to redirects, look into {@link Route#resume
|
||||
* Route.resume()} instead.
|
||||
*
|
||||
* @since v1.29
|
||||
*/
|
||||
APIResponse fetch(FetchOptions options);
|
||||
|
||||
@@ -42,9 +42,7 @@ public interface Selectors {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -66,8 +64,8 @@ public interface Selectors {
|
||||
* page.setContent("<div><button>Click me</button></div>");
|
||||
* // Use the selector prefixed with its name.
|
||||
* Locator button = page.locator("tag=button");
|
||||
* // Combine it with built-in locators.
|
||||
* page.locator("tag=div").getByText("Click me").click();
|
||||
* // Combine it with other selector engines.
|
||||
* page.locator("tag=div >> text=\"Click me\"").click();
|
||||
* // Can use it in any methods supporting selectors.
|
||||
* int buttonCount = (int) page.locator("tag=button").count();
|
||||
* browser.close();
|
||||
@@ -82,9 +80,7 @@ public interface Selectors {
|
||||
register(name, script, null);
|
||||
}
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -106,8 +102,8 @@ public interface Selectors {
|
||||
* page.setContent("<div><button>Click me</button></div>");
|
||||
* // Use the selector prefixed with its name.
|
||||
* Locator button = page.locator("tag=button");
|
||||
* // Combine it with built-in locators.
|
||||
* page.locator("tag=div").getByText("Click me").click();
|
||||
* // Combine it with other selector engines.
|
||||
* page.locator("tag=div >> text=\"Click me\"").click();
|
||||
* // Can use it in any methods supporting selectors.
|
||||
* int buttonCount = (int) page.locator("tag=button").count();
|
||||
* browser.close();
|
||||
@@ -120,9 +116,7 @@ public interface Selectors {
|
||||
*/
|
||||
void register(String name, String script, RegisterOptions options);
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -144,8 +138,8 @@ public interface Selectors {
|
||||
* page.setContent("<div><button>Click me</button></div>");
|
||||
* // Use the selector prefixed with its name.
|
||||
* Locator button = page.locator("tag=button");
|
||||
* // Combine it with built-in locators.
|
||||
* page.locator("tag=div").getByText("Click me").click();
|
||||
* // Combine it with other selector engines.
|
||||
* page.locator("tag=div >> text=\"Click me\"").click();
|
||||
* // Can use it in any methods supporting selectors.
|
||||
* int buttonCount = (int) page.locator("tag=button").count();
|
||||
* browser.close();
|
||||
@@ -160,9 +154,7 @@ public interface Selectors {
|
||||
register(name, script, null);
|
||||
}
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -184,8 +176,8 @@ public interface Selectors {
|
||||
* page.setContent("<div><button>Click me</button></div>");
|
||||
* // Use the selector prefixed with its name.
|
||||
* Locator button = page.locator("tag=button");
|
||||
* // Combine it with built-in locators.
|
||||
* page.locator("tag=div").getByText("Click me").click();
|
||||
* // Combine it with other selector engines.
|
||||
* page.locator("tag=div >> text=\"Click me\"").click();
|
||||
* // Can use it in any methods supporting selectors.
|
||||
* int buttonCount = (int) page.locator("tag=button").count();
|
||||
* browser.close();
|
||||
|
||||
@@ -25,8 +25,6 @@ public interface Touchscreen {
|
||||
/**
|
||||
* Dispatches a {@code touchstart} and {@code touchend} event with a single touch at the position ({@code x},{@code y}).
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link Page#tap Page.tap()} the method will throw if {@code hasTouch} option of the browser context is false.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void tap(double x, double y);
|
||||
|
||||
@@ -38,9 +38,8 @@ import java.nio.file.Path;
|
||||
public interface Tracing {
|
||||
class StartOptions {
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stop Tracing.stop()} instead.
|
||||
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
|
||||
* specified in {@link BrowserType#launch BrowserType.launch()}.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
@@ -67,9 +66,8 @@ public interface Tracing {
|
||||
public String title;
|
||||
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stop Tracing.stop()} instead.
|
||||
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
|
||||
* specified in {@link BrowserType#launch BrowserType.launch()}.
|
||||
*/
|
||||
public StartOptions setName(String name) {
|
||||
this.name = name;
|
||||
@@ -111,26 +109,11 @@ public interface Tracing {
|
||||
}
|
||||
}
|
||||
class StartChunkOptions {
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stopChunk Tracing.stopChunk()} instead.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Trace name to be shown in the Trace Viewer.
|
||||
*/
|
||||
public String title;
|
||||
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stopChunk Tracing.stopChunk()} instead.
|
||||
*/
|
||||
public StartChunkOptions setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Trace name to be shown in the Trace Viewer.
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
+2
-1
@@ -19,7 +19,8 @@ package com.microsoft.playwright.assertions;
|
||||
|
||||
/**
|
||||
* The {@code APIResponseAssertions} class provides assertion methods that can be used to make assertions about the {@code
|
||||
* APIResponse} in the tests.
|
||||
* APIResponse} in the tests. A new instance of {@code APIResponseAssertions} is created by calling {@link
|
||||
* PlaywrightAssertions#assertThat PlaywrightAssertions.assertThat()}:
|
||||
* <pre>{@code
|
||||
* ...
|
||||
* import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
|
||||
+76
-304
@@ -20,7 +20,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* The {@code LocatorAssertions} class provides assertion methods that can be used to make assertions about the {@code
|
||||
* Locator} state in the tests.
|
||||
* Locator} state in the tests. A new instance of {@code LocatorAssertions} is created by calling {@link
|
||||
* PlaywrightAssertions#assertThat PlaywrightAssertions.assertThat()}:
|
||||
* <pre>{@code
|
||||
* ...
|
||||
* import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
@@ -37,29 +38,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 +50,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 +59,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 +74,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 +83,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 +92,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 +107,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 +116,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 +125,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,54 +139,27 @@ 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;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class IsInViewportOptions {
|
||||
/**
|
||||
* The minimal ratio of the element to intersect viewport. If equals to {@code 0}, then element should intersect viewport
|
||||
* at any positive ratio. Defaults to {@code 0}.
|
||||
*/
|
||||
public Double ratio;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* The minimal ratio of the element to intersect viewport. If equals to {@code 0}, then element should intersect viewport
|
||||
* at any positive ratio. Defaults to {@code 0}.
|
||||
*/
|
||||
public IsInViewportOptions setRatio(double ratio) {
|
||||
this.ratio = ratio;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsInViewportOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
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 +177,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 +194,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 +210,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 +224,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 +238,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 +252,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 +266,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 +280,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 +299,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 +316,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 +332,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 +346,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 +368,6 @@ public interface LocatorAssertions {
|
||||
* @since v1.20
|
||||
*/
|
||||
LocatorAssertions not();
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an element that is <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected">connected</a> to a Document or a ShadowRoot.
|
||||
*
|
||||
* <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 element that is <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected">connected</a> to a Document or a ShadowRoot.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.33
|
||||
*/
|
||||
void isAttached(IsAttachedOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
@@ -633,63 +549,12 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void isHidden(IsHiddenOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that intersects viewport, according to the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API">intersection observer API</a>.
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
|
||||
* and <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByRole(AriaRole.BUTTON);
|
||||
* // Make sure at least some part of element intersects viewport.
|
||||
* assertThat(locator).isInViewport();
|
||||
* // Make sure element is fully outside of viewport.
|
||||
* assertThat(locator).not().isInViewport();
|
||||
* // Make sure that at least half of the element intersects viewport.
|
||||
* assertThat(locator).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.5));
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.31
|
||||
*/
|
||||
default void isInViewport() {
|
||||
isInViewport(null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that intersects viewport, according to the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API">intersection observer API</a>.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByRole(AriaRole.BUTTON);
|
||||
* // Make sure at least some part of element intersects viewport.
|
||||
* assertThat(locator).isInViewport();
|
||||
* // Make sure element is fully outside of viewport.
|
||||
* assertThat(locator).not().isInViewport();
|
||||
* // Make sure that at least half of the element intersects viewport.
|
||||
* assertThat(locator).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.5));
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.31
|
||||
*/
|
||||
void isInViewport(IsInViewportOptions options);
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an attached and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
|
||||
*
|
||||
* <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
|
||||
@@ -698,38 +563,20 @@ public interface LocatorAssertions {
|
||||
isVisible(null);
|
||||
}
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an attached and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
|
||||
* and <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // A specific element is visible.
|
||||
* assertThat(page.getByText("Welcome")).isVisible();
|
||||
*
|
||||
* // At least one item in the list is visible.
|
||||
* asserThat(page.getByTestId("todo-item").first()).isVisible();
|
||||
*
|
||||
* // At least one of the two elements is visible, possibly both.
|
||||
* asserThat(
|
||||
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
|
||||
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .first()
|
||||
* ).isVisible();
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.20
|
||||
*/
|
||||
void isVisible(IsVisibleOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -768,13 +615,8 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -811,13 +653,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void containsText(String expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -856,13 +693,8 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -899,13 +731,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void containsText(Pattern expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -944,13 +771,8 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -987,13 +809,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void containsText(String[] expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1032,13 +849,8 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1455,13 +1267,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasJSProperty(String name, Object value, HasJSPropertyOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1500,13 +1307,8 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1543,13 +1345,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasText(String expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1588,13 +1385,8 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1631,13 +1423,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasText(Pattern expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1676,13 +1463,8 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1719,13 +1501,8 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasText(String[] expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1764,13 +1541,8 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
|
||||
@@ -20,7 +20,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* The {@code PageAssertions} class provides assertion methods that can be used to make assertions about the {@code Page}
|
||||
* state in the tests.
|
||||
* state in the tests. A new instance of {@code PageAssertions} is created by calling {@link
|
||||
* PlaywrightAssertions#assertThat PlaywrightAssertions.assertThat()}:
|
||||
* <pre>{@code
|
||||
* ...
|
||||
* import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
@@ -39,12 +40,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 +54,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);
|
||||
@@ -196,7 +193,7 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
|
||||
private static RequestOptionsImpl ensureOptions(RequestOptions options, String method) {
|
||||
RequestOptionsImpl impl = Utils.clone((RequestOptionsImpl) options);
|
||||
RequestOptionsImpl impl = (RequestOptionsImpl) options;
|
||||
if (impl == null) {
|
||||
impl = new RequestOptionsImpl();
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -47,16 +46,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
private final APIRequestContextImpl request;
|
||||
final List<PageImpl> pages = new ArrayList<>();
|
||||
final Router routes = new Router();
|
||||
private boolean closeWasCalled;
|
||||
private final WaitableEvent<EventType, ?> closePromise;
|
||||
private boolean isClosedOrClosing;
|
||||
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 +75,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
CONSOLE,
|
||||
DIALOG,
|
||||
PAGE,
|
||||
WEBERROR,
|
||||
REQUEST,
|
||||
REQUESTFAILED,
|
||||
REQUESTFINISHED,
|
||||
@@ -98,9 +89,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
} else {
|
||||
browser = null;
|
||||
}
|
||||
tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
|
||||
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
|
||||
this.tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
this.request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
|
||||
}
|
||||
|
||||
void setRecordHar(Path path, HarContentPolicy policy) {
|
||||
@@ -117,16 +107,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 +117,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 +127,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 +188,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 +197,12 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
|
||||
}
|
||||
|
||||
private void closeImpl(CloseOptions options) {
|
||||
if (!closeWasCalled) {
|
||||
closeWasCalled = true;
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
private void closeImpl() {
|
||||
if (isClosedOrClosing) {
|
||||
return;
|
||||
}
|
||||
isClosedOrClosing = true;
|
||||
try {
|
||||
for (Map.Entry<String, HarRecorder> entry : harRecorders.entrySet()) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("harId", entry.getKey());
|
||||
@@ -291,10 +224,13 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
artifact.delete();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("close", params);
|
||||
|
||||
sendMessage("close");
|
||||
} catch (PlaywrightException e) {
|
||||
if (!isSafeCloseError(e)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
runUntil(() -> {}, closePromise);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -463,7 +399,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
private void route(UrlMatcher matcher, Consumer<Route> handler, RouteOptions options) {
|
||||
withLogging("BrowserContext.route", () -> {
|
||||
routes.add(matcher, handler, options == null ? null : options.times);
|
||||
updateInterceptionPatterns();
|
||||
if (routes.size() == 1) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("enabled", true);
|
||||
sendMessage("setNetworkInterceptionEnabled", params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -474,12 +414,8 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
JsonObject jsonOptions = new JsonObject();
|
||||
jsonOptions.addProperty("path", har.toAbsolutePath().toString());
|
||||
jsonOptions.addProperty("content", options.updateContent == null ?
|
||||
HarContentPolicy.ATTACH.name().toLowerCase() :
|
||||
options.updateContent.name().toLowerCase());
|
||||
jsonOptions.addProperty("mode", options.updateMode == null ?
|
||||
HarMode.MINIMAL.name().toLowerCase() :
|
||||
options.updateMode.name().toLowerCase());
|
||||
jsonOptions.addProperty("content", HarContentPolicy.ATTACH.name().toLowerCase());
|
||||
jsonOptions.addProperty("mode", HarMode.MINIMAL.name().toLowerCase());
|
||||
addHarUrlFilter(jsonOptions, options.url);
|
||||
params.add("options", jsonOptions);
|
||||
JsonObject json = sendMessage("harStart", params).getAsJsonObject();
|
||||
@@ -489,10 +425,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 +435,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();
|
||||
@@ -568,14 +496,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return tracing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unrouteAll() {
|
||||
withLogging("BrowserContext.unrouteAll", () -> {
|
||||
routes.removeAll();
|
||||
updateInterceptionPatterns();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unroute(String url, Consumer<Route> handler) {
|
||||
unroute(new UrlMatcher(this.baseUrl, url), handler);
|
||||
@@ -591,27 +511,6 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
unroute(new UrlMatcher(url), handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForCondition(BooleanSupplier predicate, WaitForConditionOptions options) {
|
||||
List<Waitable<Void>> waitables = new ArrayList<>();
|
||||
waitables.add(new WaitableContextClose<>());
|
||||
waitables.add(timeoutSettings.createWaitable(options == null ? null : options.timeout));
|
||||
waitables.add(new WaitablePredicate<>(predicate));
|
||||
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);
|
||||
@@ -619,69 +518,43 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public R get() {
|
||||
throw new TargetClosedError(effectiveCloseReason());
|
||||
throw new PlaywrightException("Context closed");
|
||||
}
|
||||
}
|
||||
|
||||
private void unroute(UrlMatcher matcher, Consumer<Route> handler) {
|
||||
withLogging("BrowserContext.unroute", () -> {
|
||||
routes.remove(matcher, handler);
|
||||
updateInterceptionPatterns();
|
||||
maybeDisableNetworkInterception();
|
||||
});
|
||||
}
|
||||
|
||||
private void updateInterceptionPatterns() {
|
||||
sendMessage("setNetworkInterceptionPatterns", routes.interceptionPatterns());
|
||||
private void maybeDisableNetworkInterception() {
|
||||
if (routes.size() == 0) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("enabled", false);
|
||||
sendMessage("setNetworkInterceptionEnabled", params);
|
||||
}
|
||||
}
|
||||
|
||||
void handleRoute(RouteImpl route) {
|
||||
Router.HandleResult handled = routes.handle(route);
|
||||
if (handled != Router.HandleResult.NoMatchingHandler) {
|
||||
updateInterceptionPatterns();
|
||||
maybeDisableNetworkInterception();
|
||||
}
|
||||
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
|
||||
route.resume(null, true);
|
||||
route.resume();
|
||||
}
|
||||
}
|
||||
|
||||
WaitableResult<JsonElement> pause() {
|
||||
return sendMessageAsync("pause", new JsonObject());
|
||||
void pause() {
|
||||
sendMessage("pause");
|
||||
}
|
||||
|
||||
@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());
|
||||
@@ -696,13 +569,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);
|
||||
@@ -746,41 +612,22 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
void didClose() {
|
||||
isClosedOrClosing = true;
|
||||
if (browser != null) {
|
||||
browser.contexts.remove(this);
|
||||
}
|
||||
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;
|
||||
@@ -40,9 +41,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
boolean isConnectedOverWebSocket;
|
||||
private boolean isConnected = true;
|
||||
BrowserTypeImpl browserType;
|
||||
BrowserType.LaunchOptions launchOptions;
|
||||
private Path tracePath;
|
||||
String closeReason;
|
||||
|
||||
enum EventType {
|
||||
DISCONNECTED,
|
||||
@@ -68,15 +66,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 +182,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 +202,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;
|
||||
@@ -219,9 +209,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
context.setBaseUrl(options.baseURL);
|
||||
}
|
||||
context.setRecordHar(recordHarPath, harContentPolicy);
|
||||
if (launchOptions != null) {
|
||||
context.tracing().setTracesDir(launchOptions.tracesDir);
|
||||
}
|
||||
contexts.add(context);
|
||||
return context;
|
||||
}
|
||||
@@ -240,7 +227,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 +241,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 +272,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);
|
||||
}
|
||||
@@ -50,7 +52,6 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
JsonElement result = sendMessage("launch", params);
|
||||
BrowserImpl browser = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("browser").get("guid").getAsString());
|
||||
browser.browserType = this;
|
||||
browser.launchOptions = options;
|
||||
return browser;
|
||||
}
|
||||
|
||||
@@ -201,7 +202,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 +222,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;
|
||||
@@ -232,7 +229,6 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
context.setBaseUrl(options.baseURL);
|
||||
}
|
||||
context.setRecordHar(recordHarPath, harContentPolicy);
|
||||
context.tracing().setTracesDir(options.tracesDir);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
@@ -25,13 +24,10 @@ 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;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
|
||||
class Message {
|
||||
int id;
|
||||
@@ -40,7 +36,6 @@ class Message {
|
||||
JsonObject params;
|
||||
JsonElement result;
|
||||
SerializedError error;
|
||||
JsonArray log;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -72,7 +67,6 @@ public class Connection {
|
||||
}
|
||||
LocalUtils localUtils;
|
||||
final Map<String, String> env;
|
||||
private int tracingCount;
|
||||
|
||||
class Root extends ChannelOwner {
|
||||
Root(Connection connection) {
|
||||
@@ -107,12 +101,8 @@ public class Connection {
|
||||
stackTraceCollector = StackTraceCollector.createFromEnv(env);
|
||||
}
|
||||
|
||||
void setIsTracing(boolean tracing) {
|
||||
if (tracing) {
|
||||
++tracingCount;
|
||||
} else {
|
||||
--tracingCount;
|
||||
}
|
||||
boolean isCollectingStacks() {
|
||||
return stackTraceCollector != null;
|
||||
}
|
||||
|
||||
String setApiName(String name) {
|
||||
@@ -130,10 +120,10 @@ public class Connection {
|
||||
}
|
||||
|
||||
public WaitableResult<JsonElement> sendMessageAsync(String guid, String method, JsonObject params) {
|
||||
return internalSendMessage(guid, method, params, true);
|
||||
return internalSendMessage(guid, method, params);
|
||||
}
|
||||
|
||||
private WaitableResult<JsonElement> internalSendMessage(String guid, String method, JsonObject params, boolean sendStack) {
|
||||
private WaitableResult<JsonElement> internalSendMessage(String guid, String method, JsonObject params) {
|
||||
int id = ++lastId;
|
||||
WaitableResult<JsonElement> result = new WaitableResult<>();
|
||||
callbacks.put(id, result);
|
||||
@@ -143,8 +133,6 @@ public class Connection {
|
||||
message.addProperty("method", method);
|
||||
message.add("params", params);
|
||||
JsonObject metadata = new JsonObject();
|
||||
metadata.addProperty("wallTime", currentTimeMillis());
|
||||
JsonArray stack = null;
|
||||
if (apiName == null) {
|
||||
metadata.addProperty("internal", true);
|
||||
} else {
|
||||
@@ -152,27 +140,11 @@ public class Connection {
|
||||
// All but first message in an API call are considered internal and will be hidden from the inspector.
|
||||
apiName = null;
|
||||
if (stackTraceCollector != null) {
|
||||
stack = stackTraceCollector.currentStackTrace();
|
||||
if (!stack.isEmpty()) {
|
||||
JsonObject location = new JsonObject();
|
||||
JsonObject frame = stack.get(0).getAsJsonObject();
|
||||
location.addProperty("file", frame.get("file").getAsString());
|
||||
location.addProperty("line", frame.get("line").getAsInt());
|
||||
location.addProperty("column", frame.get("column").getAsInt());
|
||||
metadata.add("location", location);
|
||||
}
|
||||
metadata.add("stack", stackTraceCollector.currentStackTrace());
|
||||
}
|
||||
}
|
||||
message.add("metadata", metadata);
|
||||
transport.send(message);
|
||||
if (sendStack && tracingCount > 0 && stack != null && !method.startsWith("LocalUtils")) {
|
||||
JsonObject callData = new JsonObject();
|
||||
callData.addProperty("id", id);
|
||||
callData.add("stack", stack);
|
||||
JsonObject stackParams = new JsonObject();
|
||||
stackParams.add("callData", callData);
|
||||
internalSendMessage(localUtils.guid,"addStackToTracingNoReply", stackParams, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -209,30 +181,6 @@ public class Connection {
|
||||
dispatch(messageObj);
|
||||
}
|
||||
|
||||
private static String formatCallLog(JsonArray log) {
|
||||
if (log == null) {
|
||||
return "";
|
||||
}
|
||||
boolean allEmpty = true;
|
||||
for (JsonElement e: log) {
|
||||
if (!e.getAsString().isEmpty()) {
|
||||
allEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allEmpty) {
|
||||
return "";
|
||||
}
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add("");
|
||||
lines.add("Call log:");
|
||||
for (JsonElement e: log) {
|
||||
lines.add("- " + e.getAsString());
|
||||
}
|
||||
lines.add("");
|
||||
return String.join("\n", lines);
|
||||
}
|
||||
|
||||
private void dispatch(Message message) {
|
||||
// System.out.println("Message: " + message.method + " " + message.id);
|
||||
if (message.id != 0) {
|
||||
@@ -245,18 +193,12 @@ public class Connection {
|
||||
if (message.error == null) {
|
||||
callback.complete(message.result);
|
||||
} else {
|
||||
String callLog = formatCallLog(message.log);
|
||||
if (message.error.error == null) {
|
||||
callback.completeExceptionally(new PlaywrightException(message.error + callLog));
|
||||
} else if ("Expect".equals(message.error.error.name)) {
|
||||
callback.complete(message.result);
|
||||
callback.completeExceptionally(new PlaywrightException(message.error.toString()));
|
||||
} else if ("TimeoutError".equals(message.error.error.name)) {
|
||||
callback.completeExceptionally(new TimeoutError(message.error.error + callLog));
|
||||
} else if ("TargetClosedError".equals(message.error.error.name)) {
|
||||
callback.completeExceptionally(new TargetClosedError(message.error.error + callLog));
|
||||
|
||||
callback.completeExceptionally(new TimeoutError(message.error.error.toString()));
|
||||
} else {
|
||||
callback.completeExceptionally(new DriverException(message.error.error + callLog));
|
||||
callback.completeExceptionally(new DriverException(message.error.error));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -285,8 +227,7 @@ public class Connection {
|
||||
return;
|
||||
}
|
||||
if (message.method.equals("__dispose__")) {
|
||||
boolean wasCollected = message.params.has("reason") && "gc".equals(message.params.get("reason").getAsString());
|
||||
object.disposeChannelOwner(wasCollected);
|
||||
object.disconnect();
|
||||
return;
|
||||
}
|
||||
object.handleEvent(message.method, message.params);
|
||||
@@ -327,6 +268,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;
|
||||
@@ -390,9 +334,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
|
||||
@@ -490,7 +495,7 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.add("payloads", Serialization.toJsonArray(files));
|
||||
params.add("files", Serialization.toJsonArray(files));
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -761,13 +761,17 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
}
|
||||
|
||||
void setInputFilesImpl(String selector, Path[] files, SetInputFilesOptions options) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
if (hasLargeFile(files)) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addLargeFileUploadParams(files, params, page.context());
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("setInputFilePaths", params);
|
||||
} else {
|
||||
setInputFilesImpl(selector, Utils.toFilePayloads(files), options);
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addFilePathUploadParams(files, params, page.context());
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -787,7 +791,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
params.add("payloads", toJsonArray(files));
|
||||
params.add("files", toJsonArray(files));
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.FrameLocator;
|
||||
import com.microsoft.playwright.Locator;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -120,15 +119,6 @@ class FrameLocatorImpl implements FrameLocator {
|
||||
return new LocatorImpl(frame, frameSelector + " >> internal:control=enter-frame >> " + selector, convertType(options, Locator.LocatorOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator locator(Locator selectorOrLocator, LocatorOptions options) {
|
||||
LocatorImpl other = (LocatorImpl) selectorOrLocator;
|
||||
if (other.frame != frame) {
|
||||
throw new PlaywrightException("Locators must belong to the same frame.");
|
||||
}
|
||||
return locator(other.selector, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameLocator nth(int index) {
|
||||
return new FrameLocatorImpl(frame, frameSelector + " >> nth=" + index);
|
||||
|
||||
@@ -20,38 +20,16 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class LocalUtils extends ChannelOwner {
|
||||
LocalUtils(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
void zip(Path zipFile, JsonArray entries, String stacksId, boolean appendMode, boolean includeSources) {
|
||||
void zip(Path zipFile, JsonArray entries) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("zipFile", zipFile.toString());
|
||||
params.add("entries", entries);
|
||||
params.addProperty("mode", appendMode ? "append" : "write");
|
||||
params.addProperty("stacksId", stacksId);
|
||||
params.addProperty("includeSources", includeSources);
|
||||
sendMessage("zip", params);
|
||||
}
|
||||
|
||||
void traceDiscarded(String stacksId) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("stacksId", stacksId);
|
||||
sendMessage("traceDiscarded", params);
|
||||
}
|
||||
|
||||
String tracingStarted(String tracesDir, String traceName) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (tracesDir != null) {
|
||||
params.addProperty("tracesDir", "");
|
||||
}
|
||||
params.addProperty("traceName", traceName);
|
||||
JsonObject json = connection.localUtils().sendMessage("tracingStarted", params).getAsJsonObject();
|
||||
return json.get("stacksId").getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -150,7 +148,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
options = new HasCountOptions();
|
||||
}
|
||||
FrameExpectOptions commonOptions = convertType(options, FrameExpectOptions.class);
|
||||
commonOptions.expectedNumber = (double) count;
|
||||
commonOptions.expectedNumber = count;
|
||||
List<ExpectedTextValue> expectedText = null;
|
||||
expectImpl("to.have.count", expectedText, count, "Locator expected to have count", commonOptions);
|
||||
}
|
||||
@@ -290,10 +288,8 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
|
||||
@Override
|
||||
public void isChecked(IsCheckedOptions options) {
|
||||
boolean unchecked = options != null && options.checked != null && !options.checked;
|
||||
String expression = unchecked ? "to.be.unchecked" : "to.be.checked";
|
||||
String message = "Locator expected to be " + (unchecked ? "un" : "") + "checked";
|
||||
expectTrue(expression, message, convertType(options, FrameExpectOptions.class));
|
||||
String expression = (options != null && options.checked != null && !options.checked) ? "to.be.unchecked" : "to.be.checked";
|
||||
expectTrue(expression, "Locator expected to be checked", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,8 +301,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void isEditable(IsEditableOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean editable = options == null || options.editable == null || options.editable == true;
|
||||
String message = "Locator expected to be " + (editable ? "editable" : "readonly");
|
||||
expectTrue(editable ? "to.be.editable" : "to.be.readonly", message, frameOptions);
|
||||
expectTrue(editable ? "to.be.editable" : "to.be.readonly", "Locator expected to be editable", frameOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -318,8 +313,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void isEnabled(IsEnabledOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean enabled = options == null || options.enabled == null || options.enabled == true;
|
||||
String message = "Locator expected to be " + (enabled ? "enabled" : "disabled");
|
||||
expectTrue(enabled ? "to.be.enabled" : "to.be.disabled", message, frameOptions);
|
||||
expectTrue(enabled ? "to.be.enabled" : "to.be.disabled", "Locator expected to be enabled", frameOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -332,21 +326,11 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
expectTrue("to.be.hidden", "Locator expected to be hidden", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isInViewport(IsInViewportOptions options) {
|
||||
FrameExpectOptions expectOptions = convertType(options, FrameExpectOptions.class);
|
||||
if (options != null && options.ratio != null) {
|
||||
expectOptions.expectedNumber = options.ratio;
|
||||
}
|
||||
expectTrue("to.be.in.viewport", "Locator expected to be in viewport", expectOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isVisible(IsVisibleOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean visible = options == null || options.visible == null || options.visible == true;
|
||||
String message = "Locator expected to be " + (visible ? "visible" : "hidden");
|
||||
expectTrue(visible ? "to.be.visible" : "to.be.hidden", message, frameOptions);
|
||||
expectTrue(visible ? "to.be.visible" : "to.be.hidden", "Locator expected to be visible", frameOptions);
|
||||
}
|
||||
|
||||
private void expectTrue(String expression, String message, FrameExpectOptions options) {
|
||||
@@ -359,14 +343,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;
|
||||
|
||||
@@ -20,8 +20,8 @@ import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
import static com.microsoft.playwright.impl.Utils.toJsRegexFlags;
|
||||
|
||||
class LocatorImpl implements Locator {
|
||||
final FrameImpl frame;
|
||||
final String selector;
|
||||
private final FrameImpl frame;
|
||||
private final String selector;
|
||||
|
||||
public LocatorImpl(FrameImpl frame, String selector, LocatorOptions options) {
|
||||
this.frame = frame;
|
||||
@@ -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));
|
||||
@@ -401,28 +384,11 @@ class LocatorImpl implements Locator {
|
||||
return new LocatorImpl(frame, this.selector + " >> " + selector, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator locator(Locator selectorOrLocator, LocatorOptions options) {
|
||||
LocatorImpl other = (LocatorImpl) selectorOrLocator;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator nth(int index) {
|
||||
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 +402,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("\"", "\\\\\"") + '"' + (exact ? "" : "i");
|
||||
}
|
||||
|
||||
private static String toJsRegExp(Pattern pattern) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.*;
|
||||
import com.microsoft.playwright.options.*;
|
||||
@@ -25,7 +24,6 @@ import com.microsoft.playwright.options.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -51,8 +49,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 +64,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 +111,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 +136,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,10 +186,9 @@ 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();
|
||||
maybeDisableNetworkInterception();
|
||||
}
|
||||
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
|
||||
browserContext.handleRoute(route);
|
||||
@@ -184,6 +197,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 +224,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);
|
||||
@@ -493,22 +509,19 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
if (isClosed) {
|
||||
return;
|
||||
}
|
||||
closeReason = options.reason;
|
||||
JsonObject params = options == null ? new JsonObject() : gson().toJsonTree(options).getAsJsonObject();
|
||||
try {
|
||||
if (ownedContext != null) {
|
||||
ownedContext.close();
|
||||
} else {
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("close", params);
|
||||
}
|
||||
sendMessage("close", params);
|
||||
} catch (PlaywrightException exception) {
|
||||
if (isSafeCloseError(exception) && (options.runBeforeUnload == null || !options.runBeforeUnload)) {
|
||||
return;
|
||||
if (!isSafeCloseError(exception)) {
|
||||
throw exception;
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
if (ownedContext != null) {
|
||||
ownedContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -935,17 +948,8 @@ 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);
|
||||
}
|
||||
withLogging("BrowserContext.pause", () -> {
|
||||
context().pause();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -955,6 +959,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();
|
||||
}
|
||||
@@ -1029,7 +1036,11 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private void route(UrlMatcher matcher, Consumer<Route> handler, RouteOptions options) {
|
||||
withLogging("Page.route", () -> {
|
||||
routes.add(matcher, handler, options == null ? null : options.times);
|
||||
updateInterceptionPatterns();
|
||||
if (routes.size() == 1) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("enabled", true);
|
||||
sendMessage("setNetworkInterceptionEnabled", params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1226,14 +1237,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
() -> mainFrame.uncheckImpl(selector, convertType(options, Frame.UncheckOptions.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unrouteAll() {
|
||||
withLogging("Page.unrouteAll", () -> {
|
||||
routes.removeAll();
|
||||
updateInterceptionPatterns();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unroute(String url, Consumer<Route> handler) {
|
||||
unroute(new UrlMatcher(browserContext.baseUrl, url), handler);
|
||||
@@ -1252,12 +1255,16 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private void unroute(UrlMatcher matcher, Consumer<Route> handler) {
|
||||
withLogging("Page.unroute", () -> {
|
||||
routes.remove(matcher, handler);
|
||||
updateInterceptionPatterns();
|
||||
maybeDisableNetworkInterception();
|
||||
});
|
||||
}
|
||||
|
||||
private void updateInterceptionPatterns() {
|
||||
sendMessage("setNetworkInterceptionPatterns", routes.interceptionPatterns());
|
||||
private void maybeDisableNetworkInterception() {
|
||||
if (routes.size() == 0) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("enabled", false);
|
||||
sendMessage("setNetworkInterceptionEnabled", params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1358,7 +1365,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new TargetClosedError(effectiveCloseReason());
|
||||
throw new PlaywrightException("Page closed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1369,7 +1376,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new TargetClosedError("Page crashed");
|
||||
throw new PlaywrightException("Page crashed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1457,15 +1464,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
() -> mainFrame.waitForSelectorImpl(selector, convertType(options, Frame.WaitForSelectorOptions.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForCondition(BooleanSupplier predicate, WaitForConditionOptions options) {
|
||||
List<Waitable<Void>> waitables = new ArrayList<>();
|
||||
waitables.add(createWaitForCloseHelper());
|
||||
waitables.add(createWaitableTimeout(options == null ? null : options.timeout));
|
||||
waitables.add(new WaitablePredicate<>(predicate));
|
||||
runUntil(() -> {}, new WaitableRace<>(waitables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForTimeout(double timeout) {
|
||||
withLogging("Page.waitForTimeout", () -> mainFrame.waitForTimeoutImpl(timeout));
|
||||
|
||||
@@ -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{
|
||||
@@ -99,7 +94,7 @@ class ExpectedTextValue {
|
||||
class FrameExpectOptions {
|
||||
Object expressionArg;
|
||||
List<ExpectedTextValue> expectedText;
|
||||
Double expectedNumber;
|
||||
Integer expectedNumber;
|
||||
SerializedArgument expectedValue;
|
||||
Boolean useInnerText;
|
||||
boolean isNot;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,14 @@
|
||||
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Route;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.microsoft.playwright.impl.Utils.toJsRegexFlags;
|
||||
|
||||
class Router {
|
||||
private List<RouteInfo> routes = new ArrayList<>();
|
||||
|
||||
@@ -66,8 +61,8 @@ class Router {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void removeAll() {
|
||||
routes.clear();
|
||||
int size() {
|
||||
return routes.size();
|
||||
}
|
||||
|
||||
enum HandleResult { NoMatchingHandler, Handled, Fallback, PendingHandler }
|
||||
@@ -97,29 +92,4 @@ class Router {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JsonObject interceptionPatterns() {
|
||||
JsonArray jsonPatterns = new JsonArray();
|
||||
for (RouteInfo route : routes) {
|
||||
JsonObject jsonPattern = new JsonObject();
|
||||
Object urlFilter = route.matcher.rawSource;
|
||||
if (urlFilter instanceof String) {
|
||||
jsonPattern.addProperty("glob", (String) urlFilter);
|
||||
} else if (urlFilter instanceof Pattern) {
|
||||
Pattern pattern = (Pattern) urlFilter;
|
||||
jsonPattern.addProperty("regexSource", pattern.pattern());
|
||||
jsonPattern.addProperty("regexFlags", toJsRegexFlags(pattern));
|
||||
} else {
|
||||
// Match all requests.
|
||||
jsonPattern.addProperty("glob", "**/*");
|
||||
jsonPatterns = new JsonArray();
|
||||
jsonPatterns.add(jsonPattern);
|
||||
break;
|
||||
}
|
||||
jsonPatterns.add(jsonPattern);
|
||||
}
|
||||
JsonObject result = new JsonObject();
|
||||
result.add("patterns", jsonPatterns);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -118,7 +118,6 @@ class StackTraceCollector {
|
||||
JsonObject jsonFrame = new JsonObject();
|
||||
jsonFrame.addProperty("file", sourceFile(frame));
|
||||
jsonFrame.addProperty("line", frame.getLineNumber());
|
||||
jsonFrame.addProperty("column", 0);
|
||||
jsonFrame.addProperty("function", frame.getClassName() + "." + frame.getMethodName());
|
||||
jsonStack.add(jsonFrame);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.Tracing;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -25,112 +26,86 @@ import java.nio.file.Path;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class TracingImpl extends ChannelOwner implements Tracing {
|
||||
private boolean includeSources;
|
||||
private Path tracesDir;
|
||||
private boolean isTracing;
|
||||
private String stacksId;
|
||||
|
||||
|
||||
TracingImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
private void stopChunkImpl(Path path) {
|
||||
if (isTracing) {
|
||||
isTracing = false;
|
||||
connection.setIsTracing(false);
|
||||
}
|
||||
JsonObject params = new JsonObject();
|
||||
|
||||
// Not interested in artifacts.
|
||||
if (path == null) {
|
||||
params.addProperty("mode", "discard");
|
||||
sendMessage("tracingStopChunk", params);
|
||||
if (stacksId != null) {
|
||||
connection.localUtils().traceDiscarded(stacksId);
|
||||
String mode = "doNotSave";
|
||||
if (path != null) {
|
||||
if (connection.isRemote) {
|
||||
mode = "compressTrace";
|
||||
} else {
|
||||
mode = "compressTraceAndSources";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isLocal = !connection.isRemote;
|
||||
if (isLocal) {
|
||||
params.addProperty("mode", "entries");
|
||||
JsonObject json = sendMessage("tracingStopChunk", params).getAsJsonObject();
|
||||
JsonArray entries = json.getAsJsonArray("entries");
|
||||
connection.localUtils.zip(path, entries, stacksId, false, includeSources);
|
||||
return;
|
||||
}
|
||||
|
||||
params.addProperty("mode", "archive");
|
||||
params.addProperty("mode", mode);
|
||||
JsonObject json = sendMessage("tracingStopChunk", params).getAsJsonObject();
|
||||
// The artifact may be missing if the browser closed while stopping tracing.
|
||||
if (!json.has("artifact")) {
|
||||
if (stacksId != null) {
|
||||
connection.localUtils().traceDiscarded(stacksId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject("artifact").get("guid").getAsString());
|
||||
artifact.saveAs(path);
|
||||
artifact.delete();
|
||||
|
||||
connection.localUtils.zip(path, new JsonArray(), stacksId, true, includeSources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startChunk(StartChunkOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartChunkOptions();
|
||||
// Add local sources to the remote trace if necessary.
|
||||
// In case of CDP connection since the connection is established by
|
||||
// the driver it is safe to consider the artifact local.
|
||||
if (connection.isRemote && json.has("sourceEntries")) {
|
||||
JsonArray entries = json.getAsJsonArray("sourceEntries");
|
||||
connection.localUtils.zip(path, entries);
|
||||
}
|
||||
tracingStartChunk(options.name, options.title);
|
||||
}
|
||||
|
||||
private void tracingStartChunk(String name, String title) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (name != null) {
|
||||
params.addProperty("name", name);
|
||||
}
|
||||
if (title != null) {
|
||||
params.addProperty("title", title);
|
||||
}
|
||||
JsonObject result = sendMessage("tracingStartChunk", params).getAsJsonObject();
|
||||
startCollectingStacks(result.get("traceName").getAsString());
|
||||
}
|
||||
|
||||
private void startCollectingStacks(String traceName) {
|
||||
if (!isTracing) {
|
||||
isTracing = true;
|
||||
connection.setIsTracing(true);
|
||||
}
|
||||
stacksId = connection.localUtils().tracingStarted(tracesDir == null ? null : tracesDir.toString(), traceName);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("tracingStartChunk", params);
|
||||
}
|
||||
|
||||
private void startImpl(StartOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
includeSources = options.sources != null && options.sources;
|
||||
boolean includeSources = options.sources != null && options.sources;
|
||||
if (includeSources) {
|
||||
if (!connection.isCollectingStacks()) {
|
||||
throw new PlaywrightException("Source root directory must be specified via PLAYWRIGHT_JAVA_SRC environment variable when source collection is enabled");
|
||||
}
|
||||
params.addProperty("sources", true);
|
||||
}
|
||||
sendMessage("tracingStart", params);
|
||||
tracingStartChunk(options.name, options.title);
|
||||
sendMessage("tracingStartChunk");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
void setTracesDir(Path tracesDir) {
|
||||
this.tracesDir = tracesDir;
|
||||
withLogging("Tracing.stopChunk", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.regex.Pattern;
|
||||
import static com.microsoft.playwright.impl.Utils.globToRegex;
|
||||
|
||||
class UrlMatcher {
|
||||
final Object rawSource;
|
||||
private final Object rawSource;
|
||||
private final Predicate<String> predicate;
|
||||
|
||||
private static Predicate<String> toPredicate(Pattern pattern) {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gson.JsonObject;
|
||||
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 +31,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;
|
||||
|
||||
@@ -80,16 +80,7 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
static <T> T clone(T f) {
|
||||
if (f == null) {
|
||||
return f;
|
||||
}
|
||||
return convertType(f, (Class<T>) f.getClass());
|
||||
}
|
||||
|
||||
|
||||
// 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 +88,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 +114,6 @@ class Utils {
|
||||
case '?':
|
||||
tokens.append('.');
|
||||
break;
|
||||
case '[':
|
||||
tokens.append('[');
|
||||
break;
|
||||
case ']':
|
||||
tokens.append(']');
|
||||
break;
|
||||
case '{':
|
||||
inGroup = true;
|
||||
tokens.append('(');
|
||||
@@ -149,11 +130,7 @@ class Utils {
|
||||
tokens.append("\\").append(c);
|
||||
break;
|
||||
default:
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokens.append('$');
|
||||
@@ -173,21 +150,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 +193,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 +243,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,25 +0,0 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
class WaitablePredicate<T> implements Waitable<T> {
|
||||
private final BooleanSupplier predicate;
|
||||
|
||||
WaitablePredicate(BooleanSupplier predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return predicate.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.WebError;
|
||||
|
||||
public class WebErrorImpl implements WebError {
|
||||
private final PageImpl page;
|
||||
private final String error;
|
||||
|
||||
WebErrorImpl(PageImpl page, String error) {
|
||||
this.page = page;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,6 @@ class WritableStream extends ChannelOwner {
|
||||
params.addProperty("binary", new String(encoded.array(), StandardCharsets.UTF_8));
|
||||
sendMessage("write", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
sendMessage("close");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,19 +42,6 @@ public interface FormData {
|
||||
}
|
||||
/**
|
||||
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .set("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .set("profilePicture1", Paths.get("john.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
|
||||
* .set("age", 30);
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
@@ -63,19 +50,6 @@ public interface FormData {
|
||||
FormData set(String name, String value);
|
||||
/**
|
||||
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .set("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .set("profilePicture1", Paths.get("john.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
|
||||
* .set("age", 30);
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
@@ -84,19 +58,6 @@ public interface FormData {
|
||||
FormData set(String name, boolean value);
|
||||
/**
|
||||
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .set("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .set("profilePicture1", Paths.get("john.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
|
||||
* .set("age", 30);
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
@@ -105,19 +66,6 @@ public interface FormData {
|
||||
FormData set(String name, int value);
|
||||
/**
|
||||
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .set("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .set("profilePicture1", Paths.get("john.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
|
||||
* .set("age", 30);
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
@@ -126,19 +74,6 @@ public interface FormData {
|
||||
FormData set(String name, Path value);
|
||||
/**
|
||||
* Sets a field on the form. File values can be passed either as {@code Path} or as {@code FilePayload}.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .set("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .set("profilePicture1", Paths.get("john.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))));
|
||||
* .set("age", 30);
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -110,8 +110,7 @@ public interface RequestOptions {
|
||||
*/
|
||||
RequestOptions setForm(FormData form);
|
||||
/**
|
||||
* Sets an HTTP header to the request. This header will apply to the fetched request as well as any redirects initiated by
|
||||
* it.
|
||||
* Sets an HTTP header to the request.
|
||||
*
|
||||
* @param name Header name.
|
||||
* @param value Header value.
|
||||
|
||||
-22
@@ -1,22 +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.options;
|
||||
|
||||
public enum RouteFromHarUpdateContentPolicy {
|
||||
EMBED,
|
||||
ATTACH
|
||||
}
|
||||
@@ -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;
|
||||
/**
|
||||
|
||||
@@ -1,54 +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.*;
|
||||
|
||||
// Copied from expect-misc.spec.ts > toBeInViewport
|
||||
public class TestAssertThatIsInViewport extends TestBase {
|
||||
@Test
|
||||
void shouldWork() {
|
||||
page.setContent("<div id=big style=\"height: 10000px;\"></div>\n" +
|
||||
" <div id=small>foo</div>");
|
||||
assertThat(page.locator("#big")).isInViewport();
|
||||
assertThat(page.locator("#small")).not().isInViewport();
|
||||
page.locator("#small").scrollIntoViewIfNeeded();
|
||||
assertThat(page.locator("#small")).isInViewport();
|
||||
assertThat(page.locator("#small")).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRespectRatioOption() {
|
||||
page.setContent("<style>body, div, html { padding: 0; margin: 0; }</style>\n" +
|
||||
" <div id=big style=\"height: 400vh;\"></div>");
|
||||
assertThat(page.locator("div")).isInViewport();
|
||||
assertThat(page.locator("div")).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.1));
|
||||
assertThat(page.locator("div")).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.2));
|
||||
|
||||
assertThat(page.locator("div")).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.24));
|
||||
// In this test, element's ratio is 0.25.
|
||||
assertThat(page.locator("div")).isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.25));
|
||||
assertThat(page.locator("div")).not().isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.26));
|
||||
|
||||
assertThat(page.locator("div")).not().isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.3));
|
||||
assertThat(page.locator("div")).not().isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.7));
|
||||
assertThat(page.locator("div")).not().isInViewport(new LocatorAssertions.IsInViewportOptions().setRatio(0.8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveGoodStack() {
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class, () -> assertThat(page.locator("body")).not().isInViewport(new LocatorAssertions.IsInViewportOptions().setTimeout(100)));
|
||||
assertNotNull(error);
|
||||
assertTrue(error.getMessage().contains("Locator expected not to be in viewport"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReportIntersectionEvenIfFullyCoveredByOtherElement() {
|
||||
page.setContent("<h1>hello</h1>\n" +
|
||||
" <div style=\"position: relative; height: 10000px; top: -5000px;></div>");
|
||||
assertThat(page.locator("h1")).isInViewport();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -20,11 +20,9 @@ import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.Utils.verifyViewport;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBrowserContextBasic extends TestBase {
|
||||
@@ -144,7 +142,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
context.waitForPage(() -> context.close());
|
||||
});
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Context closed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,17 +234,8 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
void shouldWorkWithOfflineOption() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setOffline(true));
|
||||
Page page = context.newPage();
|
||||
if (isFirefox()) {
|
||||
// Firefox navigates to an error page, and this navigation might conflict with the
|
||||
// next navigation we do in test.
|
||||
// So we need to wait for the navigation explicitly.
|
||||
boolean[] frameNavigated = { false };
|
||||
page.onFrameNavigated(frame -> frameNavigated[0] = true);
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
|
||||
page.waitForCondition(() -> frameNavigated[0], new Page.WaitForConditionOptions().setTimeout(10_000));
|
||||
} else {
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
|
||||
}
|
||||
assertThrows(PlaywrightException.class, () -> page.navigate(server.EMPTY_PAGE));
|
||||
|
||||
context.setOffline(false);
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals(200, response.status());
|
||||
@@ -264,42 +253,4 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
assertEquals(true, page.evaluate("() => window.navigator.onLine"));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWaitForCondition() {
|
||||
List<String> messages = new ArrayList<>();
|
||||
page.onConsoleMessage(m -> messages.add(m.text()));
|
||||
page.evaluate("setTimeout(() => {\n" +
|
||||
" console.log('foo');\n" +
|
||||
" console.log('bar');\n" +
|
||||
"}, 100);");
|
||||
context.waitForCondition(() -> messages.size() > 1);
|
||||
assertEquals(asList("foo", "bar"), messages);
|
||||
}
|
||||
|
||||
@Test
|
||||
void waitForConditionTimeout() {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class,
|
||||
() -> context.waitForCondition(() -> false, new BrowserContext.WaitForConditionOptions().setTimeout(100)));
|
||||
assertTrue(e.getMessage().contains("Timeout"), e.getMessage());
|
||||
}
|
||||
@Test
|
||||
void waitForConditionPageClosed() {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class,
|
||||
() -> context.waitForCondition(() -> {
|
||||
context.close();
|
||||
return false;
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("Target page, context or browser has been closed"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPropagateCloseReasonToPendingActions() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.waitForPopup(() -> {
|
||||
context.close(new BrowserContext.CloseOptions().setReason("The reason."));
|
||||
}));
|
||||
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.microsoft.playwright;
|
||||
import com.microsoft.playwright.options.HarContentPolicy;
|
||||
import com.microsoft.playwright.options.HarMode;
|
||||
import com.microsoft.playwright.options.HarNotFound;
|
||||
import com.microsoft.playwright.options.RouteFromHarUpdateContentPolicy;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -39,7 +38,6 @@ import static com.microsoft.playwright.Utils.copy;
|
||||
import static com.microsoft.playwright.Utils.extractZip;
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static com.microsoft.playwright.options.HarContentPolicy.ATTACH;
|
||||
import static com.microsoft.playwright.options.HarContentPolicy.EMBED;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBrowserContextHar extends TestBase {
|
||||
@@ -432,27 +430,6 @@ public class TestBrowserContextHar extends TestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateHarZipForPageWithDifferentOptions(@TempDir Path tmpDir) {
|
||||
Path harPath = tmpDir.resolve("har.zip");
|
||||
try (BrowserContext context1 = browser.newContext()) {
|
||||
Page page1 = context1.newPage();
|
||||
page1.routeFromHAR(harPath, new Page.RouteFromHAROptions()
|
||||
.setUpdate(true)
|
||||
.setUpdateContent(RouteFromHarUpdateContentPolicy.EMBED)
|
||||
.setUpdateMode(HarMode.FULL));
|
||||
page1.navigate(server.PREFIX + "/one-style.html");
|
||||
}
|
||||
|
||||
try (BrowserContext context2 = browser.newContext()) {
|
||||
Page page2 = context2.newPage();
|
||||
page2.routeFromHAR(harPath, new Page.RouteFromHAROptions().setNotFound(HarNotFound.ABORT));
|
||||
page2.navigate(server.PREFIX + "/one-style.html");
|
||||
assertTrue(page2.content().contains("hello, world!"));
|
||||
assertThat(page2.locator("body")).hasCSS("background-color", "rgb(255, 192, 203)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateExtractedHarZipForPage(@TempDir Path tmpDir) {
|
||||
Path harPath = tmpDir.resolve("har.har");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -353,6 +350,39 @@ public class TestBrowserTypeConnect extends TestBase {
|
||||
browser.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotThrowOnContextCloseAfterDisconnect() throws InterruptedException {
|
||||
BrowserServer remoteServer = launchBrowserServer(browserType);
|
||||
Browser browser = browserType.connect(remoteServer.wsEndpoint);
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
|
||||
remoteServer.kill();
|
||||
while (browser.isConnected()) {
|
||||
try {
|
||||
page.waitForTimeout(10);
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
}
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotThrowOnPageCloseAfterDisconnect() throws InterruptedException {
|
||||
BrowserServer remoteServer = launchBrowserServer(browserType);
|
||||
Browser browser = browserType.connect(remoteServer.wsEndpoint);
|
||||
Page page = browser.newPage();
|
||||
|
||||
remoteServer.kill();
|
||||
while (browser.isConnected()) {
|
||||
try {
|
||||
page.waitForTimeout(10);
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
}
|
||||
page.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSaveAsVideosFromRemoteBrowser(@TempDir Path tempDir) {
|
||||
Path videosPath = tempDir.resolve("videosPath");
|
||||
@@ -504,17 +534,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,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
@@ -405,12 +406,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 +420,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");
|
||||
|
||||
@@ -12,7 +12,7 @@ public class TestElementHandleSelectText extends TestBase {
|
||||
ElementHandle textarea = page.querySelector("textarea");
|
||||
textarea.evaluate("textarea => textarea.value = 'some value'");
|
||||
textarea.selectText();
|
||||
if (isFirefox() || isWebKit()) {
|
||||
if (isFirefox()) {
|
||||
assertEquals(0, textarea.evaluate("el => el.selectionStart"));
|
||||
assertEquals(10, textarea.evaluate("el => el.selectionEnd"));
|
||||
} else {
|
||||
@@ -26,7 +26,7 @@ public class TestElementHandleSelectText extends TestBase {
|
||||
ElementHandle input = page.querySelector("input");
|
||||
input.evaluate("input => input.value = 'some value'");
|
||||
input.selectText();
|
||||
if (isFirefox() || isWebKit()) {
|
||||
if (isFirefox()) {
|
||||
assertEquals(0, input.evaluate("el => el.selectionStart"));
|
||||
assertEquals(10, input.evaluate("el => el.selectionEnd"));
|
||||
} else {
|
||||
|
||||
@@ -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;
|
||||
@@ -165,10 +164,10 @@ public class TestGlobalFetch extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldSupportGlobalTimeoutOption() {
|
||||
APIRequestContext request = playwright.request().newContext(new APIRequest.NewContextOptions().setTimeout(100));
|
||||
APIRequestContext request = playwright.request().newContext(new APIRequest.NewContextOptions().setTimeout(1));
|
||||
server.setRoute("/empty.html", exchange -> {});
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> request.get(server.EMPTY_PAGE));
|
||||
assertTrue(e.getMessage().contains("Request timed out after 100ms"), e.getMessage());
|
||||
assertTrue(e.getMessage().contains("Request timed out after 1ms"), e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -381,97 +380,4 @@ public class TestGlobalFetch extends TestBase {
|
||||
}
|
||||
request.dispose();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotModifyRequestMethodInOptions() {
|
||||
APIRequestContext request = playwright.request().newContext();
|
||||
server.setRoute("/empty.html", exchange -> {
|
||||
exchange.getResponseHeaders().set("Content-type", "text/plain");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write(exchange.getRequestMethod());
|
||||
}
|
||||
});
|
||||
RequestOptions options = RequestOptions.create();
|
||||
options.setTimeout(10000);
|
||||
{
|
||||
APIResponse response = request.fetch(server.EMPTY_PAGE, options);
|
||||
assertTrue(response.ok());
|
||||
assertEquals("GET", response.text());
|
||||
}
|
||||
{
|
||||
APIResponse response = request.delete(server.EMPTY_PAGE, options);
|
||||
assertTrue(response.ok());
|
||||
assertEquals("DELETE", response.text());
|
||||
}
|
||||
{
|
||||
APIResponse response = request.put(server.EMPTY_PAGE, options);
|
||||
assertTrue(response.ok());
|
||||
assertEquals("PUT", response.text());
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class TestLocatorAssertions extends TestBase {
|
||||
assertThat(locator).not().hasText(new String[] {}, new LocatorAssertions.HasTextOptions().setTimeout(1000));
|
||||
});
|
||||
assertEquals("[]", e.getExpected().getStringRepresentation());
|
||||
assertEquals("[]", e.getActual().getStringRepresentation());
|
||||
assertEquals("null", e.getActual().getStringRepresentation());
|
||||
assertTrue(e.getMessage().contains("Locator expected not to have text"), e.getMessage());
|
||||
}
|
||||
|
||||
@@ -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>");
|
||||
@@ -681,15 +673,6 @@ public class TestLocatorAssertions extends TestBase {
|
||||
assertThat(locator).isChecked(new LocatorAssertions.IsCheckedOptions().setChecked(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isCheckedFalseFail() {
|
||||
page.setContent("<input checked type=checkbox></input>");
|
||||
Locator locator = page.locator("input");
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(locator).isChecked(new LocatorAssertions.IsCheckedOptions().setChecked(false).setTimeout(1000)));
|
||||
assertTrue(error.getMessage().contains("Locator expected to be unchecked"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isDisabledPass() {
|
||||
page.setContent("<button disabled>Text</button>");
|
||||
@@ -740,15 +723,6 @@ public class TestLocatorAssertions extends TestBase {
|
||||
assertTrue(e.getMessage().contains("Locator expected to be editable"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isEditableFalseFail() {
|
||||
page.setContent("<input></input>");
|
||||
Locator locator = page.locator("input");
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(locator).isEditable(new LocatorAssertions.IsEditableOptions().setEditable(false).setTimeout(1000)));
|
||||
assertTrue(error.getMessage().contains("Locator expected to be readonly"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void notIsEditableFail() {
|
||||
page.setContent("<input></input>");
|
||||
@@ -865,15 +839,6 @@ public class TestLocatorAssertions extends TestBase {
|
||||
assertThat(locator).isEnabled(new LocatorAssertions.IsEnabledOptions().setEnabled(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isEnabledFalseFail() {
|
||||
page.setContent("<button>Text</button>");
|
||||
Locator locator = page.locator("button");
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(locator).isEnabled(new LocatorAssertions.IsEnabledOptions().setEnabled(false).setTimeout(1000)));
|
||||
assertTrue(error.getMessage().contains("Locator expected to be disabled"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isEnabledEventually() {
|
||||
page.setContent("<button disabled>Text</button>");
|
||||
@@ -984,15 +949,6 @@ public class TestLocatorAssertions extends TestBase {
|
||||
assertTrue(e.getMessage().contains("Locator expected to be visible"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isVisibleFalseFail() {
|
||||
page.setContent("<input></input>");
|
||||
Locator locator = page.locator("input");
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(locator).isVisible(new LocatorAssertions.IsVisibleOptions().setVisible(false).setTimeout(1000)));
|
||||
assertTrue(error.getMessage().contains("Locator expected to be hidden"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void notIsVisibleFail() {
|
||||
page.setContent("<input></input>");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user