Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 550313d2fd | |||
| bb0f48ee40 | |||
| ee18e1a499 | |||
| 9cf4bf2263 | |||
| 36350f3c5c | |||
| f3476c68ff | |||
| 8fd8f1c831 | |||
| 7d2066693b | |||
| 6b01b878cb | |||
| 2e32eb704f | |||
| b81b144680 | |||
| 256e41a505 | |||
| 3054364101 | |||
| 40b8802874 | |||
| 49f53fceaf | |||
| 291c12a54c | |||
| 2b3413fad4 | |||
| 3eab530e95 | |||
| 7d35be4f89 | |||
| 800c2e9c71 | |||
| edf8174581 | |||
| 8ae67204eb | |||
| 5f2540e556 | |||
| 776e3f26ef | |||
| 46f4ac1f33 | |||
| 73d22552e6 | |||
| 650419c952 | |||
| 1e8adde480 | |||
| a9e1242aef | |||
| a222edee5a | |||
| 7a12897be4 | |||
| 7fa8081032 | |||
| 212bf981f7 | |||
| d9ac70c66b | |||
| 4279a4ef3e | |||
| 141afb1f09 | |||
| 2eaae58659 | |||
| e4828d00b6 | |||
| a08ab2dcae | |||
| 626050d988 | |||
| 4cc3fa3012 | |||
| 226d075355 | |||
| 0a759e699e | |||
| f2a17b6255 | |||
| 202bc80d76 | |||
| 731d8e8dc2 | |||
| 75062c4024 | |||
| c9ea56a640 | |||
| e4c427aa75 | |||
| 0471c5e86c | |||
| 5636edf69a | |||
| abfe50ce59 | |||
| d72364627b | |||
| fe51fb4cf6 | |||
| 764cc8cc8a | |||
| 7b8efadc57 | |||
| a654a4234e | |||
| 102d337b4a | |||
| f5f9b8a12d | |||
| 2f264eab76 | |||
| 5c17cc49ed | |||
| 8652942482 | |||
| 2829a37d58 | |||
| 90aa4579c4 | |||
| 1a8f5f7746 | |||
| a917f2ef5c | |||
| 452effbe3f | |||
| f497bcc27d | |||
| 240f8d0873 | |||
| e7653ddde7 | |||
| a135675580 | |||
| 4b9a436d57 | |||
| f15147ba33 | |||
| 8cdfd183b8 | |||
| c37b13eafb | |||
| 53879c8405 |
@@ -47,7 +47,7 @@ extends:
|
||||
GPG_PRIVATE_KEY_BASE64: $(GPG_PRIVATE_KEY_BASE64) # secret variable has to be mapped to an env variable
|
||||
displayName: "Import gpg key"
|
||||
|
||||
- bash: ./scripts/download_driver_for_all_platforms.sh
|
||||
- bash: ./scripts/download_driver.sh
|
||||
displayName: 'Download driver'
|
||||
|
||||
- bash: mvn -B deploy -D skipTests --no-transfer-progress --activate-profiles release -D gpg.passphrase=$GPG_PASSPHRASE -DaltDeploymentRepository=snapshot-repo::default::file:$(pwd)/local-build
|
||||
@@ -55,27 +55,23 @@ extends:
|
||||
env:
|
||||
GPG_PASSPHRASE: $(GPG_PASSPHRASE) # secret variable has to be mapped to an env variable
|
||||
|
||||
- bash: |
|
||||
for file in $(find snapshots -type f); do
|
||||
echo "processing: $file"
|
||||
if [[ $file =~ \.(md5|sha1|sha256)$ ]]; then
|
||||
continue
|
||||
fi
|
||||
sha256sum "$file" | cut -f1 -d \ > "$file.sha256"
|
||||
done
|
||||
displayName: 'Create .sha256 files'
|
||||
|
||||
- task: EsrpRelease@4
|
||||
- task: EsrpRelease@7
|
||||
inputs:
|
||||
ConnectedServiceName: 'Playwright-ESRP'
|
||||
Intent: 'PackageDistribution'
|
||||
ContentType: 'Maven'
|
||||
ContentSource: 'Folder'
|
||||
FolderLocation: './local-build'
|
||||
WaitForReleaseCompletion: true
|
||||
Owners: 'yurys@microsoft.com'
|
||||
Approvers: 'maxschmitt@microsoft.com'
|
||||
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
|
||||
MainPublisher: 'Playwright'
|
||||
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
|
||||
connectedservicename: 'Playwright-ESRP-Azure'
|
||||
keyvaultname: 'pw-publishing-secrets'
|
||||
authcertname: 'ESRP-Release-Auth'
|
||||
signcertname: 'ESRP-Release-Sign'
|
||||
clientid: '13434a40-7de4-4c23-81a3-d843dc81c2c5'
|
||||
intent: 'PackageDistribution'
|
||||
contenttype: 'Maven'
|
||||
# Keeping it commented out as a workaround for:
|
||||
# https://portal.microsofticm.com/imp/v3/incidents/incident/499972482/summary
|
||||
# contentsource: 'folder'
|
||||
folderlocation: './local-build'
|
||||
waitforreleasecompletion: true
|
||||
owners: 'yurys@microsoft.com'
|
||||
approvers: 'maxschmitt@microsoft.com'
|
||||
serviceendpointurl: 'https://api.esrp.microsoft.com'
|
||||
mainpublisher: 'Playwright'
|
||||
domaintenantid: '72f988bf-86f1-41af-91ab-2d7cd011db47'
|
||||
displayName: 'ESRP Release to Maven'
|
||||
|
||||
+10
-1
@@ -3,8 +3,17 @@ updates:
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/" # Location of the pom.xml file
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
interval: "monthly"
|
||||
open-pull-requests-limit: 10
|
||||
groups:
|
||||
# Create a group of dependencies to be updated together in one pull request
|
||||
all:
|
||||
applies-to: version-updates
|
||||
patterns:
|
||||
- "*"
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
allow:
|
||||
- dependency-type: "direct" # Optional: Only update direct dependencies
|
||||
- dependency-type: "indirect" # Optional: Only update indirect (transitive) dependencies
|
||||
|
||||
@@ -3,29 +3,28 @@ on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
is_release:
|
||||
required: true
|
||||
type: boolean
|
||||
description: "Is this a release image?"
|
||||
jobs:
|
||||
publish-canary-docker:
|
||||
name: publish to DockerHub
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
id-token: write # This is required for OIDC login (azure/login) to succeed
|
||||
contents: read # This is required for actions/checkout to succeed
|
||||
environment: Docker
|
||||
if: github.repository == 'microsoft/playwright-java'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: azure/docker-login@v1
|
||||
- name: Azure login
|
||||
uses: azure/login@v2
|
||||
with:
|
||||
login-server: playwright.azurecr.io
|
||||
username: playwright
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
client-id: ${{ secrets.AZURE_DOCKER_CLIENT_ID }}
|
||||
tenant-id: ${{ secrets.AZURE_DOCKER_TENANT_ID }}
|
||||
subscription-id: ${{ secrets.AZURE_DOCKER_SUBSCRIPTION_ID }}
|
||||
- name: Login to ACR via OIDC
|
||||
run: az acr login --name playwright
|
||||
- name: Set up Docker QEMU for arm64 docker builds
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: arm64
|
||||
- uses: actions/checkout@v4
|
||||
- run: ./utils/docker/publish_docker.sh stable
|
||||
if: (github.event_name != 'workflow_dispatch' && !github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true')
|
||||
- run: ./utils/docker/publish_docker.sh canary
|
||||
if: (github.event_name != 'workflow_dispatch' && github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release != 'true')
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
java-version: 8
|
||||
- name: Download drivers
|
||||
shell: bash
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
run: scripts/download_driver.sh
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Run tests
|
||||
@@ -75,16 +75,20 @@ jobs:
|
||||
java-version: 8
|
||||
- name: Download drivers
|
||||
shell: bash
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
run: scripts/download_driver.sh
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Install MS Edge
|
||||
if: matrix.browser-channel == 'msedge' && matrix.os == 'macos-latest'
|
||||
shell: bash
|
||||
run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install msedge" -f playwright/pom.xml
|
||||
- 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
|
||||
env:
|
||||
BROWSER: chromium
|
||||
BROWSER_CHANNEL: ${{ matrix.browser-channel }}
|
||||
|
||||
Java_17:
|
||||
Java_21:
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -94,14 +98,14 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: microsoft/playwright-github-action@v1
|
||||
- name: Set up JDK 17
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: adopt
|
||||
java-version: 17
|
||||
java-version: 21
|
||||
- name: Download drivers
|
||||
shell: bash
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
run: scripts/download_driver.sh
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Run tests
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-m2
|
||||
- name: Download drivers
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
run: scripts/download_driver.sh
|
||||
- name: Intall Playwright
|
||||
run: mvn install -D skipTests --no-transfer-progress
|
||||
- name: Test CLI
|
||||
|
||||
@@ -11,7 +11,7 @@ on:
|
||||
paths:
|
||||
- .github/workflows/test_docker.yml
|
||||
- '**/Dockerfile*'
|
||||
- scripts/CLI_VERSION
|
||||
- scripts/DRIVER_VERSION
|
||||
- '**/pom.xml'
|
||||
branches:
|
||||
- main
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
flavor: [focal, jammy]
|
||||
flavor: [focal, jammy, noble]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build Docker image
|
||||
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: microsoft/playwright-github-action@v1
|
||||
- name: Download drivers
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
run: scripts/download_driver.sh
|
||||
- name: Regenerate APIs
|
||||
run: scripts/generate_api.sh
|
||||
- name: Update browser versions in README
|
||||
|
||||
+6
-14
@@ -20,14 +20,12 @@ git clone https://github.com/microsoft/playwright-java
|
||||
cd playwright-java
|
||||
```
|
||||
|
||||
2. Run the following script to download playwright-cli binaries for all platforms into `driver-bundle/src/main/resources/driver/` directory (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run).
|
||||
2. Run the following script to download Playwright driver for all platforms into `driver-bundle/src/main/resources/driver/` directory (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run).
|
||||
|
||||
```bash
|
||||
scripts/download_driver_for_all_platforms.sh
|
||||
scripts/download_driver.sh
|
||||
```
|
||||
|
||||
Names of published driver archives can be found at https://github.com/microsoft/playwright-cli/actions
|
||||
|
||||
### Building and running the tests with Maven
|
||||
|
||||
```bash
|
||||
@@ -41,25 +39,19 @@ BROWSER=chromium mvn test --projects=playwright -Dtest=TestPageNetworkSizes
|
||||
|
||||
### Generating API
|
||||
|
||||
Public Java API is generated from api.json which is produced by `playwright-cli print-api-json`. To regenerate
|
||||
Java interfaces for the current driver run the following commands:
|
||||
Public Java API is generated from api.json which is produced by `print-api-json` command of playwright CLI. To regenerate Java interfaces for the current driver run the following commands:
|
||||
|
||||
```bash
|
||||
./scripts/download_driver_for_all_platforms.sh
|
||||
./scripts/download_driver.sh
|
||||
./scripts/generate_api.sh
|
||||
```
|
||||
|
||||
#### Updating driver version
|
||||
|
||||
Driver version is read from [scripts/CLI_VERSION](https://github.com/microsoft/playwright-java/blob/main/scripts/CLI_VERSION) and can be found in the upstream [GHA build](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) logs. To update the driver to a particular version run the following commands:
|
||||
Versions of published driver archives can be found in [publish canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) and [publish release](https://github.com/microsoft/playwright/actions/workflows/publish_release_driver.yml) actions logs. To update the driver to a particular version run the following command:
|
||||
|
||||
```bash
|
||||
cat > scripts/CLI_VERSION
|
||||
<paste new version>
|
||||
^D
|
||||
./scripts/download_driver_for_all_platforms.sh -f
|
||||
./scripts/generate_api.sh
|
||||
./scripts/update_readme.sh
|
||||
scripts/roll_driver.sh [version]
|
||||
```
|
||||
|
||||
### Code Style
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[](https://javadoc.io/doc/com.microsoft.playwright/playwright)
|
||||
[](https://search.maven.org/search?q=com.microsoft.playwright)
|
||||
[](https://oss.sonatype.org/content/repositories/snapshots/com/microsoft/playwright/playwright/)
|
||||
[](https://aka.ms/playwright-slack)
|
||||
[](https://aka.ms/playwright/discord)
|
||||
|
||||
#### [Website](https://playwright.dev/java/) | [API reference](https://www.javadoc.io/doc/com.microsoft.playwright/playwright/latest/index.html)
|
||||
|
||||
@@ -11,9 +11,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->123.0.6312.4<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->123.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->129.0.6668.29<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->18.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->130.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.
|
||||
|
||||
@@ -122,7 +122,7 @@ public class MobileAndGeolocation {
|
||||
.setPermissions(asList("geolocation")));
|
||||
Page page = context.newPage();
|
||||
page.navigate("https://www.openstreetmap.org/");
|
||||
page.click("a[data-original-title=\"Show My Location\"]");
|
||||
page.click("a[data-bs-original-title=\"Show My Location\"]");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("colosseum-pixel2.png")));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -2,11 +2,10 @@
|
||||
|
||||
* make sure to have at least Java 8 and Maven 3.6.3
|
||||
* clone playwright for java: http://github.com/microsoft/playwright-java
|
||||
* set new driver version in `scripts/CLI_VERSION`
|
||||
* regenerate API: `./scripts/download_driver_for_all_platforms.sh -f && ./scripts/generate_api.sh && ./scripts/update_readme.sh`
|
||||
* `./scripts/roll_driver.sh 1.47.0-beta-1726138322000`
|
||||
* commit & send PR with the roll
|
||||
|
||||
### Finding driver version
|
||||
## 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">
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
# Support
|
||||
|
||||
## How to file issues and get help
|
||||
|
||||
This project uses GitHub issues to track bugs and feature requests. Please search the [existing issues][gh-issues] before filing new ones to avoid duplicates. For new issues, file your bug or feature request as a new issue using corresponding template.
|
||||
|
||||
For help and questions about using this project, please see the [docs site for Playwright for Java][docs].
|
||||
|
||||
Join our community [Discord Server][discord-server] to connect with other developers using Playwright and ask questions in our 'help-playwright' forum.
|
||||
|
||||
## Microsoft Support Policy
|
||||
|
||||
Support for Playwright for Java is limited to the resources listed above.
|
||||
|
||||
[gh-issues]: https://github.com/microsoft/playwright-java/issues/
|
||||
[docs]: https://playwright.dev/java/
|
||||
[discord-server]: https://aka.ms/playwright/discord
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.42.0</version>
|
||||
<version>1.47.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
|
||||
public class DriverJar extends Driver {
|
||||
private static final String PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD";
|
||||
private static final String SELENIUM_REMOTE_URL = "SELENIUM_REMOTE_URL";
|
||||
static final String PLAYWRIGHT_NODEJS_PATH = "PLAYWRIGHT_NODEJS_PATH";
|
||||
private final Path driverTempDir;
|
||||
private Path preinstalledNodePath;
|
||||
|
||||
@@ -64,7 +63,7 @@ public class DriverJar extends Driver {
|
||||
env.put(PLAYWRIGHT_NODEJS_PATH, preinstalledNodePath.toString());
|
||||
}
|
||||
extractDriverToTempDir();
|
||||
logMessage("extracted driver from jar to " + driverPath());
|
||||
logMessage("extracted driver from jar to " + driverDir());
|
||||
if (installBrowsers)
|
||||
installBrowsers(env);
|
||||
}
|
||||
@@ -75,14 +74,14 @@ public class DriverJar extends Driver {
|
||||
skip = System.getenv(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD);
|
||||
}
|
||||
if (skip != null && !"0".equals(skip) && !"false".equals(skip)) {
|
||||
System.out.println("Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set");
|
||||
logMessage("Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set");
|
||||
return;
|
||||
}
|
||||
if (env.get(SELENIUM_REMOTE_URL) != null || System.getenv(SELENIUM_REMOTE_URL) != null) {
|
||||
logMessage("Skipping browsers download because `SELENIUM_REMOTE_URL` env variable is set");
|
||||
return;
|
||||
}
|
||||
Path driver = driverPath();
|
||||
Path driver = driverDir();
|
||||
if (!Files.exists(driver)) {
|
||||
throw new RuntimeException("Failed to find driver: " + driver);
|
||||
}
|
||||
@@ -204,7 +203,7 @@ public class DriverJar extends Driver {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Path driverDir() {
|
||||
public Path driverDir() {
|
||||
return driverTempDir;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -32,7 +32,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.microsoft.playwright.impl.driver.jar.DriverJar.PLAYWRIGHT_NODEJS_PATH;
|
||||
import static com.microsoft.playwright.impl.driver.Driver.PLAYWRIGHT_NODEJS_PATH;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TestInstall {
|
||||
@Test
|
||||
void playwrightCliInstalled() throws Exception {
|
||||
Driver driver = Driver.createAndInstall(Collections.emptyMap(), false);
|
||||
assertTrue(Files.exists(driver.driverPath()));
|
||||
assertTrue(Files.exists(driver.driverDir()));
|
||||
|
||||
ProcessBuilder pb = driver.createProcessBuilder();
|
||||
pb.command().add("install");
|
||||
@@ -98,7 +98,7 @@ public class TestInstall {
|
||||
void playwrightDriverInAlternativeTmpdir(@TempDir Path tmpdir) throws Exception {
|
||||
System.setProperty("playwright.driver.tmpdir", tmpdir.toString());
|
||||
DriverJar driver = new DriverJar();
|
||||
assertTrue(driver.driverPath().startsWith(tmpdir), "Driver path: " + driver.driverPath() + " tmp: " + tmpdir);
|
||||
assertTrue(driver.driverDir().startsWith(tmpdir), "Driver path: " + driver.driverDir() + " tmp: " + tmpdir);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,7 +135,7 @@ public class TestInstall {
|
||||
private static String extractNodeJsToTemp() throws URISyntaxException, IOException {
|
||||
DriverJar auxDriver = new DriverJar();
|
||||
auxDriver.extractDriverToTempDir();
|
||||
String nodePath = auxDriver.driverPath().getParent().resolve(isWindows() ? "node.exe" : "node").toString();
|
||||
String nodePath = auxDriver.driverDir().resolve(isWindows() ? "node.exe" : "node").toString();
|
||||
return nodePath;
|
||||
}
|
||||
|
||||
@@ -145,9 +145,9 @@ public class TestInstall {
|
||||
}
|
||||
|
||||
private static void canSpecifyPreinstalledNodeJsShared(Driver driver, Path tmpDir) throws IOException, URISyntaxException, InterruptedException {
|
||||
Path builtinNode = driver.driverPath().getParent().resolve("node");
|
||||
Path builtinNode = driver.driverDir().resolve("node");
|
||||
assertFalse(Files.exists(builtinNode), builtinNode.toString());
|
||||
Path builtinNodeExe = driver.driverPath().getParent().resolve("node.exe");
|
||||
Path builtinNodeExe = driver.driverDir().resolve("node.exe");
|
||||
assertFalse(Files.exists(builtinNodeExe), builtinNodeExe.toString());
|
||||
|
||||
ProcessBuilder pb = driver.createProcessBuilder();
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.42.0</version>
|
||||
<version>1.47.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver</artifactId>
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.microsoft.playwright.impl.driver;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -30,7 +29,8 @@ import static com.microsoft.playwright.impl.driver.DriverLogging.logWithTimestam
|
||||
* loaded from the driver-bundle module if that module is in the classpath.
|
||||
*/
|
||||
public abstract class Driver {
|
||||
protected final Map<String, String> env = new LinkedHashMap<>();
|
||||
protected final Map<String, String> env = new LinkedHashMap<>(System.getenv());
|
||||
public static final String PLAYWRIGHT_NODEJS_PATH = "PLAYWRIGHT_NODEJS_PATH";
|
||||
|
||||
private static Driver instance;
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class Driver {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Path driverDir() {
|
||||
public Path driverDir() {
|
||||
return driverDir;
|
||||
}
|
||||
}
|
||||
@@ -65,14 +65,14 @@ public abstract class Driver {
|
||||
}
|
||||
protected abstract void initialize(Boolean installBrowsers) throws Exception;
|
||||
|
||||
public Path driverPath() {
|
||||
String cliFileName = System.getProperty("os.name").toLowerCase().contains("windows") ?
|
||||
"playwright.cmd" : "playwright.sh";
|
||||
return driverDir().resolve(cliFileName);
|
||||
}
|
||||
|
||||
public ProcessBuilder createProcessBuilder() {
|
||||
ProcessBuilder pb = new ProcessBuilder(driverPath().toString());
|
||||
String nodePath = env.get("PLAYWRIGHT_NODEJS_PATH");
|
||||
if (nodePath == null) {
|
||||
String node = System.getProperty("os.name").toLowerCase().contains("windows") ? "node.exe" : "node";
|
||||
nodePath = driverDir().resolve(node).toAbsolutePath().toString();
|
||||
}
|
||||
ProcessBuilder pb = new ProcessBuilder(nodePath);
|
||||
pb.command().add(driverDir().resolve("package").resolve("cli.js").toAbsolutePath().toString());
|
||||
pb.environment().putAll(env);
|
||||
pb.environment().put("PW_LANG_NAME", "java");
|
||||
pb.environment().put("PW_LANG_NAME_VERSION", getMajorJavaVersion());
|
||||
@@ -118,7 +118,7 @@ public abstract class Driver {
|
||||
return (Driver) jarDriver.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
protected abstract Path driverDir();
|
||||
public abstract Path driverDir();
|
||||
|
||||
protected static void logMessage(String message) {
|
||||
// This matches log format produced by the server.
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>1.42.0</version>
|
||||
<version>1.47.0</version>
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.42.0</version>
|
||||
<version>1.47.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>playwright</artifactId>
|
||||
@@ -26,7 +26,7 @@
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration combine.self="append">
|
||||
<subpackages>com.microsoft.playwright</subpackages>
|
||||
<excludePackageNames>com.microsoft.playwright.impl,com.microsoft.playwright.junit.impl</excludePackageNames>
|
||||
<excludePackageNames>com.microsoft.playwright.impl</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@@ -23,14 +23,14 @@ import java.util.*;
|
||||
/**
|
||||
* Exposes API that can be used for the Web API testing. This class is used for creating {@code APIRequestContext} instance
|
||||
* which in turn can be used for sending web requests. An instance of this class can be obtained via {@link
|
||||
* Playwright#request Playwright.request()}. For more information see {@code APIRequestContext}.
|
||||
* com.microsoft.playwright.Playwright#request Playwright.request()}. For more information see {@code APIRequestContext}.
|
||||
*/
|
||||
public interface APIRequest {
|
||||
class NewContextOptions {
|
||||
/**
|
||||
* Methods like {@link APIRequestContext#get APIRequestContext.get()} take the base URL into consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* Methods like {@link com.microsoft.playwright.APIRequestContext#get APIRequestContext.get()} take the base URL into
|
||||
* consideration by using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a>
|
||||
* constructor for building the corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and sending request to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -41,6 +41,22 @@ public interface APIRequest {
|
||||
* </ul>
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public List<ClientCertificate> clientCertificates;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
@@ -60,16 +76,17 @@ public interface APIRequest {
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()}. Either a path to the file with saved storage, or the value returned by one of {@link
|
||||
* BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()} or {@link
|
||||
* com.microsoft.playwright.APIRequestContext#storageState APIRequestContext.storageState()}. Either a path to the file
|
||||
* with saved storage, or the value returned by one of {@link com.microsoft.playwright.BrowserContext#storageState
|
||||
* BrowserContext.storageState()} or {@link com.microsoft.playwright.APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()} methods.
|
||||
*/
|
||||
public String storageState;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
*/
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
@@ -83,9 +100,9 @@ public interface APIRequest {
|
||||
public String userAgent;
|
||||
|
||||
/**
|
||||
* Methods like {@link APIRequestContext#get APIRequestContext.get()} take the base URL into consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* Methods like {@link com.microsoft.playwright.APIRequestContext#get APIRequestContext.get()} take the base URL into
|
||||
* consideration by using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a>
|
||||
* constructor for building the corresponding URL. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and sending request to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -99,6 +116,25 @@ public interface APIRequest {
|
||||
this.baseURL = baseURL;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public NewContextOptions setClientCertificates(List<ClientCertificate> clientCertificates) {
|
||||
this.clientCertificates = clientCertificates;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
@@ -143,9 +179,10 @@ public interface APIRequest {
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()}. Either a path to the file with saved storage, or the value returned by one of {@link
|
||||
* BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()} or {@link
|
||||
* com.microsoft.playwright.APIRequestContext#storageState APIRequestContext.storageState()}. Either a path to the file
|
||||
* with saved storage, or the value returned by one of {@link com.microsoft.playwright.BrowserContext#storageState
|
||||
* BrowserContext.storageState()} or {@link com.microsoft.playwright.APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()} methods.
|
||||
*/
|
||||
public NewContextOptions setStorageState(String storageState) {
|
||||
@@ -154,8 +191,8 @@ public interface APIRequest {
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
*/
|
||||
public NewContextOptions setStorageStatePath(Path storageStatePath) {
|
||||
this.storageStatePath = storageStatePath;
|
||||
|
||||
@@ -24,23 +24,39 @@ import java.nio.file.Path;
|
||||
* environment or the service to your e2e test.
|
||||
*
|
||||
* <p> Each Playwright browser context has associated with it {@code APIRequestContext} instance which shares cookie storage
|
||||
* with the browser context and can be accessed via {@link BrowserContext#request BrowserContext.request()} or {@link
|
||||
* Page#request Page.request()}. It is also possible to create a new APIRequestContext instance manually by calling {@link
|
||||
* APIRequest#newContext APIRequest.newContext()}.
|
||||
* with the browser context and can be accessed via {@link com.microsoft.playwright.BrowserContext#request
|
||||
* BrowserContext.request()} or {@link com.microsoft.playwright.Page#request Page.request()}. It is also possible to create
|
||||
* a new APIRequestContext instance manually by calling {@link com.microsoft.playwright.APIRequest#newContext
|
||||
* APIRequest.newContext()}.
|
||||
*
|
||||
* <p> **Cookie management**
|
||||
* <p> <strong>Cookie management</strong>
|
||||
*
|
||||
* <p> {@code APIRequestContext} returned by {@link BrowserContext#request BrowserContext.request()} and {@link Page#request
|
||||
* Page.request()} shares cookie storage with the corresponding {@code BrowserContext}. Each API request will have {@code
|
||||
* Cookie} header populated with the values from the browser context. If the API response contains {@code Set-Cookie}
|
||||
* header it will automatically update {@code BrowserContext} cookies and requests made from the page will pick them up.
|
||||
* This means that if you log in using this API, your e2e test will be logged in and vice versa.
|
||||
* <p> {@code APIRequestContext} returned by {@link com.microsoft.playwright.BrowserContext#request BrowserContext.request()}
|
||||
* and {@link com.microsoft.playwright.Page#request Page.request()} shares cookie storage with the corresponding {@code
|
||||
* BrowserContext}. Each API request will have {@code Cookie} header populated with the values from the browser context. If
|
||||
* the API response contains {@code Set-Cookie} header it will automatically update {@code BrowserContext} cookies and
|
||||
* requests made from the page will pick them up. This means that if you log in using this API, your e2e test will be
|
||||
* logged in and vice versa.
|
||||
*
|
||||
* <p> If you want API requests to not interfere with the browser cookies you should create a new {@code APIRequestContext} by
|
||||
* calling {@link APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext} object will have its own
|
||||
* isolated cookie storage.
|
||||
* calling {@link com.microsoft.playwright.APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext}
|
||||
* object will have its own isolated cookie storage.
|
||||
*/
|
||||
public interface APIRequestContext {
|
||||
class DisposeOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context disposal.
|
||||
*/
|
||||
public String reason;
|
||||
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context disposal.
|
||||
*/
|
||||
public DisposeOptions setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class StorageStateOptions {
|
||||
/**
|
||||
* The file path to save the storage state to. If {@code path} is a relative path, then it is resolved relative to current
|
||||
@@ -79,19 +95,32 @@ 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.
|
||||
* All responses returned by {@link com.microsoft.playwright.APIRequestContext#get APIRequestContext.get()} and similar
|
||||
* methods are stored in the memory, so that you can later call {@link com.microsoft.playwright.APIResponse#body
|
||||
* APIResponse.body()}.This method discards all its resources, calling any method on disposed {@code APIRequestContext}
|
||||
* will throw an exception.
|
||||
*
|
||||
* @since v1.16
|
||||
*/
|
||||
void dispose();
|
||||
default void dispose() {
|
||||
dispose(null);
|
||||
}
|
||||
/**
|
||||
* All responses returned by {@link com.microsoft.playwright.APIRequestContext#get APIRequestContext.get()} and similar
|
||||
* methods are stored in the memory, so that you can later call {@link com.microsoft.playwright.APIResponse#body
|
||||
* APIResponse.body()}.This method discards all its resources, calling any method on disposed {@code APIRequestContext}
|
||||
* will throw an exception.
|
||||
*
|
||||
* @since v1.16
|
||||
*/
|
||||
void dispose(DisposeOptions options);
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects. JSON objects can be passed directly
|
||||
* to the request.
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -99,8 +128,9 @@ public interface APIRequestContext {
|
||||
* request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
|
||||
* encoding. You can achieve that with Playwright API like this:
|
||||
* <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code
|
||||
* multipart/form-data} encoding. Use {@code FormData} to construct request body and pass it to the request as {@code
|
||||
* multipart} parameter:
|
||||
* <pre>{@code
|
||||
* // Pass file path to the form data constructor:
|
||||
* Path file = Paths.get("team.csv");
|
||||
@@ -111,7 +141,7 @@ public interface APIRequestContext {
|
||||
* // Or you can pass the file content directly as FilePayload object:
|
||||
* FilePayload filePayload = new FilePayload("f.js", "text/javascript",
|
||||
* "console.log(2022);".getBytes(StandardCharsets.UTF_8));
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadScript",
|
||||
* RequestOptions.create().setMethod("post").setMultipart(
|
||||
* FormData.create().set("fileField", filePayload)));
|
||||
* }</pre>
|
||||
@@ -124,10 +154,11 @@ public interface APIRequestContext {
|
||||
}
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects. JSON objects can be passed directly
|
||||
* to the request.
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -135,8 +166,9 @@ public interface APIRequestContext {
|
||||
* request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
|
||||
* encoding. You can achieve that with Playwright API like this:
|
||||
* <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code
|
||||
* multipart/form-data} encoding. Use {@code FormData} to construct request body and pass it to the request as {@code
|
||||
* multipart} parameter:
|
||||
* <pre>{@code
|
||||
* // Pass file path to the form data constructor:
|
||||
* Path file = Paths.get("team.csv");
|
||||
@@ -147,7 +179,7 @@ public interface APIRequestContext {
|
||||
* // Or you can pass the file content directly as FilePayload object:
|
||||
* FilePayload filePayload = new FilePayload("f.js", "text/javascript",
|
||||
* "console.log(2022);".getBytes(StandardCharsets.UTF_8));
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadScript",
|
||||
* RequestOptions.create().setMethod("post").setMultipart(
|
||||
* FormData.create().set("fileField", filePayload)));
|
||||
* }</pre>
|
||||
@@ -159,10 +191,11 @@ public interface APIRequestContext {
|
||||
APIResponse fetch(String urlOrRequest, RequestOptions params);
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects. JSON objects can be passed directly
|
||||
* to the request.
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -170,8 +203,9 @@ public interface APIRequestContext {
|
||||
* request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
|
||||
* encoding. You can achieve that with Playwright API like this:
|
||||
* <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code
|
||||
* multipart/form-data} encoding. Use {@code FormData} to construct request body and pass it to the request as {@code
|
||||
* multipart} parameter:
|
||||
* <pre>{@code
|
||||
* // Pass file path to the form data constructor:
|
||||
* Path file = Paths.get("team.csv");
|
||||
@@ -182,7 +216,7 @@ public interface APIRequestContext {
|
||||
* // Or you can pass the file content directly as FilePayload object:
|
||||
* FilePayload filePayload = new FilePayload("f.js", "text/javascript",
|
||||
* "console.log(2022);".getBytes(StandardCharsets.UTF_8));
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadScript",
|
||||
* RequestOptions.create().setMethod("post").setMultipart(
|
||||
* FormData.create().set("fileField", filePayload)));
|
||||
* }</pre>
|
||||
@@ -195,10 +229,11 @@ public interface APIRequestContext {
|
||||
}
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects. JSON objects can be passed directly
|
||||
* to the request.
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -206,8 +241,9 @@ public interface APIRequestContext {
|
||||
* request.fetch("https://example.com/api/createBook", RequestOptions.create().setMethod("post").setData(data));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> The common way to send file(s) in the body of a request is to encode it as form fields with {@code multipart/form-data}
|
||||
* encoding. You can achieve that with Playwright API like this:
|
||||
* <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code
|
||||
* multipart/form-data} encoding. Use {@code FormData} to construct request body and pass it to the request as {@code
|
||||
* multipart} parameter:
|
||||
* <pre>{@code
|
||||
* // Pass file path to the form data constructor:
|
||||
* Path file = Paths.get("team.csv");
|
||||
@@ -218,7 +254,7 @@ public interface APIRequestContext {
|
||||
* // Or you can pass the file content directly as FilePayload object:
|
||||
* FilePayload filePayload = new FilePayload("f.js", "text/javascript",
|
||||
* "console.log(2022);".getBytes(StandardCharsets.UTF_8));
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadTeamList",
|
||||
* APIResponse response = request.fetch("https://example.com/api/uploadScript",
|
||||
* RequestOptions.create().setMethod("post").setMultipart(
|
||||
* FormData.create().set("fileField", filePayload)));
|
||||
* }</pre>
|
||||
@@ -233,7 +269,7 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Request parameters can be configured with {@code params} option, they will be serialized into the URL search parameters:
|
||||
* <pre>{@code
|
||||
@@ -253,7 +289,7 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Request parameters can be configured with {@code params} option, they will be serialized into the URL search parameters:
|
||||
* <pre>{@code
|
||||
@@ -314,7 +350,7 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
@@ -334,7 +370,8 @@ public interface APIRequestContext {
|
||||
* }</pre>
|
||||
*
|
||||
* <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code
|
||||
* multipart/form-data} encoding. You can achieve that with Playwright API like this:
|
||||
* multipart/form-data} encoding. Use {@code FormData} to construct request body and pass it to the request as {@code
|
||||
* multipart} parameter:
|
||||
* <pre>{@code
|
||||
* // Pass file path to the form data constructor:
|
||||
* Path file = Paths.get("team.csv");
|
||||
@@ -343,9 +380,9 @@ public interface APIRequestContext {
|
||||
* FormData.create().set("fileField", file)));
|
||||
*
|
||||
* // Or you can pass the file content directly as FilePayload object:
|
||||
* FilePayload filePayload = new FilePayload("f.js", "text/javascript",
|
||||
* FilePayload filePayload1 = new FilePayload("f1.js", "text/javascript",
|
||||
* "console.log(2022);".getBytes(StandardCharsets.UTF_8));
|
||||
* APIResponse response = request.post("https://example.com/api/uploadTeamList",
|
||||
* APIResponse response = request.post("https://example.com/api/uploadScript",
|
||||
* RequestOptions.create().setMultipart(
|
||||
* FormData.create().set("fileField", filePayload)));
|
||||
* }</pre>
|
||||
@@ -361,7 +398,7 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
@@ -381,7 +418,8 @@ public interface APIRequestContext {
|
||||
* }</pre>
|
||||
*
|
||||
* <p> The common way to send file(s) in the body of a request is to upload them as form fields with {@code
|
||||
* multipart/form-data} encoding. You can achieve that with Playwright API like this:
|
||||
* multipart/form-data} encoding. Use {@code FormData} to construct request body and pass it to the request as {@code
|
||||
* multipart} parameter:
|
||||
* <pre>{@code
|
||||
* // Pass file path to the form data constructor:
|
||||
* Path file = Paths.get("team.csv");
|
||||
@@ -390,9 +428,9 @@ public interface APIRequestContext {
|
||||
* FormData.create().set("fileField", file)));
|
||||
*
|
||||
* // Or you can pass the file content directly as FilePayload object:
|
||||
* FilePayload filePayload = new FilePayload("f.js", "text/javascript",
|
||||
* FilePayload filePayload1 = new FilePayload("f1.js", "text/javascript",
|
||||
* "console.log(2022);".getBytes(StandardCharsets.UTF_8));
|
||||
* APIResponse response = request.post("https://example.com/api/uploadTeamList",
|
||||
* APIResponse response = request.post("https://example.com/api/uploadScript",
|
||||
* RequestOptions.create().setMultipart(
|
||||
* FormData.create().set("fileField", filePayload)));
|
||||
* }</pre>
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.microsoft.playwright.options.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* {@code APIResponse} class represents responses returned by {@link APIRequestContext#get APIRequestContext.get()} and
|
||||
* similar methods.
|
||||
* {@code APIResponse} class represents responses returned by {@link com.microsoft.playwright.APIRequestContext#get
|
||||
* APIRequestContext.get()} and similar methods.
|
||||
*/
|
||||
public interface APIResponse {
|
||||
/**
|
||||
@@ -43,8 +43,8 @@ public interface APIResponse {
|
||||
*/
|
||||
Map<String, String> headers();
|
||||
/**
|
||||
* An array with all the request HTTP headers associated with this response. Header names are not lower-cased. Headers with
|
||||
* multiple entries, such as {@code Set-Cookie}, appear in the array multiple times.
|
||||
* An array with all the response HTTP headers associated with this response. Header names are not lower-cased. Headers
|
||||
* with multiple entries, such as {@code Set-Cookie}, appear in the array multiple times.
|
||||
*
|
||||
* @since v1.16
|
||||
*/
|
||||
|
||||
@@ -23,8 +23,8 @@ import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A Browser is created via {@link BrowserType#launch BrowserType.launch()}. An example of using a {@code Browser} to
|
||||
* create a {@code Page}:
|
||||
* A Browser is created via {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. An example of using a
|
||||
* {@code Browser} to create a {@code Page}:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
*
|
||||
@@ -47,7 +47,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
|
||||
* <ul>
|
||||
* <li> Browser application is closed or crashed.</li>
|
||||
* <li> The {@link Browser#close Browser.close()} method was called.</li>
|
||||
* <li> The {@link com.microsoft.playwright.Browser#close Browser.close()} method was called.</li>
|
||||
* </ul>
|
||||
*/
|
||||
void onDisconnected(Consumer<Browser> handler);
|
||||
@@ -76,10 +76,11 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* When using {@link Page#navigate Page.navigate()}, {@link Page#route Page.route()}, {@link Page#waitForURL
|
||||
* 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
|
||||
* When using {@link com.microsoft.playwright.Page#navigate Page.navigate()}, {@link com.microsoft.playwright.Page#route
|
||||
* Page.route()}, {@link com.microsoft.playwright.Page#waitForURL Page.waitForURL()}, {@link
|
||||
* com.microsoft.playwright.Page#waitForRequest Page.waitForRequest()}, or {@link
|
||||
* com.microsoft.playwright.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:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
@@ -95,10 +96,26 @@ public interface Browser extends AutoCloseable {
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public List<ClientCertificate> clientCertificates;
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code
|
||||
* "no-preference"}. See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "light"}.
|
||||
* "no-preference"}. See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing
|
||||
* {@code null} resets emulation to system defaults. Defaults to {@code "light"}.
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
@@ -112,8 +129,8 @@ public interface Browser extends AutoCloseable {
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* 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.
|
||||
* Defaults to {@code "none"}.
|
||||
* com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation
|
||||
* to system defaults. Defaults to {@code "none"}.
|
||||
*/
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
@@ -155,16 +172,13 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* A list of permissions to grant to all pages in this context. See {@link
|
||||
* com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} for more details. Defaults
|
||||
* to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
* 'http://per-context' } })}.
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
@@ -185,14 +199,14 @@ public interface Browser extends AutoCloseable {
|
||||
public Boolean recordHarOmitContent;
|
||||
/**
|
||||
* Enables <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> recording for all pages into the specified HAR
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link BrowserContext#close
|
||||
* BrowserContext.close()} for the HAR to be saved.
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public Path recordHarPath;
|
||||
public Object recordHarUrlFilter;
|
||||
/**
|
||||
* Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
|
||||
* to call {@link BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public Path recordVideoDir;
|
||||
/**
|
||||
@@ -203,8 +217,8 @@ public interface Browser extends AutoCloseable {
|
||||
public RecordVideoSize recordVideoSize;
|
||||
/**
|
||||
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system
|
||||
* defaults. Defaults to {@code "no-preference"}.
|
||||
* See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "no-preference"}.
|
||||
*/
|
||||
public Optional<ReducedMotion> reducedMotion;
|
||||
/**
|
||||
@@ -223,13 +237,13 @@ public interface Browser extends AutoCloseable {
|
||||
public ServiceWorkerPolicy serviceWorkers;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public String storageState;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
*/
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
@@ -267,10 +281,11 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When using {@link Page#navigate Page.navigate()}, {@link Page#route Page.route()}, {@link Page#waitForURL
|
||||
* 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
|
||||
* When using {@link com.microsoft.playwright.Page#navigate Page.navigate()}, {@link com.microsoft.playwright.Page#route
|
||||
* Page.route()}, {@link com.microsoft.playwright.Page#waitForURL Page.waitForURL()}, {@link
|
||||
* com.microsoft.playwright.Page#waitForRequest Page.waitForRequest()}, or {@link
|
||||
* com.microsoft.playwright.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:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
@@ -292,10 +307,29 @@ public interface Browser extends AutoCloseable {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public NewContextOptions setClientCertificates(List<ClientCertificate> clientCertificates) {
|
||||
this.clientCertificates = clientCertificates;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code
|
||||
* "no-preference"}. See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "light"}.
|
||||
* "no-preference"}. See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing
|
||||
* {@code null} resets emulation to system defaults. Defaults to {@code "light"}.
|
||||
*/
|
||||
public NewContextOptions setColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = Optional.ofNullable(colorScheme);
|
||||
@@ -318,8 +352,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
* Defaults to {@code "none"}.
|
||||
* com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation
|
||||
* to system defaults. Defaults to {@code "none"}.
|
||||
*/
|
||||
public NewContextOptions setForcedColors(ForcedColors forcedColors) {
|
||||
this.forcedColors = Optional.ofNullable(forcedColors);
|
||||
@@ -398,8 +432,9 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* A list of permissions to grant to all pages in this context. See {@link
|
||||
* com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} for more details. Defaults
|
||||
* to none.
|
||||
*/
|
||||
public NewContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
@@ -407,20 +442,12 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
* 'http://per-context' } })}.
|
||||
*/
|
||||
public NewContextOptions setProxy(String server) {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
* 'http://per-context' } })}.
|
||||
*/
|
||||
public NewContextOptions setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
@@ -453,8 +480,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Enables <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> recording for all pages into the specified HAR
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link BrowserContext#close
|
||||
* BrowserContext.close()} for the HAR to be saved.
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public NewContextOptions setRecordHarPath(Path recordHarPath) {
|
||||
this.recordHarPath = recordHarPath;
|
||||
@@ -470,7 +497,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
|
||||
* to call {@link BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public NewContextOptions setRecordVideoDir(Path recordVideoDir) {
|
||||
this.recordVideoDir = recordVideoDir;
|
||||
@@ -495,8 +522,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system
|
||||
* defaults. Defaults to {@code "no-preference"}.
|
||||
* See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "no-preference"}.
|
||||
*/
|
||||
public NewContextOptions setReducedMotion(ReducedMotion reducedMotion) {
|
||||
this.reducedMotion = Optional.ofNullable(reducedMotion);
|
||||
@@ -531,7 +558,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public NewContextOptions setStorageState(String storageState) {
|
||||
this.storageState = storageState;
|
||||
@@ -539,8 +566,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
*/
|
||||
public NewContextOptions setStorageStatePath(Path storageStatePath) {
|
||||
this.storageStatePath = storageStatePath;
|
||||
@@ -602,10 +629,11 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* When using {@link Page#navigate Page.navigate()}, {@link Page#route Page.route()}, {@link Page#waitForURL
|
||||
* 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
|
||||
* When using {@link com.microsoft.playwright.Page#navigate Page.navigate()}, {@link com.microsoft.playwright.Page#route
|
||||
* Page.route()}, {@link com.microsoft.playwright.Page#waitForURL Page.waitForURL()}, {@link
|
||||
* com.microsoft.playwright.Page#waitForRequest Page.waitForRequest()}, or {@link
|
||||
* com.microsoft.playwright.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:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
@@ -621,10 +649,26 @@ public interface Browser extends AutoCloseable {
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public List<ClientCertificate> clientCertificates;
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code
|
||||
* "no-preference"}. See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "light"}.
|
||||
* "no-preference"}. See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing
|
||||
* {@code null} resets emulation to system defaults. Defaults to {@code "light"}.
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
@@ -638,8 +682,8 @@ public interface Browser extends AutoCloseable {
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* 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.
|
||||
* Defaults to {@code "none"}.
|
||||
* com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation
|
||||
* to system defaults. Defaults to {@code "none"}.
|
||||
*/
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
@@ -681,16 +725,13 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* A list of permissions to grant to all pages in this context. See {@link
|
||||
* com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} for more details. Defaults
|
||||
* to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
* 'http://per-context' } })}.
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
@@ -711,14 +752,14 @@ public interface Browser extends AutoCloseable {
|
||||
public Boolean recordHarOmitContent;
|
||||
/**
|
||||
* Enables <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> recording for all pages into the specified HAR
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link BrowserContext#close
|
||||
* BrowserContext.close()} for the HAR to be saved.
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public Path recordHarPath;
|
||||
public Object recordHarUrlFilter;
|
||||
/**
|
||||
* Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
|
||||
* to call {@link BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public Path recordVideoDir;
|
||||
/**
|
||||
@@ -729,8 +770,8 @@ public interface Browser extends AutoCloseable {
|
||||
public RecordVideoSize recordVideoSize;
|
||||
/**
|
||||
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system
|
||||
* defaults. Defaults to {@code "no-preference"}.
|
||||
* See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "no-preference"}.
|
||||
*/
|
||||
public Optional<ReducedMotion> reducedMotion;
|
||||
/**
|
||||
@@ -749,13 +790,13 @@ public interface Browser extends AutoCloseable {
|
||||
public ServiceWorkerPolicy serviceWorkers;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public String storageState;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
*/
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
@@ -793,10 +834,11 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When using {@link Page#navigate Page.navigate()}, {@link Page#route Page.route()}, {@link Page#waitForURL
|
||||
* 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
|
||||
* When using {@link com.microsoft.playwright.Page#navigate Page.navigate()}, {@link com.microsoft.playwright.Page#route
|
||||
* Page.route()}, {@link com.microsoft.playwright.Page#waitForURL Page.waitForURL()}, {@link
|
||||
* com.microsoft.playwright.Page#waitForRequest Page.waitForRequest()}, or {@link
|
||||
* com.microsoft.playwright.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:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
@@ -818,10 +860,29 @@ public interface Browser extends AutoCloseable {
|
||||
this.bypassCSP = bypassCSP;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public NewPageOptions setClientCertificates(List<ClientCertificate> clientCertificates) {
|
||||
this.clientCertificates = clientCertificates;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code
|
||||
* "no-preference"}. See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "light"}.
|
||||
* "no-preference"}. See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing
|
||||
* {@code null} resets emulation to system defaults. Defaults to {@code "light"}.
|
||||
*/
|
||||
public NewPageOptions setColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = Optional.ofNullable(colorScheme);
|
||||
@@ -844,8 +905,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
* Defaults to {@code "none"}.
|
||||
* com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation
|
||||
* to system defaults. Defaults to {@code "none"}.
|
||||
*/
|
||||
public NewPageOptions setForcedColors(ForcedColors forcedColors) {
|
||||
this.forcedColors = Optional.ofNullable(forcedColors);
|
||||
@@ -924,8 +985,9 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* A list of permissions to grant to all pages in this context. See {@link
|
||||
* com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} for more details. Defaults
|
||||
* to none.
|
||||
*/
|
||||
public NewPageOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
@@ -933,20 +995,12 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
* 'http://per-context' } })}.
|
||||
*/
|
||||
public NewPageOptions setProxy(String server) {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
* 'http://per-context' } })}.
|
||||
*/
|
||||
public NewPageOptions setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
@@ -979,8 +1033,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Enables <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> recording for all pages into the specified HAR
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link BrowserContext#close
|
||||
* BrowserContext.close()} for the HAR to be saved.
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public NewPageOptions setRecordHarPath(Path recordHarPath) {
|
||||
this.recordHarPath = recordHarPath;
|
||||
@@ -996,7 +1050,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
|
||||
* to call {@link BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public NewPageOptions setRecordVideoDir(Path recordVideoDir) {
|
||||
this.recordVideoDir = recordVideoDir;
|
||||
@@ -1021,8 +1075,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system
|
||||
* defaults. Defaults to {@code "no-preference"}.
|
||||
* See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "no-preference"}.
|
||||
*/
|
||||
public NewPageOptions setReducedMotion(ReducedMotion reducedMotion) {
|
||||
this.reducedMotion = Optional.ofNullable(reducedMotion);
|
||||
@@ -1057,7 +1111,7 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public NewPageOptions setStorageState(String storageState) {
|
||||
this.storageState = storageState;
|
||||
@@ -1065,8 +1119,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
*/
|
||||
public NewPageOptions setStorageStatePath(Path storageStatePath) {
|
||||
this.storageStatePath = storageStatePath;
|
||||
@@ -1165,15 +1219,16 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
BrowserType browserType();
|
||||
/**
|
||||
* In case this browser is obtained using {@link BrowserType#launch BrowserType.launch()}, closes the browser and all of
|
||||
* its pages (if any were opened).
|
||||
* In case this browser is obtained using {@link com.microsoft.playwright.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> <strong>NOTE:</strong> This is similar to force quitting the browser. Therefore, you should call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} on any {@code BrowserContext}'s you explicitly
|
||||
* created earlier with {@link com.microsoft.playwright.Browser#newContext Browser.newContext()} **before** calling {@link
|
||||
* com.microsoft.playwright.Browser#close Browser.close()}.
|
||||
*
|
||||
* <p> The {@code Browser} object itself is considered to be disposed and cannot be used anymore.
|
||||
*
|
||||
@@ -1183,15 +1238,16 @@ public interface Browser extends AutoCloseable {
|
||||
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).
|
||||
* In case this browser is obtained using {@link com.microsoft.playwright.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> <strong>NOTE:</strong> This is similar to force quitting the browser. Therefore, you should call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} on any {@code BrowserContext}'s you explicitly
|
||||
* created earlier with {@link com.microsoft.playwright.Browser#newContext Browser.newContext()} **before** calling {@link
|
||||
* com.microsoft.playwright.Browser#close Browser.close()}.
|
||||
*
|
||||
* <p> The {@code Browser} object itself is considered to be disposed and cannot be used anymore.
|
||||
*
|
||||
@@ -1201,7 +1257,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Browser browser = pw.webkit().launch();
|
||||
* System.out.println(browser.contexts().size()); // prints "0"
|
||||
@@ -1230,11 +1286,11 @@ public interface Browser extends AutoCloseable {
|
||||
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If directly using this method to create {@code BrowserContext}s, it is best practice to explicitly close the returned
|
||||
* context via {@link BrowserContext#close BrowserContext.close()} when your code is done with the {@code BrowserContext},
|
||||
* and before calling {@link Browser#close Browser.close()}. This will ensure the {@code context} is closed gracefully and
|
||||
* any artifacts—like HARs and videos—are fully flushed and saved.
|
||||
* context via {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} when your code is done with the
|
||||
* {@code BrowserContext}, and before calling {@link com.microsoft.playwright.Browser#close Browser.close()}. This will
|
||||
* ensure the {@code context} is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
|
||||
* // Create a new incognito browser context.
|
||||
@@ -1257,11 +1313,11 @@ public interface Browser extends AutoCloseable {
|
||||
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> If directly using this method to create {@code BrowserContext}s, it is best practice to explicitly close the returned
|
||||
* context via {@link BrowserContext#close BrowserContext.close()} when your code is done with the {@code BrowserContext},
|
||||
* and before calling {@link Browser#close Browser.close()}. This will ensure the {@code context} is closed gracefully and
|
||||
* any artifacts—like HARs and videos—are fully flushed and saved.
|
||||
* context via {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} when your code is done with the
|
||||
* {@code BrowserContext}, and before calling {@link com.microsoft.playwright.Browser#close Browser.close()}. This will
|
||||
* ensure the {@code context} is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
|
||||
* // Create a new incognito browser context.
|
||||
@@ -1282,8 +1338,9 @@ public interface Browser extends AutoCloseable {
|
||||
* Creates a new page in a new browser context. Closing this page will close the context as well.
|
||||
*
|
||||
* <p> This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
||||
* testing frameworks should explicitly create {@link Browser#newContext Browser.newContext()} followed by the {@link
|
||||
* BrowserContext#newPage BrowserContext.newPage()} to control their exact life times.
|
||||
* testing frameworks should explicitly create {@link com.microsoft.playwright.Browser#newContext Browser.newContext()}
|
||||
* followed by the {@link com.microsoft.playwright.BrowserContext#newPage BrowserContext.newPage()} to control their exact
|
||||
* life times.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -1294,8 +1351,9 @@ public interface Browser extends AutoCloseable {
|
||||
* Creates a new page in a new browser context. Closing this page will close the context as well.
|
||||
*
|
||||
* <p> This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
||||
* testing frameworks should explicitly create {@link Browser#newContext Browser.newContext()} followed by the {@link
|
||||
* BrowserContext#newPage BrowserContext.newPage()} to control their exact life times.
|
||||
* testing frameworks should explicitly create {@link com.microsoft.playwright.Browser#newContext Browser.newContext()}
|
||||
* followed by the {@link com.microsoft.playwright.BrowserContext#newPage BrowserContext.newPage()} to control their exact
|
||||
* life times.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -1306,10 +1364,11 @@ public interface Browser extends AutoCloseable {
|
||||
* href="https://playwright.dev/java/docs/trace-viewer">Playwright Tracing</a> could be found <a
|
||||
* href="https://playwright.dev/java/docs/api/class-tracing">here</a>.
|
||||
*
|
||||
* <p> You can use {@link Browser#startTracing Browser.startTracing()} and {@link Browser#stopTracing Browser.stopTracing()} to
|
||||
* create a trace file that can be opened in Chrome DevTools performance panel.
|
||||
* <p> You can use {@link com.microsoft.playwright.Browser#startTracing Browser.startTracing()} and {@link
|
||||
* com.microsoft.playwright.Browser#stopTracing Browser.stopTracing()} to create a trace file that can be opened in Chrome
|
||||
* DevTools performance panel.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* browser.startTracing(page, new Browser.StartTracingOptions()
|
||||
* .setPath(Paths.get("trace.json")));
|
||||
@@ -1329,10 +1388,11 @@ public interface Browser extends AutoCloseable {
|
||||
* href="https://playwright.dev/java/docs/trace-viewer">Playwright Tracing</a> could be found <a
|
||||
* href="https://playwright.dev/java/docs/api/class-tracing">here</a>.
|
||||
*
|
||||
* <p> You can use {@link Browser#startTracing Browser.startTracing()} and {@link Browser#stopTracing Browser.stopTracing()} to
|
||||
* create a trace file that can be opened in Chrome DevTools performance panel.
|
||||
* <p> You can use {@link com.microsoft.playwright.Browser#startTracing Browser.startTracing()} and {@link
|
||||
* com.microsoft.playwright.Browser#stopTracing Browser.stopTracing()} to create a trace file that can be opened in Chrome
|
||||
* DevTools performance panel.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* browser.startTracing(page, new Browser.StartTracingOptions()
|
||||
* .setPath(Paths.get("trace.json")));
|
||||
@@ -1351,10 +1411,11 @@ public interface Browser extends AutoCloseable {
|
||||
* href="https://playwright.dev/java/docs/trace-viewer">Playwright Tracing</a> could be found <a
|
||||
* href="https://playwright.dev/java/docs/api/class-tracing">here</a>.
|
||||
*
|
||||
* <p> You can use {@link Browser#startTracing Browser.startTracing()} and {@link Browser#stopTracing Browser.stopTracing()} to
|
||||
* create a trace file that can be opened in Chrome DevTools performance panel.
|
||||
* <p> You can use {@link com.microsoft.playwright.Browser#startTracing Browser.startTracing()} and {@link
|
||||
* com.microsoft.playwright.Browser#stopTracing Browser.stopTracing()} to create a trace file that can be opened in Chrome
|
||||
* DevTools performance panel.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* browser.startTracing(page, new Browser.StartTracingOptions()
|
||||
* .setPath(Paths.get("trace.json")));
|
||||
|
||||
@@ -30,8 +30,9 @@ import java.util.regex.Pattern;
|
||||
* <p> If a page opens another page, e.g. with a {@code window.open} call, the popup will belong to the parent page's browser
|
||||
* context.
|
||||
*
|
||||
* <p> Playwright allows creating "incognito" browser contexts with {@link Browser#newContext Browser.newContext()} method.
|
||||
* "Incognito" browser contexts don't write any browsing data to disk.
|
||||
* <p> Playwright allows creating isolated non-persistent browser contexts with {@link
|
||||
* com.microsoft.playwright.Browser#newContext Browser.newContext()} method. Non-persistent browser contexts don't write
|
||||
* any browsing data to disk.
|
||||
* <pre>{@code
|
||||
* // Create a new incognito browser context
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -44,12 +45,28 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> Only works with Chromium browser's persistent context.
|
||||
*
|
||||
* <p> Emitted when new background page is created in the context.
|
||||
* <pre>{@code
|
||||
* context.onBackgroundPage(backgroundPage -> {
|
||||
* System.out.println(backgroundPage.url());
|
||||
* });
|
||||
* }</pre>
|
||||
*/
|
||||
void onBackgroundPage(Consumer<Page> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onBackgroundPage onBackgroundPage(handler)}.
|
||||
*/
|
||||
void offBackgroundPage(Consumer<Page> handler);
|
||||
|
||||
/**
|
||||
* Emitted when Browser context gets closed. This might happen because of one of the following:
|
||||
* <ul>
|
||||
* <li> Browser context is closed.</li>
|
||||
* <li> Browser application is closed or crashed.</li>
|
||||
* <li> The {@link Browser#close Browser.close()} method was called.</li>
|
||||
* <li> The {@link com.microsoft.playwright.Browser#close Browser.close()} method was called.</li>
|
||||
* </ul>
|
||||
*/
|
||||
void onClose(Consumer<BrowserContext> handler);
|
||||
@@ -65,7 +82,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <p> The arguments passed into {@code console.log} and the page are available on the {@code ConsoleMessage} event handler
|
||||
* argument.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.onConsoleMessage(msg -> {
|
||||
* for (int i = 0; i < msg.args().size(); ++i)
|
||||
@@ -82,20 +99,21 @@ public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* beforeunload}. Listener **must** either {@link com.microsoft.playwright.Dialog#accept Dialog.accept()} or {@link
|
||||
* com.microsoft.playwright.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**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <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.
|
||||
* <p> <strong>NOTE:</strong> When no {@link com.microsoft.playwright.Page#onDialog Page.onDialog()} or {@link
|
||||
* com.microsoft.playwright.BrowserContext#onDialog BrowserContext.onDialog()} listeners are present, all dialogs are
|
||||
* automatically dismissed.
|
||||
*/
|
||||
void onDialog(Consumer<Dialog> handler);
|
||||
/**
|
||||
@@ -105,12 +123,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* specific page.
|
||||
* also fire for popup pages. See also {@link com.microsoft.playwright.Page#onPopup Page.onPopup()} to receive events about
|
||||
* popups relevant to a specific page.
|
||||
*
|
||||
* <p> The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
|
||||
* popup with {@code window.open('http://example.com')}, this event will fire when the network request to
|
||||
* "http://example.com" is done and its response has started loading in the popup.
|
||||
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen to
|
||||
* this network request, use {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} and {@link
|
||||
* com.microsoft.playwright.BrowserContext#onRequest BrowserContext.onRequest()} respectively instead of similar methods on
|
||||
* the {@code Page}.
|
||||
* <pre>{@code
|
||||
* Page newPage = context.waitForPage(() -> {
|
||||
* page.getByText("open new page").click();
|
||||
@@ -118,8 +139,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* System.out.println(newPage.evaluate("location.href"));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Use {@link Page#waitForLoadState Page.waitForLoadState()} to wait until the page gets to a particular state (you should
|
||||
* not need it in most cases).
|
||||
* <p> <strong>NOTE:</strong> Use {@link com.microsoft.playwright.Page#waitForLoadState Page.waitForLoadState()} to wait until the page gets to a
|
||||
* particular state (you should not need it in most cases).
|
||||
*/
|
||||
void onPage(Consumer<Page> handler);
|
||||
/**
|
||||
@@ -129,7 +150,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* use {@link com.microsoft.playwright.Page#onPageError Page.onPageError()} instead.
|
||||
*/
|
||||
void onWebError(Consumer<WebError> handler);
|
||||
/**
|
||||
@@ -139,10 +160,10 @@ public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* 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()}.
|
||||
* listen for requests from a particular page, use {@link com.microsoft.playwright.Page#onRequest Page.onRequest()}.
|
||||
*
|
||||
* <p> In order to intercept and mutate requests, see {@link BrowserContext#route BrowserContext.route()} or {@link Page#route
|
||||
* Page.route()}.
|
||||
* <p> In order to intercept and mutate requests, see {@link com.microsoft.playwright.BrowserContext#route
|
||||
* BrowserContext.route()} or {@link com.microsoft.playwright.Page#route Page.route()}.
|
||||
*/
|
||||
void onRequest(Consumer<Request> handler);
|
||||
/**
|
||||
@@ -152,11 +173,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* Emitted when a request fails, for example by timing out. To only listen for failed requests from a particular page, use
|
||||
* {@link Page#onRequestFailed Page.onRequestFailed()}.
|
||||
* {@link com.microsoft.playwright.Page#onRequestFailed Page.onRequestFailed()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
|
||||
* with {@link BrowserContext#onRequestFinished BrowserContext.onRequestFinished()} event and not with {@link
|
||||
* BrowserContext#onRequestFailed BrowserContext.onRequestFailed()}.
|
||||
* with {@link com.microsoft.playwright.BrowserContext#onRequestFinished BrowserContext.onRequestFinished()} event and not
|
||||
* with {@link com.microsoft.playwright.BrowserContext#onRequestFailed BrowserContext.onRequestFailed()}.
|
||||
*/
|
||||
void onRequestFailed(Consumer<Request> handler);
|
||||
/**
|
||||
@@ -167,7 +188,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
/**
|
||||
* Emitted when a request finishes successfully after downloading the response body. For a successful response, the
|
||||
* sequence of events is {@code request}, {@code response} and {@code requestfinished}. To listen for successful requests
|
||||
* from a particular page, use {@link Page#onRequestFinished Page.onRequestFinished()}.
|
||||
* from a particular page, use {@link com.microsoft.playwright.Page#onRequestFinished Page.onRequestFinished()}.
|
||||
*/
|
||||
void onRequestFinished(Consumer<Request> handler);
|
||||
/**
|
||||
@@ -178,7 +199,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
/**
|
||||
* Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
|
||||
* is {@code request}, {@code response} and {@code requestfinished}. To listen for response events from a particular page,
|
||||
* use {@link Page#onResponse Page.onResponse()}.
|
||||
* use {@link com.microsoft.playwright.Page#onResponse Page.onResponse()}.
|
||||
*/
|
||||
void onResponse(Consumer<Response> handler);
|
||||
/**
|
||||
@@ -186,6 +207,63 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offResponse(Consumer<Response> handler);
|
||||
|
||||
class ClearCookiesOptions {
|
||||
/**
|
||||
* Only removes cookies with the given domain.
|
||||
*/
|
||||
public Object domain;
|
||||
/**
|
||||
* Only removes cookies with the given name.
|
||||
*/
|
||||
public Object name;
|
||||
/**
|
||||
* Only removes cookies with the given path.
|
||||
*/
|
||||
public Object path;
|
||||
|
||||
/**
|
||||
* Only removes cookies with the given domain.
|
||||
*/
|
||||
public ClearCookiesOptions setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only removes cookies with the given domain.
|
||||
*/
|
||||
public ClearCookiesOptions setDomain(Pattern domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only removes cookies with the given name.
|
||||
*/
|
||||
public ClearCookiesOptions setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only removes cookies with the given name.
|
||||
*/
|
||||
public ClearCookiesOptions setName(Pattern name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only removes cookies with the given path.
|
||||
*/
|
||||
public ClearCookiesOptions setPath(String path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Only removes cookies with the given path.
|
||||
*/
|
||||
public ClearCookiesOptions setPath(Pattern path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class CloseOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context closure.
|
||||
@@ -202,14 +280,12 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
* supported. When passing by value, multiple arguments are supported.
|
||||
* @deprecated This option will be removed in the future.
|
||||
*/
|
||||
public Boolean handle;
|
||||
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
* supported. When passing by value, multiple arguments are supported.
|
||||
* @deprecated This option will be removed in the future.
|
||||
*/
|
||||
public ExposeBindingOptions setHandle(boolean handle) {
|
||||
this.handle = handle;
|
||||
@@ -256,7 +332,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
public HarNotFound notFound;
|
||||
/**
|
||||
* If specified, updates the given HAR with the actual network information instead of serving from file. The file is
|
||||
* written to disk when {@link BrowserContext#close BrowserContext.close()} is called.
|
||||
* written to disk when {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} is called.
|
||||
*/
|
||||
public Boolean update;
|
||||
/**
|
||||
@@ -290,7 +366,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* If specified, updates the given HAR with the actual network information instead of serving from file. The file is
|
||||
* written to disk when {@link BrowserContext#close BrowserContext.close()} is called.
|
||||
* written to disk when {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} is called.
|
||||
*/
|
||||
public RouteFromHAROptions setUpdate(boolean update) {
|
||||
this.update = update;
|
||||
@@ -349,15 +425,17 @@ public interface BrowserContext extends AutoCloseable {
|
||||
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.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.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.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public WaitForConditionOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -371,7 +449,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -384,7 +463,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForConsoleMessageOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -398,7 +478,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
public Predicate<Page> 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -411,7 +492,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForPageOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -419,17 +501,20 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
||||
* obtained via {@link BrowserContext#cookies BrowserContext.cookies()}.
|
||||
* Playwright has ability to mock clock and passage of time.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* @since v1.45
|
||||
*/
|
||||
Clock clock();
|
||||
/**
|
||||
* Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#cookies BrowserContext.cookies()}.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* 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);
|
||||
@@ -444,7 +529,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <p> The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
||||
* the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of overriding {@code Math.random} before the page loads:
|
||||
* <pre>{@code
|
||||
@@ -452,8 +537,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* browserContext.addInitScript(Paths.get("preload.js"));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The order of evaluation of multiple scripts installed via {@link BrowserContext#addInitScript
|
||||
* BrowserContext.addInitScript()} and {@link Page#addInitScript Page.addInitScript()} is not defined.
|
||||
* <p> <strong>NOTE:</strong> The order of evaluation of multiple scripts installed via {@link com.microsoft.playwright.BrowserContext#addInitScript
|
||||
* BrowserContext.addInitScript()} and {@link com.microsoft.playwright.Page#addInitScript Page.addInitScript()} is not
|
||||
* defined.
|
||||
*
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @since v1.8
|
||||
@@ -470,7 +556,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <p> The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
||||
* the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of overriding {@code Math.random} before the page loads:
|
||||
* <pre>{@code
|
||||
@@ -478,13 +564,22 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* browserContext.addInitScript(Paths.get("preload.js"));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The order of evaluation of multiple scripts installed via {@link BrowserContext#addInitScript
|
||||
* BrowserContext.addInitScript()} and {@link Page#addInitScript Page.addInitScript()} is not defined.
|
||||
* <p> <strong>NOTE:</strong> The order of evaluation of multiple scripts installed via {@link com.microsoft.playwright.BrowserContext#addInitScript
|
||||
* BrowserContext.addInitScript()} and {@link com.microsoft.playwright.Page#addInitScript Page.addInitScript()} is not
|
||||
* defined.
|
||||
*
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void addInitScript(Path script);
|
||||
/**
|
||||
* <strong>NOTE:</strong> Background pages are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> All existing background pages in the context.
|
||||
*
|
||||
* @since v1.11
|
||||
*/
|
||||
List<Page> backgroundPages();
|
||||
/**
|
||||
* Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
|
||||
*
|
||||
@@ -492,15 +587,45 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
Browser browser();
|
||||
/**
|
||||
* Clears context cookies.
|
||||
* Removes cookies from context. Accepts optional filter.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.clearCookies();
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions().setName("session-id"));
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions().setDomain("my-origin.com"));
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions().setPath("/api/v1"));
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions()
|
||||
* .setName("session-id")
|
||||
* .setDomain("my-origin.com"));
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void clearCookies();
|
||||
default void clearCookies() {
|
||||
clearCookies(null);
|
||||
}
|
||||
/**
|
||||
* Removes cookies from context. Accepts optional filter.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.clearCookies();
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions().setName("session-id"));
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions().setDomain("my-origin.com"));
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions().setPath("/api/v1"));
|
||||
* context.clearCookies(new BrowserContext.ClearCookiesOptions()
|
||||
* .setName("session-id")
|
||||
* .setDomain("my-origin.com"));
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void clearCookies(ClearCookiesOptions options);
|
||||
/**
|
||||
* Clears all permission overrides for the browser context.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
* context.grantPermissions(Arrays.asList("clipboard-read"));
|
||||
@@ -565,9 +690,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <p> The first argument of the {@code callback} function contains information about the caller: {@code { browserContext:
|
||||
* BrowserContext, page: Page, frame: Frame }}.
|
||||
*
|
||||
* <p> See {@link Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
* <p> See {@link com.microsoft.playwright.Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of exposing page URL to all frames in all pages in the context:
|
||||
* <pre>{@code
|
||||
@@ -594,21 +719,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of passing an element handle:
|
||||
* <pre>{@code
|
||||
* context.exposeBinding("clicked", (source, args) -> {
|
||||
* ElementHandle element = (ElementHandle) args[0];
|
||||
* System.out.println(element.textContent());
|
||||
* return null;
|
||||
* }, new BrowserContext.ExposeBindingOptions().setHandle(true));
|
||||
* page.setContent("" +
|
||||
* "<script>\n" +
|
||||
* " document.addEventListener('click', event => window.clicked(event.target));\n" +
|
||||
* "</script>\n" +
|
||||
* "<div>Click me</div>\n" +
|
||||
* "<div>Or click me</div>\n");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @since v1.8
|
||||
@@ -627,9 +737,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <p> The first argument of the {@code callback} function contains information about the caller: {@code { browserContext:
|
||||
* BrowserContext, page: Page, frame: Frame }}.
|
||||
*
|
||||
* <p> See {@link Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
* <p> See {@link com.microsoft.playwright.Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of exposing page URL to all frames in all pages in the context:
|
||||
* <pre>{@code
|
||||
@@ -656,21 +766,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of passing an element handle:
|
||||
* <pre>{@code
|
||||
* context.exposeBinding("clicked", (source, args) -> {
|
||||
* ElementHandle element = (ElementHandle) args[0];
|
||||
* System.out.println(element.textContent());
|
||||
* return null;
|
||||
* }, new BrowserContext.ExposeBindingOptions().setHandle(true));
|
||||
* page.setContent("" +
|
||||
* "<script>\n" +
|
||||
* " document.addEventListener('click', event => window.clicked(event.target));\n" +
|
||||
* "</script>\n" +
|
||||
* "<div>Click me</div>\n" +
|
||||
* "<div>Or click me</div>\n");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @since v1.8
|
||||
@@ -686,9 +781,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, it will be
|
||||
* awaited.
|
||||
*
|
||||
* <p> See {@link Page#exposeFunction Page.exposeFunction()} for page-only version.
|
||||
* <p> See {@link com.microsoft.playwright.Page#exposeFunction Page.exposeFunction()} for page-only version.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of adding a {@code sha256} function to all pages in the context:
|
||||
* <pre>{@code
|
||||
@@ -740,21 +835,22 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* <ul>
|
||||
* <li> {@code "geolocation"}</li>
|
||||
* <li> {@code "midi"}</li>
|
||||
* <li> {@code "midi-sysex"} (system-exclusive midi)</li>
|
||||
* <li> {@code "notifications"}</li>
|
||||
* <li> {@code "camera"}</li>
|
||||
* <li> {@code "microphone"}</li>
|
||||
* <li> {@code "background-sync"}</li>
|
||||
* <li> {@code "ambient-light-sensor"}</li>
|
||||
* <li> {@code "accelerometer"}</li>
|
||||
* <li> {@code "gyroscope"}</li>
|
||||
* <li> {@code "magnetometer"}</li>
|
||||
* <li> {@code "accessibility-events"}</li>
|
||||
* <li> {@code "ambient-light-sensor"}</li>
|
||||
* <li> {@code "background-sync"}</li>
|
||||
* <li> {@code "camera"}</li>
|
||||
* <li> {@code "clipboard-read"}</li>
|
||||
* <li> {@code "clipboard-write"}</li>
|
||||
* <li> {@code "geolocation"}</li>
|
||||
* <li> {@code "gyroscope"}</li>
|
||||
* <li> {@code "magnetometer"}</li>
|
||||
* <li> {@code "microphone"}</li>
|
||||
* <li> {@code "midi-sysex"} (system-exclusive midi)</li>
|
||||
* <li> {@code "midi"}</li>
|
||||
* <li> {@code "notifications"}</li>
|
||||
* <li> {@code "payment-handler"}</li>
|
||||
* <li> {@code "storage-access"}</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -767,21 +863,22 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* <ul>
|
||||
* <li> {@code "geolocation"}</li>
|
||||
* <li> {@code "midi"}</li>
|
||||
* <li> {@code "midi-sysex"} (system-exclusive midi)</li>
|
||||
* <li> {@code "notifications"}</li>
|
||||
* <li> {@code "camera"}</li>
|
||||
* <li> {@code "microphone"}</li>
|
||||
* <li> {@code "background-sync"}</li>
|
||||
* <li> {@code "ambient-light-sensor"}</li>
|
||||
* <li> {@code "accelerometer"}</li>
|
||||
* <li> {@code "gyroscope"}</li>
|
||||
* <li> {@code "magnetometer"}</li>
|
||||
* <li> {@code "accessibility-events"}</li>
|
||||
* <li> {@code "ambient-light-sensor"}</li>
|
||||
* <li> {@code "background-sync"}</li>
|
||||
* <li> {@code "camera"}</li>
|
||||
* <li> {@code "clipboard-read"}</li>
|
||||
* <li> {@code "clipboard-write"}</li>
|
||||
* <li> {@code "geolocation"}</li>
|
||||
* <li> {@code "gyroscope"}</li>
|
||||
* <li> {@code "magnetometer"}</li>
|
||||
* <li> {@code "microphone"}</li>
|
||||
* <li> {@code "midi-sysex"} (system-exclusive midi)</li>
|
||||
* <li> {@code "midi"}</li>
|
||||
* <li> {@code "notifications"}</li>
|
||||
* <li> {@code "payment-handler"}</li>
|
||||
* <li> {@code "storage-access"}</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -828,11 +925,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by
|
||||
* Service Worker. See <a href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling
|
||||
* Service Workers when using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
@@ -863,10 +960,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Page routes (set up with {@link Page#route Page.route()}) take precedence over browser context routes when request
|
||||
* matches both handlers.
|
||||
* <p> Page routes (set up with {@link com.microsoft.playwright.Page#route Page.route()}) take precedence over browser context
|
||||
* routes when request matches both handlers.
|
||||
*
|
||||
* <p> To remove a route with its handler you can use {@link BrowserContext#unroute BrowserContext.unroute()}.
|
||||
* <p> To remove a route with its handler you can use {@link com.microsoft.playwright.BrowserContext#unroute
|
||||
* BrowserContext.unroute()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Enabling routing disables http cache.
|
||||
*
|
||||
@@ -883,11 +981,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by
|
||||
* Service Worker. See <a href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling
|
||||
* Service Workers when using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
@@ -918,10 +1016,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Page routes (set up with {@link Page#route Page.route()}) take precedence over browser context routes when request
|
||||
* matches both handlers.
|
||||
* <p> Page routes (set up with {@link com.microsoft.playwright.Page#route Page.route()}) take precedence over browser context
|
||||
* routes when request matches both handlers.
|
||||
*
|
||||
* <p> To remove a route with its handler you can use {@link BrowserContext#unroute BrowserContext.unroute()}.
|
||||
* <p> To remove a route with its handler you can use {@link com.microsoft.playwright.BrowserContext#unroute
|
||||
* BrowserContext.unroute()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Enabling routing disables http cache.
|
||||
*
|
||||
@@ -936,11 +1035,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by
|
||||
* Service Worker. See <a href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling
|
||||
* Service Workers when using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
@@ -971,10 +1070,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Page routes (set up with {@link Page#route Page.route()}) take precedence over browser context routes when request
|
||||
* matches both handlers.
|
||||
* <p> Page routes (set up with {@link com.microsoft.playwright.Page#route Page.route()}) take precedence over browser context
|
||||
* routes when request matches both handlers.
|
||||
*
|
||||
* <p> To remove a route with its handler you can use {@link BrowserContext#unroute BrowserContext.unroute()}.
|
||||
* <p> To remove a route with its handler you can use {@link com.microsoft.playwright.BrowserContext#unroute
|
||||
* BrowserContext.unroute()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Enabling routing disables http cache.
|
||||
*
|
||||
@@ -991,11 +1091,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by
|
||||
* Service Worker. See <a href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling
|
||||
* Service Workers when using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
@@ -1026,10 +1126,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Page routes (set up with {@link Page#route Page.route()}) take precedence over browser context routes when request
|
||||
* matches both handlers.
|
||||
* <p> Page routes (set up with {@link com.microsoft.playwright.Page#route Page.route()}) take precedence over browser context
|
||||
* routes when request matches both handlers.
|
||||
*
|
||||
* <p> To remove a route with its handler you can use {@link BrowserContext#unroute BrowserContext.unroute()}.
|
||||
* <p> To remove a route with its handler you can use {@link com.microsoft.playwright.BrowserContext#unroute
|
||||
* BrowserContext.unroute()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Enabling routing disables http cache.
|
||||
*
|
||||
@@ -1044,11 +1145,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by
|
||||
* Service Worker. See <a href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling
|
||||
* Service Workers when using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
@@ -1079,10 +1180,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Page routes (set up with {@link Page#route Page.route()}) take precedence over browser context routes when request
|
||||
* matches both handlers.
|
||||
* <p> Page routes (set up with {@link com.microsoft.playwright.Page#route Page.route()}) take precedence over browser context
|
||||
* routes when request matches both handlers.
|
||||
*
|
||||
* <p> To remove a route with its handler you can use {@link BrowserContext#unroute BrowserContext.unroute()}.
|
||||
* <p> To remove a route with its handler you can use {@link com.microsoft.playwright.BrowserContext#unroute
|
||||
* BrowserContext.unroute()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Enabling routing disables http cache.
|
||||
*
|
||||
@@ -1099,11 +1201,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by
|
||||
* Service Worker. See <a href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling
|
||||
* Service Workers when using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
@@ -1134,10 +1236,11 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Page routes (set up with {@link Page#route Page.route()}) take precedence over browser context routes when request
|
||||
* matches both handlers.
|
||||
* <p> Page routes (set up with {@link com.microsoft.playwright.Page#route Page.route()}) take precedence over browser context
|
||||
* routes when request matches both handlers.
|
||||
*
|
||||
* <p> To remove a route with its handler you can use {@link BrowserContext#unroute BrowserContext.unroute()}.
|
||||
* <p> To remove a route with its handler you can use {@link com.microsoft.playwright.BrowserContext#unroute
|
||||
* BrowserContext.unroute()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Enabling routing disables http cache.
|
||||
*
|
||||
@@ -1179,17 +1282,17 @@ public interface BrowserContext extends AutoCloseable {
|
||||
/**
|
||||
* This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
||||
* <ul>
|
||||
* <li> {@link Page#goBack Page.goBack()}</li>
|
||||
* <li> {@link Page#goForward Page.goForward()}</li>
|
||||
* <li> {@link Page#navigate Page.navigate()}</li>
|
||||
* <li> {@link Page#reload Page.reload()}</li>
|
||||
* <li> {@link Page#setContent Page.setContent()}</li>
|
||||
* <li> {@link Page#waitForNavigation Page.waitForNavigation()}</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#goBack Page.goBack()}</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#goForward Page.goForward()}</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#navigate Page.navigate()}</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#reload Page.reload()}</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#setContent Page.setContent()}</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#waitForNavigation Page.waitForNavigation()}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link Page#setDefaultNavigationTimeout Page.setDefaultNavigationTimeout()} and {@link Page#setDefaultTimeout
|
||||
* Page.setDefaultTimeout()} take priority over {@link BrowserContext#setDefaultNavigationTimeout
|
||||
* BrowserContext.setDefaultNavigationTimeout()}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.Page#setDefaultNavigationTimeout Page.setDefaultNavigationTimeout()} and {@link
|
||||
* com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()} take priority over {@link
|
||||
* com.microsoft.playwright.BrowserContext#setDefaultNavigationTimeout BrowserContext.setDefaultNavigationTimeout()}.
|
||||
*
|
||||
* @param timeout Maximum navigation time in milliseconds
|
||||
* @since v1.8
|
||||
@@ -1198,10 +1301,10 @@ public interface BrowserContext extends AutoCloseable {
|
||||
/**
|
||||
* This setting will change the default maximum time for all the methods accepting {@code timeout} option.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link Page#setDefaultNavigationTimeout Page.setDefaultNavigationTimeout()}, {@link Page#setDefaultTimeout
|
||||
* Page.setDefaultTimeout()} and {@link BrowserContext#setDefaultNavigationTimeout
|
||||
* BrowserContext.setDefaultNavigationTimeout()} take priority over {@link BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.Page#setDefaultNavigationTimeout Page.setDefaultNavigationTimeout()}, {@link
|
||||
* com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()} and {@link
|
||||
* com.microsoft.playwright.BrowserContext#setDefaultNavigationTimeout BrowserContext.setDefaultNavigationTimeout()} take
|
||||
* priority over {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
|
||||
*
|
||||
* @param timeout Maximum time in milliseconds
|
||||
* @since v1.8
|
||||
@@ -1209,11 +1312,12 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void setDefaultTimeout(double timeout);
|
||||
/**
|
||||
* The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
||||
* with page-specific extra HTTP headers set with {@link Page#setExtraHTTPHeaders Page.setExtraHTTPHeaders()}. If page
|
||||
* overrides a particular header, page-specific header value will be used instead of the browser context header value.
|
||||
* with page-specific extra HTTP headers set with {@link com.microsoft.playwright.Page#setExtraHTTPHeaders
|
||||
* Page.setExtraHTTPHeaders()}. If page overrides a particular header, page-specific header value will be used instead of
|
||||
* the browser context header value.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#setExtraHTTPHeaders BrowserContext.setExtraHTTPHeaders()} does not guarantee the order of headers
|
||||
* in the outgoing requests.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.BrowserContext#setExtraHTTPHeaders BrowserContext.setExtraHTTPHeaders()} does not
|
||||
* guarantee the order of headers in the outgoing requests.
|
||||
*
|
||||
* @param headers An object containing additional HTTP headers to be sent with every request. All header values must be strings.
|
||||
* @since v1.8
|
||||
@@ -1222,13 +1326,13 @@ public interface BrowserContext extends AutoCloseable {
|
||||
/**
|
||||
* Sets the context's geolocation. Passing {@code null} or {@code undefined} emulates position unavailable.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* browserContext.setGeolocation(new Geolocation(59.95, 30.31667));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Consider using {@link BrowserContext#grantPermissions BrowserContext.grantPermissions()} to grant permissions for the
|
||||
* browser context pages to read its geolocation.
|
||||
* <p> <strong>NOTE:</strong> Consider using {@link com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} to
|
||||
* grant permissions for the browser context pages to read its geolocation.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -1261,72 +1365,75 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
Tracing tracing();
|
||||
/**
|
||||
* Removes all routes created with {@link BrowserContext#route BrowserContext.route()} and {@link
|
||||
* BrowserContext#routeFromHAR BrowserContext.routeFromHAR()}.
|
||||
* Removes all routes created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()} and {@link
|
||||
* com.microsoft.playwright.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}.
|
||||
* Removes a route created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()}. When {@code
|
||||
* handler} is not specified, removes all routes for the {@code url}.
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link BrowserContext#route
|
||||
* BrowserContext.route()}.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void unroute(String url) {
|
||||
unroute(url, null);
|
||||
}
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
* Removes a route created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()}. When {@code
|
||||
* handler} is not specified, removes all routes for the {@code url}.
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link BrowserContext#route
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}.
|
||||
* @param handler Optional handler function used to register a routing with {@link com.microsoft.playwright.BrowserContext#route
|
||||
* BrowserContext.route()}.
|
||||
* @param handler Optional handler function used to register a routing with {@link BrowserContext#route BrowserContext.route()}.
|
||||
* @since v1.8
|
||||
*/
|
||||
void unroute(String url, Consumer<Route> handler);
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
* Removes a route created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()}. When {@code
|
||||
* handler} is not specified, removes all routes for the {@code url}.
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link BrowserContext#route
|
||||
* BrowserContext.route()}.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void unroute(Pattern url) {
|
||||
unroute(url, null);
|
||||
}
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
* Removes a route created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()}. When {@code
|
||||
* handler} is not specified, removes all routes for the {@code url}.
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link BrowserContext#route
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}.
|
||||
* @param handler Optional handler function used to register a routing with {@link com.microsoft.playwright.BrowserContext#route
|
||||
* BrowserContext.route()}.
|
||||
* @param handler Optional handler function used to register a routing with {@link BrowserContext#route BrowserContext.route()}.
|
||||
* @since v1.8
|
||||
*/
|
||||
void unroute(Pattern url, Consumer<Route> handler);
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
* Removes a route created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()}. When {@code
|
||||
* handler} is not specified, removes all routes for the {@code url}.
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link BrowserContext#route
|
||||
* BrowserContext.route()}.
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void unroute(Predicate<String> url) {
|
||||
unroute(url, null);
|
||||
}
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
* Removes a route created with {@link com.microsoft.playwright.BrowserContext#route BrowserContext.route()}. When {@code
|
||||
* handler} is not specified, removes all routes for the {@code url}.
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link BrowserContext#route
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}.
|
||||
* @param handler Optional handler function used to register a routing with {@link com.microsoft.playwright.BrowserContext#route
|
||||
* BrowserContext.route()}.
|
||||
* @param handler Optional handler function used to register a routing with {@link BrowserContext#route BrowserContext.route()}.
|
||||
* @since v1.8
|
||||
*/
|
||||
void unroute(Predicate<String> url, Consumer<Route> handler);
|
||||
@@ -1334,7 +1441,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Use the method to wait for a condition that depends on page events:
|
||||
* <pre>{@code
|
||||
@@ -1359,7 +1466,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Use the method to wait for a condition that depends on page events:
|
||||
* <pre>{@code
|
||||
@@ -1382,7 +1489,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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.
|
||||
* com.microsoft.playwright.BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
|
||||
*
|
||||
* @param callback Callback that performs the action triggering the event.
|
||||
* @since v1.34
|
||||
@@ -1394,7 +1501,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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.
|
||||
* com.microsoft.playwright.BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
|
||||
*
|
||||
* @param callback Callback that performs the action triggering the event.
|
||||
* @since v1.34
|
||||
|
||||
@@ -182,8 +182,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean chromiumSandbox;
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code
|
||||
* headless} option will be set {@code false}.
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
@@ -291,8 +290,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code
|
||||
* headless} option will be set {@code false}.
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public LaunchOptions setDevtools(boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
@@ -427,10 +425,11 @@ public interface BrowserType {
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
* When using {@link Page#navigate Page.navigate()}, {@link Page#route Page.route()}, {@link Page#waitForURL
|
||||
* 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
|
||||
* When using {@link com.microsoft.playwright.Page#navigate Page.navigate()}, {@link com.microsoft.playwright.Page#route
|
||||
* Page.route()}, {@link com.microsoft.playwright.Page#waitForURL Page.waitForURL()}, {@link
|
||||
* com.microsoft.playwright.Page#waitForRequest Page.waitForRequest()}, or {@link
|
||||
* com.microsoft.playwright.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:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
@@ -456,10 +455,26 @@ public interface BrowserType {
|
||||
* Enable Chromium sandboxing. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean chromiumSandbox;
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public List<ClientCertificate> clientCertificates;
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code
|
||||
* "no-preference"}. See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "light"}.
|
||||
* "no-preference"}. See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing
|
||||
* {@code null} resets emulation to system defaults. Defaults to {@code "light"}.
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
@@ -468,8 +483,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code
|
||||
* headless} option will be set {@code false}.
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
@@ -499,8 +513,8 @@ public interface BrowserType {
|
||||
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.
|
||||
* Defaults to {@code "none"}.
|
||||
* com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation
|
||||
* to system defaults. Defaults to {@code "none"}.
|
||||
*/
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
@@ -571,8 +585,9 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* A list of permissions to grant to all pages in this context. See {@link
|
||||
* com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} for more details. Defaults
|
||||
* to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
@@ -597,14 +612,14 @@ public interface BrowserType {
|
||||
public Boolean recordHarOmitContent;
|
||||
/**
|
||||
* Enables <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> recording for all pages into the specified HAR
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link BrowserContext#close
|
||||
* BrowserContext.close()} for the HAR to be saved.
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public Path recordHarPath;
|
||||
public Object recordHarUrlFilter;
|
||||
/**
|
||||
* Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
|
||||
* to call {@link BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public Path recordVideoDir;
|
||||
/**
|
||||
@@ -615,8 +630,8 @@ public interface BrowserType {
|
||||
public RecordVideoSize recordVideoSize;
|
||||
/**
|
||||
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system
|
||||
* defaults. Defaults to {@code "no-preference"}.
|
||||
* See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "no-preference"}.
|
||||
*/
|
||||
public Optional<ReducedMotion> reducedMotion;
|
||||
/**
|
||||
@@ -691,10 +706,11 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When using {@link Page#navigate Page.navigate()}, {@link Page#route Page.route()}, {@link Page#waitForURL
|
||||
* 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
|
||||
* When using {@link com.microsoft.playwright.Page#navigate Page.navigate()}, {@link com.microsoft.playwright.Page#route
|
||||
* Page.route()}, {@link com.microsoft.playwright.Page#waitForURL Page.waitForURL()}, {@link
|
||||
* com.microsoft.playwright.Page#waitForRequest Page.waitForRequest()}, or {@link
|
||||
* com.microsoft.playwright.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:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
@@ -742,10 +758,29 @@ public interface BrowserType {
|
||||
this.chromiumSandbox = chromiumSandbox;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* TLS Client Authentication allows the server to request a client certificate and verify it.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> An array of client certificates to be used. Each certificate object must have either both {@code certPath} and {@code
|
||||
* keyPath}, a single {@code pfxPath}, or their corresponding direct value equivalents ({@code cert} and {@code key}, or
|
||||
* {@code pfx}). Optionally, {@code passphrase} property should be provided if the certificate is encrypted. The {@code
|
||||
* origin} property should be provided with an exact match to the request origin that the certificate is valid for.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Using Client Certificates in combination with Proxy Servers is not supported.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When using WebKit on macOS, accessing {@code localhost} will not pick up client certificates. You can make it work by
|
||||
* replacing {@code localhost} with {@code local.playwright}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setClientCertificates(List<ClientCertificate> clientCertificates) {
|
||||
this.clientCertificates = clientCertificates;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code
|
||||
* "no-preference"}. See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "light"}.
|
||||
* "no-preference"}. See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing
|
||||
* {@code null} resets emulation to system defaults. Defaults to {@code "light"}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setColorScheme(ColorScheme colorScheme) {
|
||||
this.colorScheme = Optional.ofNullable(colorScheme);
|
||||
@@ -760,8 +795,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is {@code true}, the {@code
|
||||
* headless} option will be set {@code false}.
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setDevtools(boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
@@ -809,8 +843,8 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
* Defaults to {@code "none"}.
|
||||
* com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation
|
||||
* to system defaults. Defaults to {@code "none"}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setForcedColors(ForcedColors forcedColors) {
|
||||
this.forcedColors = Optional.ofNullable(forcedColors);
|
||||
@@ -936,8 +970,9 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
* A list of permissions to grant to all pages in this context. See {@link
|
||||
* com.microsoft.playwright.BrowserContext#grantPermissions BrowserContext.grantPermissions()} for more details. Defaults
|
||||
* to none.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
@@ -983,8 +1018,8 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Enables <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> recording for all pages into the specified HAR
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link BrowserContext#close
|
||||
* BrowserContext.close()} for the HAR to be saved.
|
||||
* file on the filesystem. If not specified, the HAR is not recorded. Make sure to call {@link
|
||||
* com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for the HAR to be saved.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setRecordHarPath(Path recordHarPath) {
|
||||
this.recordHarPath = recordHarPath;
|
||||
@@ -1000,7 +1035,7 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Enables video recording for all pages into the specified directory. If not specified videos are not recorded. Make sure
|
||||
* to call {@link BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
* to call {@link com.microsoft.playwright.BrowserContext#close BrowserContext.close()} for videos to be saved.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setRecordVideoDir(Path recordVideoDir) {
|
||||
this.recordVideoDir = recordVideoDir;
|
||||
@@ -1025,8 +1060,8 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system
|
||||
* defaults. Defaults to {@code "no-preference"}.
|
||||
* See {@link com.microsoft.playwright.Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets
|
||||
* emulation to system defaults. Defaults to {@code "no-preference"}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setReducedMotion(ReducedMotion reducedMotion) {
|
||||
this.reducedMotion = Optional.ofNullable(reducedMotion);
|
||||
@@ -1154,11 +1189,11 @@ public interface BrowserType {
|
||||
/**
|
||||
* This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
|
||||
*
|
||||
* <p> The default browser context is accessible via {@link Browser#contexts Browser.contexts()}.
|
||||
* <p> The default browser context is accessible via {@link com.microsoft.playwright.Browser#contexts Browser.contexts()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.chromium().connectOverCDP("http://localhost:9222");
|
||||
* BrowserContext defaultContext = browser.contexts().get(0);
|
||||
@@ -1175,11 +1210,11 @@ public interface BrowserType {
|
||||
/**
|
||||
* This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
|
||||
*
|
||||
* <p> The default browser context is accessible via {@link Browser#contexts Browser.contexts()}.
|
||||
* <p> The default browser context is accessible via {@link com.microsoft.playwright.Browser#contexts Browser.contexts()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.chromium().connectOverCDP("http://localhost:9222");
|
||||
* BrowserContext defaultContext = browser.contexts().get(0);
|
||||
@@ -1200,7 +1235,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Returns the browser instance.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> You can use {@code ignoreDefaultArgs} to filter out {@code --mute-audio} from default arguments:
|
||||
* <pre>{@code
|
||||
@@ -1236,7 +1271,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Returns the browser instance.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> You can use {@code ignoreDefaultArgs} to filter out {@code --mute-audio} from default arguments:
|
||||
* <pre>{@code
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.google.gson.JsonObject;
|
||||
* <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>
|
||||
* </ul>
|
||||
* <pre>{@code
|
||||
* CDPSession client = page.context().newCDPSession(page);
|
||||
* client.send("Runtime.enable");
|
||||
@@ -45,7 +46,6 @@ import com.google.gson.JsonObject;
|
||||
* params.addProperty("playbackRate", playbackRate / 2);
|
||||
* client.send("Animation.setPlaybackRate", params);
|
||||
* }</pre>
|
||||
* </ul>
|
||||
*/
|
||||
public interface CDPSession {
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* 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.Date;
|
||||
|
||||
/**
|
||||
* Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/clock">clock emulation</a>.
|
||||
*
|
||||
* <p> Note that clock is installed for the entire {@code BrowserContext}, so the time in all the pages and iframes is
|
||||
* controlled by the same clock.
|
||||
*/
|
||||
public interface Clock {
|
||||
class InstallOptions {
|
||||
/**
|
||||
* Time to initialize with, current system time by default.
|
||||
*/
|
||||
public Object time;
|
||||
|
||||
/**
|
||||
* Time to initialize with, current system time by default.
|
||||
*/
|
||||
public InstallOptions setTime(long time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to initialize with, current system time by default.
|
||||
*/
|
||||
public InstallOptions setTime(String time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to initialize with, current system time by default.
|
||||
*/
|
||||
public InstallOptions setTime(Date time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user closing the
|
||||
* laptop lid for a while and reopening it later, after given time.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().fastForward(1000);
|
||||
* page.clock().fastForward("30:00");
|
||||
* }</pre>
|
||||
*
|
||||
* @param ticks Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08"
|
||||
* for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void fastForward(long ticks);
|
||||
/**
|
||||
* Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user closing the
|
||||
* laptop lid for a while and reopening it later, after given time.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().fastForward(1000);
|
||||
* page.clock().fastForward("30:00");
|
||||
* }</pre>
|
||||
*
|
||||
* @param ticks Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08"
|
||||
* for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void fastForward(String ticks);
|
||||
/**
|
||||
* Install fake implementations for the following time-related functions:
|
||||
* <ul>
|
||||
* <li> {@code Date}</li>
|
||||
* <li> {@code setTimeout}</li>
|
||||
* <li> {@code clearTimeout}</li>
|
||||
* <li> {@code setInterval}</li>
|
||||
* <li> {@code clearInterval}</li>
|
||||
* <li> {@code requestAnimationFrame}</li>
|
||||
* <li> {@code cancelAnimationFrame}</li>
|
||||
* <li> {@code requestIdleCallback}</li>
|
||||
* <li> {@code cancelIdleCallback}</li>
|
||||
* <li> {@code performance}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, and
|
||||
* control the behavior of time-dependent functions. See {@link com.microsoft.playwright.Clock#runFor Clock.runFor()} and
|
||||
* {@link com.microsoft.playwright.Clock#fastForward Clock.fastForward()} for more information.
|
||||
*
|
||||
* @since v1.45
|
||||
*/
|
||||
default void install() {
|
||||
install(null);
|
||||
}
|
||||
/**
|
||||
* Install fake implementations for the following time-related functions:
|
||||
* <ul>
|
||||
* <li> {@code Date}</li>
|
||||
* <li> {@code setTimeout}</li>
|
||||
* <li> {@code clearTimeout}</li>
|
||||
* <li> {@code setInterval}</li>
|
||||
* <li> {@code clearInterval}</li>
|
||||
* <li> {@code requestAnimationFrame}</li>
|
||||
* <li> {@code cancelAnimationFrame}</li>
|
||||
* <li> {@code requestIdleCallback}</li>
|
||||
* <li> {@code cancelIdleCallback}</li>
|
||||
* <li> {@code performance}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, and
|
||||
* control the behavior of time-dependent functions. See {@link com.microsoft.playwright.Clock#runFor Clock.runFor()} and
|
||||
* {@link com.microsoft.playwright.Clock#fastForward Clock.fastForward()} for more information.
|
||||
*
|
||||
* @since v1.45
|
||||
*/
|
||||
void install(InstallOptions options);
|
||||
/**
|
||||
* Advance the clock, firing all the time-related callbacks.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().runFor(1000);
|
||||
* page.clock().runFor("30:00");
|
||||
* }</pre>
|
||||
*
|
||||
* @param ticks Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08"
|
||||
* for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void runFor(long ticks);
|
||||
/**
|
||||
* Advance the clock, firing all the time-related callbacks.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().runFor(1000);
|
||||
* page.clock().runFor("30:00");
|
||||
* }</pre>
|
||||
*
|
||||
* @param ticks Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08"
|
||||
* for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void runFor(String ticks);
|
||||
/**
|
||||
* Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired unless
|
||||
* {@link com.microsoft.playwright.Clock#runFor Clock.runFor()}, {@link com.microsoft.playwright.Clock#fastForward
|
||||
* Clock.fastForward()}, {@link com.microsoft.playwright.Clock#pauseAt Clock.pauseAt()} or {@link
|
||||
* com.microsoft.playwright.Clock#resume Clock.resume()} is called.
|
||||
*
|
||||
* <p> Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it at
|
||||
* the specified time and pausing.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd");
|
||||
* page.clock().pauseAt(format.parse("2020-02-02"));
|
||||
* page.clock().pauseAt("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to pause at.
|
||||
* @since v1.45
|
||||
*/
|
||||
void pauseAt(long time);
|
||||
/**
|
||||
* Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired unless
|
||||
* {@link com.microsoft.playwright.Clock#runFor Clock.runFor()}, {@link com.microsoft.playwright.Clock#fastForward
|
||||
* Clock.fastForward()}, {@link com.microsoft.playwright.Clock#pauseAt Clock.pauseAt()} or {@link
|
||||
* com.microsoft.playwright.Clock#resume Clock.resume()} is called.
|
||||
*
|
||||
* <p> Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it at
|
||||
* the specified time and pausing.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd");
|
||||
* page.clock().pauseAt(format.parse("2020-02-02"));
|
||||
* page.clock().pauseAt("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to pause at.
|
||||
* @since v1.45
|
||||
*/
|
||||
void pauseAt(String time);
|
||||
/**
|
||||
* Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired unless
|
||||
* {@link com.microsoft.playwright.Clock#runFor Clock.runFor()}, {@link com.microsoft.playwright.Clock#fastForward
|
||||
* Clock.fastForward()}, {@link com.microsoft.playwright.Clock#pauseAt Clock.pauseAt()} or {@link
|
||||
* com.microsoft.playwright.Clock#resume Clock.resume()} is called.
|
||||
*
|
||||
* <p> Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it at
|
||||
* the specified time and pausing.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd");
|
||||
* page.clock().pauseAt(format.parse("2020-02-02"));
|
||||
* page.clock().pauseAt("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to pause at.
|
||||
* @since v1.45
|
||||
*/
|
||||
void pauseAt(Date time);
|
||||
/**
|
||||
* Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual.
|
||||
*
|
||||
* @since v1.45
|
||||
*/
|
||||
void resume();
|
||||
/**
|
||||
* Makes {@code Date.now} and {@code new Date()} return fixed fake time at all times, keeps all the timers running.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().setFixedTime(new Date());
|
||||
* page.clock().setFixedTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||
* page.clock().setFixedTime("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to be set in milliseconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void setFixedTime(long time);
|
||||
/**
|
||||
* Makes {@code Date.now} and {@code new Date()} return fixed fake time at all times, keeps all the timers running.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().setFixedTime(new Date());
|
||||
* page.clock().setFixedTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||
* page.clock().setFixedTime("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to be set in milliseconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void setFixedTime(String time);
|
||||
/**
|
||||
* Makes {@code Date.now} and {@code new Date()} return fixed fake time at all times, keeps all the timers running.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().setFixedTime(new Date());
|
||||
* page.clock().setFixedTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||
* page.clock().setFixedTime("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to be set in milliseconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void setFixedTime(Date time);
|
||||
/**
|
||||
* Sets current system time but does not trigger any timers.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().setSystemTime(new Date());
|
||||
* page.clock().setSystemTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||
* page.clock().setSystemTime("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to be set in milliseconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void setSystemTime(long time);
|
||||
/**
|
||||
* Sets current system time but does not trigger any timers.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().setSystemTime(new Date());
|
||||
* page.clock().setSystemTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||
* page.clock().setSystemTime("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to be set in milliseconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void setSystemTime(String time);
|
||||
/**
|
||||
* Sets current system time but does not trigger any timers.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.clock().setSystemTime(new Date());
|
||||
* page.clock().setSystemTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||
* page.clock().setSystemTime("2020-02-02");
|
||||
* }</pre>
|
||||
*
|
||||
* @param time Time to be set in milliseconds.
|
||||
* @since v1.45
|
||||
*/
|
||||
void setSystemTime(Date time);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ package com.microsoft.playwright;
|
||||
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.
|
||||
* {@code ConsoleMessage} objects are dispatched by page via the {@link com.microsoft.playwright.Page#onConsoleMessage
|
||||
* Page.onConsoleMessage()} event. For each console message 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.
|
||||
* page.onConsoleMessage(msg -> System.out.println(msg.text()));
|
||||
@@ -44,8 +45,8 @@ import java.util.*;
|
||||
*/
|
||||
public interface ConsoleMessage {
|
||||
/**
|
||||
* List of arguments passed to a {@code console} function call. See also {@link Page#onConsoleMessage
|
||||
* Page.onConsoleMessage()}.
|
||||
* List of arguments passed to a {@code console} function call. See also {@link
|
||||
* com.microsoft.playwright.Page#onConsoleMessage Page.onConsoleMessage()}.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,8 @@ package com.microsoft.playwright;
|
||||
|
||||
|
||||
/**
|
||||
* {@code Dialog} objects are dispatched by page via the {@link Page#onDialog Page.onDialog()} event.
|
||||
* {@code Dialog} objects are dispatched by page via the {@link com.microsoft.playwright.Page#onDialog Page.onDialog()}
|
||||
* event.
|
||||
*
|
||||
* <p> An example of using {@code Dialog} class:
|
||||
* <pre>{@code
|
||||
@@ -41,9 +42,9 @@ package com.microsoft.playwright;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Dialogs are dismissed automatically, unless there is a {@link Page#onDialog Page.onDialog()} listener. When listener is
|
||||
* present, it **must** either {@link Dialog#accept Dialog.accept()} or {@link Dialog#dismiss Dialog.dismiss()} the dialog
|
||||
* - otherwise the page will <a
|
||||
* <p> <strong>NOTE:</strong> Dialogs are dismissed automatically, unless there is a {@link com.microsoft.playwright.Page#onDialog Page.onDialog()}
|
||||
* listener. When listener is present, it **must** either {@link com.microsoft.playwright.Dialog#accept Dialog.accept()} or
|
||||
* {@link com.microsoft.playwright.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.
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,8 @@ import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* {@code Download} objects are dispatched by page via the {@link Page#onDownload Page.onDownload()} event.
|
||||
* {@code Download} objects are dispatched by page via the {@link com.microsoft.playwright.Page#onDownload
|
||||
* Page.onDownload()} event.
|
||||
*
|
||||
* <p> All the downloaded files belonging to the browser context are deleted when the browser context is closed.
|
||||
*
|
||||
@@ -72,8 +73,8 @@ public interface Download {
|
||||
* Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will
|
||||
* wait for the download to finish if necessary. The method throws when connected remotely.
|
||||
*
|
||||
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()}
|
||||
* to get suggested file name.
|
||||
* <p> Note that the download's file name is a random GUID, use {@link com.microsoft.playwright.Download#suggestedFilename
|
||||
* Download.suggestedFilename()} to get suggested file name.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -82,7 +83,7 @@ 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**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
|
||||
* }</pre>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,8 @@ import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* {@code FileChooser} objects are dispatched by the page in the {@link Page#onFileChooser Page.onFileChooser()} event.
|
||||
* {@code FileChooser} objects are dispatched by the page in the {@link com.microsoft.playwright.Page#onFileChooser
|
||||
* Page.onFileChooser()} event.
|
||||
* <pre>{@code
|
||||
* FileChooser fileChooser = page.waitForFileChooser(() -> page.getByText("Upload file").click());
|
||||
* fileChooser.setFiles(Paths.get("myfile.pdf"));
|
||||
@@ -29,22 +30,19 @@ import java.nio.file.Path;
|
||||
public interface FileChooser {
|
||||
class SetFilesOptions {
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
* @deprecated This option has no effect.
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
* @deprecated This option has no effect.
|
||||
*/
|
||||
public SetFilesOptions setNoWaitAfter(boolean noWaitAfter) {
|
||||
this.noWaitAfter = noWaitAfter;
|
||||
@@ -52,8 +50,9 @@ public interface FileChooser {
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public SetFilesOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,14 +21,15 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* FrameLocator represents a view to the {@code iframe} on the page. It captures the logic sufficient to retrieve the
|
||||
* {@code iframe} and locate elements in that iframe. FrameLocator can be created with either {@link Page#frameLocator
|
||||
* Page.frameLocator()} or {@link Locator#frameLocator Locator.frameLocator()} method.
|
||||
* {@code iframe} and locate elements in that iframe. FrameLocator can be created with either {@link
|
||||
* com.microsoft.playwright.Page#frameLocator Page.frameLocator()} or {@link com.microsoft.playwright.Locator#frameLocator
|
||||
* Locator.frameLocator()} method.
|
||||
* <pre>{@code
|
||||
* Locator locator = page.frameLocator("#my-frame").getByText("Submit");
|
||||
* locator.click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Strictness**
|
||||
* <p> <strong>Strictness</strong>
|
||||
*
|
||||
* <p> Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches
|
||||
* a given selector.
|
||||
@@ -40,13 +41,15 @@ import java.util.regex.Pattern;
|
||||
* page.frame_locator(".result-frame").first().getByRole(AriaRole.BUTTON).click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Converting Locator to FrameLocator**
|
||||
* <p> <strong>Converting Locator to FrameLocator</strong>
|
||||
*
|
||||
* <p> If you have a {@code Locator} object pointing to an {@code iframe} it can be converted to {@code FrameLocator} using <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/:scope">{@code :scope}</a> CSS selector:
|
||||
* <pre>{@code
|
||||
* Locator frameLocator = locator.frameLocator(':scope');
|
||||
* }</pre>
|
||||
* <p> If you have a {@code Locator} object pointing to an {@code iframe} it can be converted to {@code FrameLocator} using
|
||||
* {@link com.microsoft.playwright.Locator#contentFrame Locator.contentFrame()}.
|
||||
*
|
||||
* <p> <strong>Converting FrameLocator to Locator</strong>
|
||||
*
|
||||
* <p> If you have a {@code FrameLocator} object it can be converted to {@code Locator} pointing to the same {@code iframe}
|
||||
* using {@link com.microsoft.playwright.FrameLocator#owner FrameLocator.owner()}.
|
||||
*/
|
||||
public interface FrameLocator {
|
||||
class GetByAltTextOptions {
|
||||
@@ -396,7 +399,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
@@ -412,7 +415,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
@@ -426,7 +429,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
@@ -442,7 +445,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their alt text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find the image by alt text "Playwright logo":
|
||||
* <pre>{@code
|
||||
@@ -457,7 +460,7 @@ public interface FrameLocator {
|
||||
* 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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
@@ -475,7 +478,7 @@ public interface FrameLocator {
|
||||
* 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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
@@ -491,7 +494,7 @@ public interface FrameLocator {
|
||||
* 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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
@@ -509,7 +512,7 @@ public interface FrameLocator {
|
||||
* 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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
@@ -524,7 +527,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
@@ -542,7 +545,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
@@ -558,7 +561,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
@@ -576,7 +579,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating input elements by the placeholder text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, consider the following DOM structure.
|
||||
*
|
||||
@@ -594,7 +597,7 @@ public interface FrameLocator {
|
||||
* 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>.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -615,7 +618,7 @@ public interface FrameLocator {
|
||||
* .click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the
|
||||
* ARIA guidelines.
|
||||
@@ -637,7 +640,7 @@ public interface FrameLocator {
|
||||
* 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>.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -658,7 +661,7 @@ public interface FrameLocator {
|
||||
* .click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the
|
||||
* ARIA guidelines.
|
||||
@@ -676,7 +679,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Locate element by the test id.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -685,10 +688,11 @@ public interface FrameLocator {
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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.
|
||||
* <p> By default, the {@code data-testid} attribute is used as a test id. Use {@link
|
||||
* com.microsoft.playwright.Selectors#setTestIdAttribute Selectors.setTestIdAttribute()} to configure a different test id
|
||||
* attribute if necessary.
|
||||
*
|
||||
* @param testId Id to locate the element by.
|
||||
* @since v1.27
|
||||
@@ -697,7 +701,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Locate element by the test id.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -706,10 +710,11 @@ public interface FrameLocator {
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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.
|
||||
* <p> By default, the {@code data-testid} attribute is used as a test id. Use {@link
|
||||
* com.microsoft.playwright.Selectors#setTestIdAttribute Selectors.setTestIdAttribute()} to configure a different test id
|
||||
* attribute if necessary.
|
||||
*
|
||||
* @param testId Id to locate the element by.
|
||||
* @since v1.27
|
||||
@@ -718,10 +723,10 @@ public interface FrameLocator {
|
||||
/**
|
||||
* 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> See also {@link com.microsoft.playwright.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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
*
|
||||
@@ -743,7 +748,7 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> 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.
|
||||
@@ -760,10 +765,10 @@ public interface FrameLocator {
|
||||
/**
|
||||
* 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> See also {@link com.microsoft.playwright.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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
*
|
||||
@@ -785,7 +790,7 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> 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.
|
||||
@@ -800,10 +805,10 @@ public interface FrameLocator {
|
||||
/**
|
||||
* 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> See also {@link com.microsoft.playwright.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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
*
|
||||
@@ -825,7 +830,7 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> 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.
|
||||
@@ -842,10 +847,10 @@ public interface FrameLocator {
|
||||
/**
|
||||
* 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> See also {@link com.microsoft.playwright.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> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure:
|
||||
*
|
||||
@@ -867,7 +872,7 @@ public interface FrameLocator {
|
||||
* page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> 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.
|
||||
@@ -882,7 +887,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -900,7 +905,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -916,7 +921,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -934,7 +939,7 @@ public interface FrameLocator {
|
||||
/**
|
||||
* Allows locating elements by their title attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
@@ -955,7 +960,7 @@ public interface FrameLocator {
|
||||
FrameLocator last();
|
||||
/**
|
||||
* 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.
|
||||
* similar to {@link com.microsoft.playwright.Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
@@ -967,7 +972,7 @@ public interface FrameLocator {
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
* similar to {@link com.microsoft.playwright.Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
@@ -977,7 +982,7 @@ public interface FrameLocator {
|
||||
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.
|
||||
* similar to {@link com.microsoft.playwright.Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
@@ -989,7 +994,7 @@ public interface FrameLocator {
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
* similar to {@link com.microsoft.playwright.Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
@@ -1003,5 +1008,24 @@ public interface FrameLocator {
|
||||
* @since v1.17
|
||||
*/
|
||||
FrameLocator nth(int index);
|
||||
/**
|
||||
* Returns a {@code Locator} object pointing to the same {@code iframe} as this frame locator.
|
||||
*
|
||||
* <p> Useful when you have a {@code FrameLocator} object obtained somewhere, and later on would like to interact with the
|
||||
* {@code iframe} element.
|
||||
*
|
||||
* <p> For a reverse operation, use {@link com.microsoft.playwright.Locator#contentFrame Locator.contentFrame()}.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* FrameLocator frameLocator = page.frameLocator("iframe[name=\"embedded\"]");
|
||||
* // ...
|
||||
* Locator locator = frameLocator.owner();
|
||||
* assertThat(locator).isVisible();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.43
|
||||
*/
|
||||
Locator owner();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,19 +19,20 @@ package com.microsoft.playwright;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* JSHandle represents an in-page JavaScript object. JSHandles can be created with the {@link Page#evaluateHandle
|
||||
* Page.evaluateHandle()} method.
|
||||
* JSHandle represents an in-page JavaScript object. JSHandles can be created with the {@link
|
||||
* com.microsoft.playwright.Page#evaluateHandle Page.evaluateHandle()} method.
|
||||
* <pre>{@code
|
||||
* JSHandle windowHandle = page.evaluateHandle("() => window");
|
||||
* // ...
|
||||
* }</pre>
|
||||
*
|
||||
* <p> JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with {@link
|
||||
* JSHandle#dispose JSHandle.dispose()}. JSHandles are auto-disposed when their origin frame gets navigated or the parent
|
||||
* context gets destroyed.
|
||||
* com.microsoft.playwright.JSHandle#dispose JSHandle.dispose()}. JSHandles are auto-disposed when their origin frame gets
|
||||
* navigated or the parent context gets destroyed.
|
||||
*
|
||||
* <p> JSHandle instances can be used as an argument in {@link Page#evalOnSelector Page.evalOnSelector()}, {@link Page#evaluate
|
||||
* Page.evaluate()} and {@link Page#evaluateHandle Page.evaluateHandle()} methods.
|
||||
* <p> JSHandle instances can be used as an argument in {@link com.microsoft.playwright.Page#evalOnSelector
|
||||
* Page.evalOnSelector()}, {@link com.microsoft.playwright.Page#evaluate Page.evaluate()} and {@link
|
||||
* com.microsoft.playwright.Page#evaluateHandle Page.evaluateHandle()} methods.
|
||||
*/
|
||||
public interface JSHandle {
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public interface JSHandle {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@code
|
||||
* handle.evaluate} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* ElementHandle tweetHandle = page.querySelector(".tweet .retweets");
|
||||
* assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
|
||||
@@ -77,7 +78,7 @@ public interface JSHandle {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@code
|
||||
* handle.evaluate} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* ElementHandle tweetHandle = page.querySelector(".tweet .retweets");
|
||||
* assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
|
||||
@@ -101,7 +102,7 @@ public interface JSHandle {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@code
|
||||
* jsHandle.evaluateHandle} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> See {@link Page#evaluateHandle Page.evaluateHandle()} for more details.
|
||||
* <p> See {@link com.microsoft.playwright.Page#evaluateHandle Page.evaluateHandle()} for more details.
|
||||
*
|
||||
* @param expression JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
|
||||
* automatically invoked.
|
||||
@@ -122,7 +123,7 @@ public interface JSHandle {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@code
|
||||
* jsHandle.evaluateHandle} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> See {@link Page#evaluateHandle Page.evaluateHandle()} for more details.
|
||||
* <p> See {@link com.microsoft.playwright.Page#evaluateHandle Page.evaluateHandle()} for more details.
|
||||
*
|
||||
* @param expression JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
|
||||
* automatically invoked.
|
||||
@@ -133,7 +134,7 @@ public interface JSHandle {
|
||||
/**
|
||||
* The method returns a map with **own property names** as keys and JSHandle instances for the property values.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* JSHandle handle = page.evaluateHandle("() => ({ window, document })");
|
||||
* Map<String, JSHandle> properties = handle.getProperties();
|
||||
|
||||
@@ -19,12 +19,13 @@ package com.microsoft.playwright;
|
||||
import com.microsoft.playwright.options.*;
|
||||
|
||||
/**
|
||||
* Keyboard provides an api for managing a virtual keyboard. The high level api is {@link Keyboard#type Keyboard.type()},
|
||||
* which takes raw characters and generates proper {@code keydown}, {@code keypress}/{@code input}, and {@code keyup}
|
||||
* events on your page.
|
||||
* Keyboard provides an api for managing a virtual keyboard. The high level api is {@link
|
||||
* com.microsoft.playwright.Keyboard#type Keyboard.type()}, which takes raw characters and generates proper {@code
|
||||
* keydown}, {@code keypress}/{@code input}, and {@code keyup} events on your page.
|
||||
*
|
||||
* <p> For finer control, you can use {@link Keyboard#down Keyboard.down()}, {@link Keyboard#up Keyboard.up()}, and {@link
|
||||
* Keyboard#insertText Keyboard.insertText()} to manually fire events as if they were generated from a real keyboard.
|
||||
* <p> For finer control, you can use {@link com.microsoft.playwright.Keyboard#down Keyboard.down()}, {@link
|
||||
* com.microsoft.playwright.Keyboard#up Keyboard.up()}, and {@link com.microsoft.playwright.Keyboard#insertText
|
||||
* Keyboard.insertText()} to manually fire events as if they were generated from a real keyboard.
|
||||
*
|
||||
* <p> An example of holding down {@code Shift} in order to select and delete some text:
|
||||
* <pre>{@code
|
||||
@@ -96,7 +97,8 @@ public interface Keyboard {
|
||||
* ArrowUp}, etc.
|
||||
*
|
||||
* <p> Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code
|
||||
* ShiftLeft}.
|
||||
* ShiftLeft}, {@code ControlOrMeta}. {@code ControlOrMeta} resolves to {@code Control} on Windows and Linux and to {@code
|
||||
* Meta} on macOS.
|
||||
*
|
||||
* <p> Holding down {@code Shift} will type the text that corresponds to the {@code key} in the upper case.
|
||||
*
|
||||
@@ -104,11 +106,12 @@ public interface Keyboard {
|
||||
* different respective texts.
|
||||
*
|
||||
* <p> If {@code key} is a modifier key, {@code Shift}, {@code Meta}, {@code Control}, or {@code Alt}, subsequent key presses
|
||||
* will be sent with that modifier active. To release the modifier key, use {@link Keyboard#up Keyboard.up()}.
|
||||
* will be sent with that modifier active. To release the modifier key, use {@link com.microsoft.playwright.Keyboard#up
|
||||
* Keyboard.up()}.
|
||||
*
|
||||
* <p> After the key is pressed once, subsequent calls to {@link Keyboard#down Keyboard.down()} will have <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat">repeat</a> set to true. To release the key,
|
||||
* use {@link Keyboard#up Keyboard.up()}.
|
||||
* <p> After the key is pressed once, subsequent calls to {@link com.microsoft.playwright.Keyboard#down Keyboard.down()} will
|
||||
* have <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat">repeat</a> set to true. To release
|
||||
* the key, use {@link com.microsoft.playwright.Keyboard#up Keyboard.up()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Modifier keys DO influence {@code keyboard.down}. Holding down {@code Shift} will type the text in upper case.
|
||||
*
|
||||
@@ -119,7 +122,7 @@ public interface Keyboard {
|
||||
/**
|
||||
* Dispatches only {@code input} event, does not emit the {@code keydown}, {@code keyup} or {@code keypress} events.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.keyboard().insertText("嗨");
|
||||
* }</pre>
|
||||
@@ -132,7 +135,7 @@ public interface Keyboard {
|
||||
*/
|
||||
void insertText(String text);
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link com.microsoft.playwright.Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@code key} can specify the intended <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
|
||||
@@ -145,7 +148,8 @@ public interface Keyboard {
|
||||
* ArrowUp}, etc.
|
||||
*
|
||||
* <p> Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code
|
||||
* ShiftLeft}.
|
||||
* ShiftLeft}, {@code ControlOrMeta}. {@code ControlOrMeta} resolves to {@code Control} on Windows and Linux and to {@code
|
||||
* Meta} on macOS.
|
||||
*
|
||||
* <p> Holding down {@code Shift} will type the text that corresponds to the {@code key} in the upper case.
|
||||
*
|
||||
@@ -155,7 +159,7 @@ public interface Keyboard {
|
||||
* <p> Shortcuts such as {@code key: "Control+o"}, {@code key: "Control++} or {@code key: "Control+Shift+T"} are supported as
|
||||
* well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Page page = browser.newPage();
|
||||
* page.navigate("https://keycode.info");
|
||||
@@ -168,7 +172,8 @@ public interface Keyboard {
|
||||
* browser.close();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Shortcut for {@link Keyboard#down Keyboard.down()} and {@link Keyboard#up Keyboard.up()}.
|
||||
* <p> Shortcut for {@link com.microsoft.playwright.Keyboard#down Keyboard.down()} and {@link
|
||||
* com.microsoft.playwright.Keyboard#up Keyboard.up()}.
|
||||
*
|
||||
* @param key Name of the key to press or a character to generate, such as {@code ArrowLeft} or {@code a}.
|
||||
* @since v1.8
|
||||
@@ -177,7 +182,7 @@ public interface Keyboard {
|
||||
press(key, null);
|
||||
}
|
||||
/**
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link com.microsoft.playwright.Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@code key} can specify the intended <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
|
||||
@@ -190,7 +195,8 @@ public interface Keyboard {
|
||||
* ArrowUp}, etc.
|
||||
*
|
||||
* <p> Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code
|
||||
* ShiftLeft}.
|
||||
* ShiftLeft}, {@code ControlOrMeta}. {@code ControlOrMeta} resolves to {@code Control} on Windows and Linux and to {@code
|
||||
* Meta} on macOS.
|
||||
*
|
||||
* <p> Holding down {@code Shift} will type the text that corresponds to the {@code key} in the upper case.
|
||||
*
|
||||
@@ -200,7 +206,7 @@ public interface Keyboard {
|
||||
* <p> Shortcuts such as {@code key: "Control+o"}, {@code key: "Control++} or {@code key: "Control+Shift+T"} are supported as
|
||||
* well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Page page = browser.newPage();
|
||||
* page.navigate("https://keycode.info");
|
||||
@@ -213,22 +219,24 @@ public interface Keyboard {
|
||||
* browser.close();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Shortcut for {@link Keyboard#down Keyboard.down()} and {@link Keyboard#up Keyboard.up()}.
|
||||
* <p> Shortcut for {@link com.microsoft.playwright.Keyboard#down Keyboard.down()} and {@link
|
||||
* com.microsoft.playwright.Keyboard#up Keyboard.up()}.
|
||||
*
|
||||
* @param key Name of the key to press or a character to generate, such as {@code ArrowLeft} or {@code a}.
|
||||
* @since v1.8
|
||||
*/
|
||||
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()}.
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link com.microsoft.playwright.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
|
||||
* com.microsoft.playwright.Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link com.microsoft.playwright.Keyboard#press
|
||||
* Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* page.keyboard().type("Hello");
|
||||
@@ -247,15 +255,16 @@ 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()}.
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link com.microsoft.playwright.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
|
||||
* com.microsoft.playwright.Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link com.microsoft.playwright.Keyboard#press
|
||||
* Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* page.keyboard().type("Hello");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@ import com.microsoft.playwright.options.*;
|
||||
/**
|
||||
* The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
|
||||
*
|
||||
* <p> Every {@code page} object has its own Mouse, accessible with {@link Page#mouse Page.mouse()}.
|
||||
* <p> Every {@code page} object has its own Mouse, accessible with {@link com.microsoft.playwright.Page#mouse Page.mouse()}.
|
||||
* <pre>{@code
|
||||
* // Using ‘page.mouse’ to trace a 100x100 square.
|
||||
* page.mouse().move(0, 0);
|
||||
@@ -160,32 +160,44 @@ public interface Mouse {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Shortcut for {@link Mouse#move Mouse.move()}, {@link Mouse#down Mouse.down()}, {@link Mouse#up Mouse.up()}.
|
||||
* Shortcut for {@link com.microsoft.playwright.Mouse#move Mouse.move()}, {@link com.microsoft.playwright.Mouse#down
|
||||
* Mouse.down()}, {@link com.microsoft.playwright.Mouse#up Mouse.up()}.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void click(double x, double y) {
|
||||
click(x, y, null);
|
||||
}
|
||||
/**
|
||||
* Shortcut for {@link Mouse#move Mouse.move()}, {@link Mouse#down Mouse.down()}, {@link Mouse#up Mouse.up()}.
|
||||
* Shortcut for {@link com.microsoft.playwright.Mouse#move Mouse.move()}, {@link com.microsoft.playwright.Mouse#down
|
||||
* Mouse.down()}, {@link com.microsoft.playwright.Mouse#up Mouse.up()}.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
void click(double x, double y, ClickOptions options);
|
||||
/**
|
||||
* Shortcut for {@link Mouse#move Mouse.move()}, {@link Mouse#down Mouse.down()}, {@link Mouse#up Mouse.up()}, {@link
|
||||
* Mouse#down Mouse.down()} and {@link Mouse#up Mouse.up()}.
|
||||
* Shortcut for {@link com.microsoft.playwright.Mouse#move Mouse.move()}, {@link com.microsoft.playwright.Mouse#down
|
||||
* Mouse.down()}, {@link com.microsoft.playwright.Mouse#up Mouse.up()}, {@link com.microsoft.playwright.Mouse#down
|
||||
* Mouse.down()} and {@link com.microsoft.playwright.Mouse#up Mouse.up()}.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void dblclick(double x, double y) {
|
||||
dblclick(x, y, null);
|
||||
}
|
||||
/**
|
||||
* Shortcut for {@link Mouse#move Mouse.move()}, {@link Mouse#down Mouse.down()}, {@link Mouse#up Mouse.up()}, {@link
|
||||
* Mouse#down Mouse.down()} and {@link Mouse#up Mouse.up()}.
|
||||
* Shortcut for {@link com.microsoft.playwright.Mouse#move Mouse.move()}, {@link com.microsoft.playwright.Mouse#down
|
||||
* Mouse.down()}, {@link com.microsoft.playwright.Mouse#up Mouse.up()}, {@link com.microsoft.playwright.Mouse#down
|
||||
* Mouse.down()} and {@link com.microsoft.playwright.Mouse#up Mouse.up()}.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
void dblclick(double x, double y, DblclickOptions options);
|
||||
@@ -206,6 +218,8 @@ public interface Mouse {
|
||||
/**
|
||||
* Dispatches a {@code mousemove} event.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void move(double x, double y) {
|
||||
@@ -214,6 +228,8 @@ public interface Mouse {
|
||||
/**
|
||||
* Dispatches a {@code mousemove} event.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
void move(double x, double y, MoveOptions options);
|
||||
@@ -232,7 +248,8 @@ public interface Mouse {
|
||||
*/
|
||||
void up(UpOptions options);
|
||||
/**
|
||||
* Dispatches a {@code wheel} event.
|
||||
* Dispatches a {@code wheel} event. This method is usually used to manually scroll the page. See <a
|
||||
* href="https://playwright.dev/java/docs/input#scrolling">scrolling</a> for alternative ways to scroll.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish
|
||||
* before returning.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -94,8 +94,8 @@ public interface Playwright extends AutoCloseable {
|
||||
*/
|
||||
void close();
|
||||
/**
|
||||
* Launches new Playwright driver process and connects to it. {@link Playwright#close Playwright.close()} should be called
|
||||
* when the instance is no longer needed.
|
||||
* Launches new Playwright driver process and connects to it. {@link com.microsoft.playwright.Playwright#close
|
||||
* Playwright.close()} should be called when the instance is no longer needed.
|
||||
* <pre>{@code
|
||||
* Playwright playwright = Playwright.create();
|
||||
* Browser browser = playwright.webkit().launch();
|
||||
|
||||
@@ -22,14 +22,15 @@ import java.util.*;
|
||||
/**
|
||||
* Whenever the page sends a request for a network resource the following sequence of events are emitted by {@code Page}:
|
||||
* <ul>
|
||||
* <li> {@link Page#onRequest Page.onRequest()} emitted when the request is issued by the page.</li>
|
||||
* <li> {@link Page#onResponse Page.onResponse()} emitted when/if the response status and headers are received for the request.</li>
|
||||
* <li> {@link Page#onRequestFinished Page.onRequestFinished()} emitted when the response body is downloaded and the request is
|
||||
* complete.</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#onRequest Page.onRequest()} emitted when the request is issued by the page.</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#onResponse Page.onResponse()} emitted when/if the response status and headers are
|
||||
* received for the request.</li>
|
||||
* <li> {@link com.microsoft.playwright.Page#onRequestFinished Page.onRequestFinished()} emitted when the response body is
|
||||
* downloaded and the request is complete.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> If request fails at some point, then instead of {@code "requestfinished"} event (and possibly instead of 'response'
|
||||
* event), the {@link Page#onRequestFailed Page.onRequestFailed()} event is emitted.
|
||||
* event), the {@link com.microsoft.playwright.Page#onRequestFailed Page.onRequestFailed()} event is emitted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
|
||||
* with {@code "requestfinished"} event.
|
||||
@@ -47,7 +48,7 @@ public interface Request {
|
||||
/**
|
||||
* The method returns {@code null} unless this request has failed, as reported by {@code requestfailed} event.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Example of logging of all the failed requests:
|
||||
* <pre>{@code
|
||||
@@ -62,18 +63,18 @@ public interface Request {
|
||||
/**
|
||||
* Returns the {@code Frame} that initiated this request.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* String frameUrl = request.frame().url();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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>
|
||||
* com.microsoft.playwright.Request#isNavigationRequest Request.isNavigationRequest()} to check that.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Here is an example that handles all the cases:
|
||||
@@ -83,22 +84,22 @@ public interface Request {
|
||||
Frame frame();
|
||||
/**
|
||||
* An object with the request HTTP headers. The header names are lower-cased. Note that this method does not return
|
||||
* security-related headers, including cookie-related ones. You can use {@link Request#allHeaders Request.allHeaders()} for
|
||||
* complete list of headers that include {@code cookie} information.
|
||||
* security-related headers, including cookie-related ones. You can use {@link com.microsoft.playwright.Request#allHeaders
|
||||
* Request.allHeaders()} for complete list of headers that include {@code cookie} information.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
Map<String, String> headers();
|
||||
/**
|
||||
* An array with all the request HTTP headers associated with this request. Unlike {@link Request#allHeaders
|
||||
* Request.allHeaders()}, header names are NOT lower-cased. Headers with multiple entries, such as {@code Set-Cookie},
|
||||
* appear in the array multiple times.
|
||||
* An array with all the request HTTP headers associated with this request. Unlike {@link
|
||||
* com.microsoft.playwright.Request#allHeaders Request.allHeaders()}, header names are NOT lower-cased. Headers with
|
||||
* multiple entries, such as {@code Set-Cookie}, appear in the array multiple times.
|
||||
*
|
||||
* @since v1.15
|
||||
*/
|
||||
List<HttpHeader> headersArray();
|
||||
/**
|
||||
* Returns the value of the header matching the name. The name is case insensitive.
|
||||
* Returns the value of the header matching the name. The name is case-insensitive.
|
||||
*
|
||||
* @param name Name of the header.
|
||||
* @since v1.15
|
||||
@@ -108,7 +109,7 @@ 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.
|
||||
* com.microsoft.playwright.Request#frame Request.frame()} available.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -138,7 +139,7 @@ public interface Request {
|
||||
* connected by {@code redirectedFrom()} and {@code redirectedTo()} methods. When multiple server redirects has happened,
|
||||
* it is possible to construct the whole redirect chain by repeatedly calling {@code redirectedFrom()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, if the website {@code http://example.com} redirects to {@code https://example.com}:
|
||||
* <pre>{@code
|
||||
@@ -158,9 +159,9 @@ public interface Request {
|
||||
/**
|
||||
* New request issued by the browser if the server responded with redirect.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> This method is the opposite of {@link Request#redirectedFrom Request.redirectedFrom()}:
|
||||
* <p> This method is the opposite of {@link com.microsoft.playwright.Request#redirectedFrom Request.redirectedFrom()}:
|
||||
* <pre>{@code
|
||||
* System.out.println(request.redirectedFrom().redirectedTo() == request); // true
|
||||
* }</pre>
|
||||
@@ -193,7 +194,7 @@ public interface Request {
|
||||
* {@code responseEnd} becomes available when request finishes. Find more information at <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming">Resource Timing API</a>.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.onRequestFinished(request -> {
|
||||
* Timing timing = request.timing();
|
||||
|
||||
@@ -56,22 +56,22 @@ public interface Response {
|
||||
boolean fromServiceWorker();
|
||||
/**
|
||||
* An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return
|
||||
* security-related headers, including cookie-related ones. You can use {@link Response#allHeaders Response.allHeaders()}
|
||||
* for complete list of headers that include {@code cookie} information.
|
||||
* security-related headers, including cookie-related ones. You can use {@link com.microsoft.playwright.Response#allHeaders
|
||||
* Response.allHeaders()} for complete list of headers that include {@code cookie} information.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
Map<String, String> headers();
|
||||
/**
|
||||
* An array with all the request HTTP headers associated with this response. Unlike {@link Response#allHeaders
|
||||
* Response.allHeaders()}, header names are NOT lower-cased. Headers with multiple entries, such as {@code Set-Cookie},
|
||||
* appear in the array multiple times.
|
||||
* An array with all the request HTTP headers associated with this response. Unlike {@link
|
||||
* com.microsoft.playwright.Response#allHeaders Response.allHeaders()}, header names are NOT lower-cased. Headers with
|
||||
* multiple entries, such as {@code Set-Cookie}, appear in the array multiple times.
|
||||
*
|
||||
* @since v1.15
|
||||
*/
|
||||
List<HttpHeader> headersArray();
|
||||
/**
|
||||
* Returns the value of the header matching the name. The name is case insensitive. If multiple headers have the same name
|
||||
* Returns the value of the header matching the name. The name is case-insensitive. If multiple headers have the same name
|
||||
* (except {@code set-cookie}), they are returned as a list separated by {@code , }. For {@code set-cookie}, the {@code \n}
|
||||
* separator is used. If no headers are found, {@code null} is returned.
|
||||
*
|
||||
@@ -80,7 +80,7 @@ public interface Response {
|
||||
*/
|
||||
String headerValue(String name);
|
||||
/**
|
||||
* Returns all values of the headers matching the name, for example {@code set-cookie}. The name is case insensitive.
|
||||
* Returns all values of the headers matching the name, for example {@code set-cookie}. The name is case-insensitive.
|
||||
*
|
||||
* @param name Name of the header.
|
||||
* @since v1.15
|
||||
|
||||
@@ -20,8 +20,9 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Whenever a network route is set up with {@link Page#route Page.route()} or {@link BrowserContext#route
|
||||
* BrowserContext.route()}, the {@code Route} object allows to handle the route.
|
||||
* Whenever a network route is set up with {@link com.microsoft.playwright.Page#route Page.route()} or {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}, the {@code Route} object allows to handle the
|
||||
* route.
|
||||
*
|
||||
* <p> Learn more about <a href="https://playwright.dev/java/docs/network">networking</a>.
|
||||
*/
|
||||
@@ -146,6 +147,12 @@ public interface Route {
|
||||
* exceeded. Defaults to {@code 20}. Pass {@code 0} to not follow redirects.
|
||||
*/
|
||||
public Integer maxRedirects;
|
||||
/**
|
||||
* Maximum number of times network errors should be retried. Currently only {@code ECONNRESET} error is retried. Does not
|
||||
* retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to {@code 0} - no
|
||||
* retries.
|
||||
*/
|
||||
public Integer maxRetries;
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
@@ -178,6 +185,15 @@ public interface Route {
|
||||
this.maxRedirects = maxRedirects;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum number of times network errors should be retried. Currently only {@code ECONNRESET} error is retried. Does not
|
||||
* retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to {@code 0} - no
|
||||
* retries.
|
||||
*/
|
||||
public FetchOptions setMaxRetries(int maxRetries) {
|
||||
this.maxRetries = maxRetries;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
@@ -332,9 +348,9 @@ public interface Route {
|
||||
*/
|
||||
void abort(String errorCode);
|
||||
/**
|
||||
* Continues route's request with optional overrides.
|
||||
* Sends route's request to the network with optional overrides.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Override headers
|
||||
@@ -345,12 +361,16 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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.
|
||||
* through redirects, use the combination of {@link com.microsoft.playwright.Route#fetch Route.fetch()} and {@link
|
||||
* com.microsoft.playwright.Route#fulfill Route.fulfill()} instead.
|
||||
*
|
||||
* <p> {@link com.microsoft.playwright.Route#resume Route.resume()} will immediately send the request to the network, other
|
||||
* matching handlers won't be invoked. Use {@link com.microsoft.playwright.Route#fallback Route.fallback()} If you want
|
||||
* next matching handler in the chain to be invoked.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -358,9 +378,9 @@ public interface Route {
|
||||
resume(null);
|
||||
}
|
||||
/**
|
||||
* Continues route's request with optional overrides.
|
||||
* Sends route's request to the network with optional overrides.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Override headers
|
||||
@@ -371,23 +391,30 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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.
|
||||
* through redirects, use the combination of {@link com.microsoft.playwright.Route#fetch Route.fetch()} and {@link
|
||||
* com.microsoft.playwright.Route#fulfill Route.fulfill()} instead.
|
||||
*
|
||||
* <p> {@link com.microsoft.playwright.Route#resume Route.resume()} will immediately send the request to the network, other
|
||||
* matching handlers won't be invoked. Use {@link com.microsoft.playwright.Route#fallback Route.fallback()} If you want
|
||||
* next matching handler in the chain to be invoked.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void resume(ResumeOptions options);
|
||||
/**
|
||||
* When several routes match the given pattern, they run in the order opposite to their registration. That way the last
|
||||
* Continues route's request with optional overrides. The method is similar to {@link com.microsoft.playwright.Route#resume
|
||||
* Route.resume()} with the difference that other matching handlers will be invoked before sending the request.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> When several routes match the given pattern, they run in the order opposite to their registration. That way the last
|
||||
* registered route can always override all the previous ones. In the example below, request will be handled by the
|
||||
* bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first
|
||||
* registered route.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Runs last.
|
||||
@@ -441,18 +468,24 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Use {@link com.microsoft.playwright.Route#resume Route.resume()} to immediately send the request to the network, other
|
||||
* matching handlers won't be invoked in that case.
|
||||
*
|
||||
* @since v1.23
|
||||
*/
|
||||
default void fallback() {
|
||||
fallback(null);
|
||||
}
|
||||
/**
|
||||
* When several routes match the given pattern, they run in the order opposite to their registration. That way the last
|
||||
* Continues route's request with optional overrides. The method is similar to {@link com.microsoft.playwright.Route#resume
|
||||
* Route.resume()} with the difference that other matching handlers will be invoked before sending the request.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> When several routes match the given pattern, they run in the order opposite to their registration. That way the last
|
||||
* registered route can always override all the previous ones. In the example below, request will be handled by the
|
||||
* bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first
|
||||
* registered route.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Runs last.
|
||||
@@ -506,6 +539,9 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> Use {@link com.microsoft.playwright.Route#resume Route.resume()} to immediately send the request to the network, other
|
||||
* matching handlers won't be invoked in that case.
|
||||
*
|
||||
* @since v1.23
|
||||
*/
|
||||
void fallback(FallbackOptions options);
|
||||
@@ -513,7 +549,7 @@ public interface Route {
|
||||
* Performs the request and fetches result without fulfilling it, so that the response could be modified and then
|
||||
* fulfilled.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.route("https://dog.ceo/api/breeds/list/all", route -> {
|
||||
* APIResponse response = route.fetch();
|
||||
@@ -526,11 +562,11 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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.
|
||||
* to only apply {@code headers} to the original request, but not to redirects, look into {@link
|
||||
* com.microsoft.playwright.Route#resume Route.resume()} instead.
|
||||
*
|
||||
* @since v1.29
|
||||
*/
|
||||
@@ -541,7 +577,7 @@ public interface Route {
|
||||
* Performs the request and fetches result without fulfilling it, so that the response could be modified and then
|
||||
* fulfilled.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.route("https://dog.ceo/api/breeds/list/all", route -> {
|
||||
* APIResponse response = route.fetch();
|
||||
@@ -554,11 +590,11 @@ public interface Route {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <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.
|
||||
* to only apply {@code headers} to the original request, but not to redirects, look into {@link
|
||||
* com.microsoft.playwright.Route#resume Route.resume()} instead.
|
||||
*
|
||||
* @since v1.29
|
||||
*/
|
||||
@@ -566,7 +602,7 @@ public interface Route {
|
||||
/**
|
||||
* Fulfills route's request with given response.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of fulfilling all requests with 404 responses:
|
||||
* <pre>{@code
|
||||
@@ -592,7 +628,7 @@ public interface Route {
|
||||
/**
|
||||
* Fulfills route's request with given response.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of fulfilling all requests with 404 responses:
|
||||
* <pre>{@code
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface Selectors {
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -84,7 +84,7 @@ public interface Selectors {
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -122,7 +122,7 @@ public interface Selectors {
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -162,7 +162,7 @@ public interface Selectors {
|
||||
/**
|
||||
* Selectors must be registered before creating the page.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
@@ -198,8 +198,8 @@ public interface Selectors {
|
||||
*/
|
||||
void register(String name, Path script, RegisterOptions options);
|
||||
/**
|
||||
* Defines custom attribute name to be used in {@link Page#getByTestId Page.getByTestId()}. {@code data-testid} is used by
|
||||
* default.
|
||||
* Defines custom attribute name to be used in {@link com.microsoft.playwright.Page#getByTestId Page.getByTestId()}. {@code
|
||||
* data-testid} is used by default.
|
||||
*
|
||||
* @param attributeName Test id attribute name.
|
||||
* @since v1.27
|
||||
|
||||
@@ -25,8 +25,11 @@ 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.
|
||||
* <p> <strong>NOTE:</strong> {@link com.microsoft.playwright.Page#tap Page.tap()} the method will throw if {@code hasTouch} option of the browser
|
||||
* context is false.
|
||||
*
|
||||
* @param x X coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
|
||||
* @since v1.8
|
||||
*/
|
||||
void tap(double x, double y);
|
||||
|
||||
@@ -39,8 +39,9 @@ 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.
|
||||
* tracesDir} folder specified in {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. To specify the
|
||||
* final trace zip file name, you need to pass {@code path} option to {@link com.microsoft.playwright.Tracing#stop
|
||||
* Tracing.stop()} instead.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
@@ -68,8 +69,9 @@ public interface Tracing {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* tracesDir} folder specified in {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. To specify the
|
||||
* final trace zip file name, you need to pass {@code path} option to {@link com.microsoft.playwright.Tracing#stop
|
||||
* Tracing.stop()} instead.
|
||||
*/
|
||||
public StartOptions setName(String name) {
|
||||
this.name = name;
|
||||
@@ -113,8 +115,9 @@ 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.
|
||||
* tracesDir} folder specified in {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. To specify the
|
||||
* final trace zip file name, you need to pass {@code path} option to {@link com.microsoft.playwright.Tracing#stopChunk
|
||||
* Tracing.stopChunk()} instead.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
@@ -124,8 +127,9 @@ public interface Tracing {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* tracesDir} folder specified in {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. To specify the
|
||||
* final trace zip file name, you need to pass {@code path} option to {@link com.microsoft.playwright.Tracing#stopChunk
|
||||
* Tracing.stopChunk()} instead.
|
||||
*/
|
||||
public StartChunkOptions setName(String name) {
|
||||
this.name = name;
|
||||
@@ -155,14 +159,14 @@ public interface Tracing {
|
||||
}
|
||||
class StopChunkOptions {
|
||||
/**
|
||||
* Export trace collected since the last {@link Tracing#startChunk Tracing.startChunk()} call into the file with the given
|
||||
* path.
|
||||
* Export trace collected since the last {@link com.microsoft.playwright.Tracing#startChunk Tracing.startChunk()} call into
|
||||
* the file with the given path.
|
||||
*/
|
||||
public Path path;
|
||||
|
||||
/**
|
||||
* Export trace collected since the last {@link Tracing#startChunk Tracing.startChunk()} call into the file with the given
|
||||
* path.
|
||||
* Export trace collected since the last {@link com.microsoft.playwright.Tracing#startChunk Tracing.startChunk()} call into
|
||||
* the file with the given path.
|
||||
*/
|
||||
public StopChunkOptions setPath(Path path) {
|
||||
this.path = path;
|
||||
@@ -172,7 +176,7 @@ public interface Tracing {
|
||||
/**
|
||||
* Start tracing.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -191,7 +195,7 @@ public interface Tracing {
|
||||
/**
|
||||
* Start tracing.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -207,10 +211,11 @@ public interface Tracing {
|
||||
void start(StartOptions options);
|
||||
/**
|
||||
* Start a new trace chunk. If you'd like to record multiple traces on the same {@code BrowserContext}, use {@link
|
||||
* Tracing#start Tracing.start()} once, and then create multiple trace chunks with {@link Tracing#startChunk
|
||||
* Tracing.startChunk()} and {@link Tracing#stopChunk Tracing.stopChunk()}.
|
||||
* com.microsoft.playwright.Tracing#start Tracing.start()} once, and then create multiple trace chunks with {@link
|
||||
* com.microsoft.playwright.Tracing#startChunk Tracing.startChunk()} and {@link com.microsoft.playwright.Tracing#stopChunk
|
||||
* Tracing.stopChunk()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -238,10 +243,11 @@ public interface Tracing {
|
||||
}
|
||||
/**
|
||||
* Start a new trace chunk. If you'd like to record multiple traces on the same {@code BrowserContext}, use {@link
|
||||
* Tracing#start Tracing.start()} once, and then create multiple trace chunks with {@link Tracing#startChunk
|
||||
* Tracing.startChunk()} and {@link Tracing#stopChunk Tracing.stopChunk()}.
|
||||
* com.microsoft.playwright.Tracing#start Tracing.start()} once, and then create multiple trace chunks with {@link
|
||||
* com.microsoft.playwright.Tracing#startChunk Tracing.startChunk()} and {@link com.microsoft.playwright.Tracing#stopChunk
|
||||
* Tracing.stopChunk()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -280,7 +286,8 @@ public interface Tracing {
|
||||
*/
|
||||
void stop(StopOptions options);
|
||||
/**
|
||||
* Stop the trace chunk. See {@link Tracing#startChunk Tracing.startChunk()} for more details about multiple trace chunks.
|
||||
* Stop the trace chunk. See {@link com.microsoft.playwright.Tracing#startChunk Tracing.startChunk()} for more details
|
||||
* about multiple trace chunks.
|
||||
*
|
||||
* @since v1.15
|
||||
*/
|
||||
@@ -288,7 +295,8 @@ public interface Tracing {
|
||||
stopChunk(null);
|
||||
}
|
||||
/**
|
||||
* Stop the trace chunk. See {@link Tracing#startChunk Tracing.startChunk()} for more details about multiple trace chunks.
|
||||
* Stop the trace chunk. See {@link com.microsoft.playwright.Tracing#startChunk Tracing.startChunk()} for more details
|
||||
* about multiple trace chunks.
|
||||
*
|
||||
* @since v1.15
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ 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.
|
||||
* com.microsoft.playwright.BrowserContext#onWebError BrowserContext.onWebError()} event.
|
||||
* <pre>{@code
|
||||
* // Log all uncaught errors to the terminal
|
||||
* context.onWebError(webError -> {
|
||||
|
||||
@@ -67,7 +67,8 @@ public interface WebSocket {
|
||||
public Predicate<WebSocketFrame> 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -80,7 +81,8 @@ public interface WebSocket {
|
||||
}
|
||||
/**
|
||||
* 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForFrameReceivedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -94,7 +96,8 @@ public interface WebSocket {
|
||||
public Predicate<WebSocketFrame> 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -107,7 +110,8 @@ public interface WebSocket {
|
||||
}
|
||||
/**
|
||||
* 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForFrameSentOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
@@ -19,8 +19,8 @@ package com.microsoft.playwright;
|
||||
|
||||
/**
|
||||
* The {@code WebSocketFrame} class represents frames sent over {@code WebSocket} connections in the page. Frame payload is
|
||||
* returned by either {@link WebSocketFrame#text WebSocketFrame.text()} or {@link WebSocketFrame#binary
|
||||
* WebSocketFrame.binary()} method depending on the its type.
|
||||
* returned by either {@link com.microsoft.playwright.WebSocketFrame#text WebSocketFrame.text()} or {@link
|
||||
* com.microsoft.playwright.WebSocketFrame#binary WebSocketFrame.binary()} method depending on the its type.
|
||||
*/
|
||||
public interface WebSocketFrame {
|
||||
/**
|
||||
|
||||
@@ -47,13 +47,15 @@ public interface Worker {
|
||||
class WaitForCloseOptions {
|
||||
/**
|
||||
* 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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
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()}.
|
||||
* default value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForCloseOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -63,13 +65,14 @@ public interface Worker {
|
||||
/**
|
||||
* Returns the return value of {@code expression}.
|
||||
*
|
||||
* <p> If the function passed to the {@link Worker#evaluate Worker.evaluate()} returns a <a
|
||||
* <p> If the function passed to the {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@link
|
||||
* Worker#evaluate Worker.evaluate()} would wait for the promise to resolve and return its value.
|
||||
* com.microsoft.playwright.Worker#evaluate Worker.evaluate()} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> If the function passed to the {@link Worker#evaluate Worker.evaluate()} returns a non-[Serializable] value, then {@link
|
||||
* Worker#evaluate Worker.evaluate()} returns {@code undefined}. Playwright also supports transferring some additional
|
||||
* values that are not serializable by {@code JSON}: {@code -0}, {@code NaN}, {@code Infinity}, {@code -Infinity}.
|
||||
* <p> If the function passed to the {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} returns a
|
||||
* non-[Serializable] value, then {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} returns {@code
|
||||
* undefined}. Playwright also supports transferring some additional values that are not serializable by {@code JSON}:
|
||||
* {@code -0}, {@code NaN}, {@code Infinity}, {@code -Infinity}.
|
||||
*
|
||||
* @param expression JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
|
||||
* automatically invoked.
|
||||
@@ -81,13 +84,14 @@ public interface Worker {
|
||||
/**
|
||||
* Returns the return value of {@code expression}.
|
||||
*
|
||||
* <p> If the function passed to the {@link Worker#evaluate Worker.evaluate()} returns a <a
|
||||
* <p> If the function passed to the {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@link
|
||||
* Worker#evaluate Worker.evaluate()} would wait for the promise to resolve and return its value.
|
||||
* com.microsoft.playwright.Worker#evaluate Worker.evaluate()} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> If the function passed to the {@link Worker#evaluate Worker.evaluate()} returns a non-[Serializable] value, then {@link
|
||||
* Worker#evaluate Worker.evaluate()} returns {@code undefined}. Playwright also supports transferring some additional
|
||||
* values that are not serializable by {@code JSON}: {@code -0}, {@code NaN}, {@code Infinity}, {@code -Infinity}.
|
||||
* <p> If the function passed to the {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} returns a
|
||||
* non-[Serializable] value, then {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} returns {@code
|
||||
* undefined}. Playwright also supports transferring some additional values that are not serializable by {@code JSON}:
|
||||
* {@code -0}, {@code NaN}, {@code Infinity}, {@code -Infinity}.
|
||||
*
|
||||
* @param expression JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
|
||||
* automatically invoked.
|
||||
@@ -98,12 +102,14 @@ public interface Worker {
|
||||
/**
|
||||
* Returns the return value of {@code expression} as a {@code JSHandle}.
|
||||
*
|
||||
* <p> The only difference between {@link Worker#evaluate Worker.evaluate()} and {@link Worker#evaluateHandle
|
||||
* Worker.evaluateHandle()} is that {@link Worker#evaluateHandle Worker.evaluateHandle()} returns {@code JSHandle}.
|
||||
* <p> The only difference between {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} and {@link
|
||||
* com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} is that {@link
|
||||
* com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} returns {@code JSHandle}.
|
||||
*
|
||||
* <p> If the function passed to the {@link Worker#evaluateHandle Worker.evaluateHandle()} returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@link
|
||||
* Worker#evaluateHandle Worker.evaluateHandle()} would wait for the promise to resolve and return its value.
|
||||
* <p> If the function passed to the {@link com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} returns a
|
||||
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then
|
||||
* {@link com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} would wait for the promise to resolve and
|
||||
* return its value.
|
||||
*
|
||||
* @param expression JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
|
||||
* automatically invoked.
|
||||
@@ -115,12 +121,14 @@ public interface Worker {
|
||||
/**
|
||||
* Returns the return value of {@code expression} as a {@code JSHandle}.
|
||||
*
|
||||
* <p> The only difference between {@link Worker#evaluate Worker.evaluate()} and {@link Worker#evaluateHandle
|
||||
* Worker.evaluateHandle()} is that {@link Worker#evaluateHandle Worker.evaluateHandle()} returns {@code JSHandle}.
|
||||
* <p> The only difference between {@link com.microsoft.playwright.Worker#evaluate Worker.evaluate()} and {@link
|
||||
* com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} is that {@link
|
||||
* com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} returns {@code JSHandle}.
|
||||
*
|
||||
* <p> If the function passed to the {@link Worker#evaluateHandle Worker.evaluateHandle()} returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then {@link
|
||||
* Worker#evaluateHandle Worker.evaluateHandle()} would wait for the promise to resolve and return its value.
|
||||
* <p> If the function passed to the {@link com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} returns a
|
||||
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then
|
||||
* {@link com.microsoft.playwright.Worker#evaluateHandle Worker.evaluateHandle()} would wait for the promise to resolve and
|
||||
* return its value.
|
||||
*
|
||||
* @param expression JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
|
||||
* automatically invoked.
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public interface APIResponseAssertions {
|
||||
/**
|
||||
* Ensures the response status code is within {@code 200..299} range.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(response).isOK();
|
||||
* }</pre>
|
||||
|
||||
+317
-90
@@ -17,6 +17,7 @@
|
||||
package com.microsoft.playwright.assertions;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
|
||||
/**
|
||||
* The {@code LocatorAssertions} class provides assertion methods that can be used to make assertions about the {@code
|
||||
@@ -253,6 +254,60 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HasAccessibleDescriptionOptions {
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public HasAccessibleDescriptionOptions setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasAccessibleDescriptionOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HasAccessibleNameOptions {
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public HasAccessibleNameOptions setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasAccessibleNameOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HasAttributeOptions {
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
@@ -350,6 +405,20 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HasRoleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasRoleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HasTextOptions {
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
@@ -430,7 +499,7 @@ public interface LocatorAssertions {
|
||||
* 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**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
@@ -444,7 +513,7 @@ public interface LocatorAssertions {
|
||||
* 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**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
@@ -455,7 +524,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
|
||||
* }</pre>
|
||||
@@ -468,7 +537,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
|
||||
* }</pre>
|
||||
@@ -484,7 +553,7 @@ public interface LocatorAssertions {
|
||||
* {@code option}, {@code optgroup} can be disabled by setting "disabled" attribute. "disabled" attribute on other elements
|
||||
* is ignored by the browser.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isDisabled();
|
||||
* }</pre>
|
||||
@@ -502,7 +571,7 @@ public interface LocatorAssertions {
|
||||
* {@code option}, {@code optgroup} can be disabled by setting "disabled" attribute. "disabled" attribute on other elements
|
||||
* is ignored by the browser.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isDisabled();
|
||||
* }</pre>
|
||||
@@ -513,7 +582,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an editable element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();
|
||||
* }</pre>
|
||||
@@ -526,7 +595,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an editable element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();
|
||||
* }</pre>
|
||||
@@ -537,7 +606,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an empty editable element or to a DOM node that has no text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("div.warning")).isEmpty();
|
||||
* }</pre>
|
||||
@@ -550,7 +619,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an empty editable element or to a DOM node that has no text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("div.warning")).isEmpty();
|
||||
* }</pre>
|
||||
@@ -561,7 +630,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an enabled element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isEnabled();
|
||||
* }</pre>
|
||||
@@ -574,7 +643,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an enabled element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isEnabled();
|
||||
* }</pre>
|
||||
@@ -585,7 +654,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a focused DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();
|
||||
* }</pre>
|
||||
@@ -598,7 +667,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a focused DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();
|
||||
* }</pre>
|
||||
@@ -610,7 +679,7 @@ public interface LocatorAssertions {
|
||||
* Ensures that {@code Locator} either does not resolve to any DOM node, or resolves to a <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">non-visible</a> one.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isHidden();
|
||||
* }</pre>
|
||||
@@ -624,7 +693,7 @@ public interface LocatorAssertions {
|
||||
* Ensures that {@code Locator} either does not resolve to any DOM node, or resolves to a <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">non-visible</a> one.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isHidden();
|
||||
* }</pre>
|
||||
@@ -636,7 +705,7 @@ public interface LocatorAssertions {
|
||||
* 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**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByRole(AriaRole.BUTTON);
|
||||
* // Make sure at least some part of element intersects viewport.
|
||||
@@ -656,7 +725,7 @@ public interface LocatorAssertions {
|
||||
* 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**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByRole(AriaRole.BUTTON);
|
||||
* // Make sure at least some part of element intersects viewport.
|
||||
@@ -674,18 +743,19 @@ public interface LocatorAssertions {
|
||||
* 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> To check that at least one element from the list is visible, use {@link com.microsoft.playwright.Locator#first
|
||||
* Locator.first()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <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();
|
||||
* assertThat(page.getByTestId("todo-item").first()).isVisible();
|
||||
*
|
||||
* // At least one of the two elements is visible, possibly both.
|
||||
* asserThat(
|
||||
* assertThat(
|
||||
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
|
||||
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .first()
|
||||
@@ -701,18 +771,19 @@ public interface LocatorAssertions {
|
||||
* 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> To check that at least one element from the list is visible, use {@link com.microsoft.playwright.Locator#first
|
||||
* Locator.first()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <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();
|
||||
* assertThat(page.getByTestId("todo-item").first()).isVisible();
|
||||
*
|
||||
* // At least one of the two elements is visible, possibly both.
|
||||
* asserThat(
|
||||
* assertThat(
|
||||
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
|
||||
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .first()
|
||||
@@ -726,12 +797,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -771,12 +842,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -814,12 +885,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -859,12 +930,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -902,12 +973,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -947,12 +1018,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -990,12 +1061,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -1035,12 +1106,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -1074,10 +1145,130 @@ public interface LocatorAssertions {
|
||||
* @since v1.20
|
||||
*/
|
||||
void containsText(Pattern[] expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleDescription("Save results to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param description Expected accessible description.
|
||||
* @since v1.44
|
||||
*/
|
||||
default void hasAccessibleDescription(String description) {
|
||||
hasAccessibleDescription(description, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleDescription("Save results to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param description Expected accessible description.
|
||||
* @since v1.44
|
||||
*/
|
||||
void hasAccessibleDescription(String description, HasAccessibleDescriptionOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleDescription("Save results to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param description Expected accessible description.
|
||||
* @since v1.44
|
||||
*/
|
||||
default void hasAccessibleDescription(Pattern description) {
|
||||
hasAccessibleDescription(description, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleDescription("Save results to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param description Expected accessible description.
|
||||
* @since v1.44
|
||||
*/
|
||||
void hasAccessibleDescription(Pattern description, HasAccessibleDescriptionOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleName("Save to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Expected accessible name.
|
||||
* @since v1.44
|
||||
*/
|
||||
default void hasAccessibleName(String name) {
|
||||
hasAccessibleName(name, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleName("Save to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Expected accessible name.
|
||||
* @since v1.44
|
||||
*/
|
||||
void hasAccessibleName(String name, HasAccessibleNameOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleName("Save to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Expected accessible name.
|
||||
* @since v1.44
|
||||
*/
|
||||
default void hasAccessibleName(Pattern name) {
|
||||
hasAccessibleName(name, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a
|
||||
* href="https://w3c.github.io/accname/#dfn-accessible-name">accessible name</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasAccessibleName("Save to disk");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Expected accessible name.
|
||||
* @since v1.44
|
||||
*/
|
||||
void hasAccessibleName(Pattern name, HasAccessibleNameOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -1092,7 +1283,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -1105,7 +1296,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -1120,7 +1311,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -1134,7 +1325,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1155,7 +1346,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1174,7 +1365,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1195,7 +1386,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1214,7 +1405,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1235,7 +1426,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1254,7 +1445,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1275,7 +1466,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a
|
||||
* relaxed regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -1293,7 +1484,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an exact number of DOM nodes.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("list > .component")).hasCount(3);
|
||||
* }</pre>
|
||||
@@ -1307,7 +1498,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an exact number of DOM nodes.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("list > .component")).hasCount(3);
|
||||
* }</pre>
|
||||
@@ -1319,7 +1510,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
@@ -1334,7 +1525,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
@@ -1347,7 +1538,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
@@ -1362,7 +1553,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
@@ -1375,7 +1566,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
@@ -1389,7 +1580,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
@@ -1401,7 +1592,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
@@ -1415,7 +1606,7 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
@@ -1428,7 +1619,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given JavaScript property. Note that this property can be of a
|
||||
* primitive type as well as a plain serializable JavaScript object.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasJSProperty("loaded", true);
|
||||
* }</pre>
|
||||
@@ -1444,7 +1635,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with given JavaScript property. Note that this property can be of a
|
||||
* primitive type as well as a plain serializable JavaScript object.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasJSProperty("loaded", true);
|
||||
* }</pre>
|
||||
@@ -1454,16 +1645,52 @@ public interface LocatorAssertions {
|
||||
* @since v1.20
|
||||
*/
|
||||
void hasJSProperty(String name, Object value, HasJSPropertyOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a href="https://www.w3.org/TR/wai-aria-1.2/#roles">ARIA
|
||||
* role</a>.
|
||||
*
|
||||
* <p> Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass role
|
||||
* {@code "checkbox"} on an element with a subclass role {@code "switch"} will fail.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasRole(AriaRole.BUTTON);
|
||||
* }</pre>
|
||||
*
|
||||
* @param role Required aria role.
|
||||
* @since v1.44
|
||||
*/
|
||||
default void hasRole(AriaRole role) {
|
||||
hasRole(role, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with a given <a href="https://www.w3.org/TR/wai-aria-1.2/#roles">ARIA
|
||||
* role</a>.
|
||||
*
|
||||
* <p> Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass role
|
||||
* {@code "checkbox"} on an element with a subclass role {@code "switch"} will fail.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.getByTestId("save-button");
|
||||
* assertThat(locator).hasRole(AriaRole.BUTTON);
|
||||
* }</pre>
|
||||
*
|
||||
* @param role Required aria role.
|
||||
* @since v1.44
|
||||
*/
|
||||
void hasRole(AriaRole role, HasRoleOptions 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1503,12 +1730,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1546,12 +1773,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1591,12 +1818,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1634,12 +1861,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1679,12 +1906,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1722,12 +1949,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1767,12 +1994,12 @@ public interface LocatorAssertions {
|
||||
* 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> <strong>Details</strong>
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1810,7 +2037,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1825,7 +2052,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1838,7 +2065,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1853,7 +2080,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the
|
||||
* value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1866,7 +2093,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute)
|
||||
* and the specified values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
@@ -1884,7 +2111,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute)
|
||||
* and the specified values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
@@ -1900,7 +2127,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute)
|
||||
* and the specified values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
@@ -1918,7 +2145,7 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute)
|
||||
* and the specified values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
|
||||
@@ -52,11 +52,24 @@ public interface PageAssertions {
|
||||
}
|
||||
}
|
||||
class HasURLOptions {
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public HasURLOptions setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
@@ -78,7 +91,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -92,7 +105,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -104,7 +117,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -118,7 +131,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -130,7 +143,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
@@ -144,7 +157,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
@@ -156,7 +169,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
@@ -170,7 +183,7 @@ public interface PageAssertions {
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
|
||||
+6
-6
@@ -54,7 +54,7 @@ public interface PlaywrightAssertions {
|
||||
/**
|
||||
* Creates a {@code APIResponseAssertions} object for the given {@code APIResponse}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.assertThat(response).isOK();
|
||||
* }</pre>
|
||||
@@ -69,7 +69,7 @@ public interface PlaywrightAssertions {
|
||||
/**
|
||||
* Creates a {@code LocatorAssertions} object for the given {@code Locator}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.assertThat(locator).isVisible();
|
||||
* }</pre>
|
||||
@@ -84,7 +84,7 @@ public interface PlaywrightAssertions {
|
||||
/**
|
||||
* Creates a {@code PageAssertions} object for the given {@code Page}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.assertThat(page).hasTitle("News");
|
||||
* }</pre>
|
||||
@@ -99,7 +99,7 @@ public interface PlaywrightAssertions {
|
||||
/**
|
||||
* Changes default timeout for Playwright assertions from 5 seconds to the specified value.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.setDefaultAssertionTimeout(30_000);
|
||||
* }</pre>
|
||||
@@ -107,8 +107,8 @@ public interface PlaywrightAssertions {
|
||||
* @param timeout Timeout in milliseconds.
|
||||
* @since v1.25
|
||||
*/
|
||||
static void setDefaultAssertionTimeout(double milliseconds) {
|
||||
AssertionsTimeout.setDefaultTimeout(milliseconds);
|
||||
static void setDefaultAssertionTimeout(double timeout) {
|
||||
AssertionsTimeout.setDefaultTimeout(timeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.microsoft.playwright.APIRequestContext;
|
||||
import com.microsoft.playwright.APIResponse;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
@@ -26,11 +25,11 @@ 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;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.*;
|
||||
@@ -38,6 +37,7 @@ import static com.microsoft.playwright.impl.Utils.toFilePayload;
|
||||
|
||||
class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
private final TracingImpl tracing;
|
||||
private String disposeReason;
|
||||
|
||||
APIRequestContextImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
@@ -50,8 +50,17 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
withLogging("APIRequestContext.dispose", () -> sendMessage("dispose"));
|
||||
public void dispose(DisposeOptions options) {
|
||||
withLogging("APIRequestContext.dispose", () -> disposeImpl(options));
|
||||
}
|
||||
|
||||
private void disposeImpl(DisposeOptions options) {
|
||||
if (options == null) {
|
||||
options = new DisposeOptions();
|
||||
}
|
||||
disposeReason = options.reason;
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("dispose", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,6 +87,9 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
|
||||
private APIResponse fetchImpl(String url, RequestOptionsImpl options) {
|
||||
if (disposeReason != null) {
|
||||
throw new PlaywrightException(disposeReason);
|
||||
}
|
||||
if (options == null) {
|
||||
options = new RequestOptionsImpl();
|
||||
}
|
||||
@@ -88,7 +100,7 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
for (Map.Entry<String, ?> e : options.params.entrySet()) {
|
||||
queryParams.put(e.getKey(), "" + e.getValue());
|
||||
}
|
||||
params.add("params", toNameValueArray(queryParams));
|
||||
params.add("params", toNameValueArray(queryParams.entrySet()));
|
||||
}
|
||||
if (options.method != null) {
|
||||
params.addProperty("method", options.method);
|
||||
@@ -108,7 +120,7 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
}
|
||||
if (bytes == null) {
|
||||
params.addProperty("jsonData", gson().toJson(options.data));
|
||||
params.addProperty("jsonData", jsonDataSerializer.toJson(options.data));
|
||||
} else {
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
params.addProperty("postData", base64);
|
||||
@@ -135,6 +147,12 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
params.addProperty("maxRedirects", options.maxRedirects);
|
||||
}
|
||||
if (options.maxRetries != null) {
|
||||
if (options.maxRetries < 0) {
|
||||
throw new PlaywrightException("'maxRetries' must be greater than or equal to '0'");
|
||||
}
|
||||
params.addProperty("maxRetries", options.maxRetries);
|
||||
}
|
||||
JsonObject json = sendMessage("fetch", params).getAsJsonObject();
|
||||
return new APIResponseImpl(this, json.getAsJsonObject("response"));
|
||||
}
|
||||
@@ -151,9 +169,9 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static JsonArray serializeMultipartData(Map<String, Object> data) {
|
||||
private static JsonArray serializeMultipartData(List<? extends Map.Entry<String, Object>> data) {
|
||||
JsonArray result = new JsonArray();
|
||||
for (Map.Entry<String, Object> e : data.entrySet()) {
|
||||
for (Map.Entry<String, ?> e : data) {
|
||||
FilePayload filePayload = null;
|
||||
if (e.getValue() instanceof FilePayload) {
|
||||
filePayload = (FilePayload) e.getValue();
|
||||
|
||||
@@ -17,15 +17,21 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.APIRequest;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.ClientCertificate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.addToProtocol;
|
||||
import static java.nio.file.Files.readAllBytes;
|
||||
|
||||
class APIRequestImpl implements APIRequest {
|
||||
private final PlaywrightImpl playwright;
|
||||
@@ -42,6 +48,8 @@ class APIRequestImpl implements APIRequest {
|
||||
private APIRequestContextImpl newContextImpl(NewContextOptions options) {
|
||||
if (options == null) {
|
||||
options = new NewContextOptions();
|
||||
} else {
|
||||
options = Utils.clone(options);
|
||||
}
|
||||
if (options.storageStatePath != null) {
|
||||
try {
|
||||
@@ -57,11 +65,13 @@ class APIRequestImpl implements APIRequest {
|
||||
storageState = new Gson().fromJson(options.storageState, JsonObject.class);
|
||||
options.storageState = null;
|
||||
}
|
||||
List<ClientCertificate> clientCertificateList = options.clientCertificates;
|
||||
options.clientCertificates = null;
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
if (storageState != null) {
|
||||
params.add("storageState", storageState);
|
||||
}
|
||||
|
||||
addToProtocol(params, clientCertificateList);
|
||||
JsonObject result = playwright.sendMessage("newRequest", params).getAsJsonObject();
|
||||
APIRequestContextImpl context = playwright.connection.getExistingObject(result.getAsJsonObject("request").get("guid").getAsString());
|
||||
return context;
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.microsoft.playwright.PlaywrightException;
|
||||
import org.opentest4j.AssertionFailedError;
|
||||
import org.opentest4j.ValueWrapper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -91,4 +92,17 @@ class AssertionsBase {
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
|
||||
static Boolean shouldIgnoreCase(Object options) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Field fromField = options.getClass().getDeclaredField("ignoreCase");
|
||||
Object value = fromField.get(options);
|
||||
return (Boolean) value;
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.addHarUrlFilter;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.isSafeCloseError;
|
||||
import static com.microsoft.playwright.impl.Utils.*;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.nio.file.Files.readAllBytes;
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -45,7 +45,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
private final BrowserImpl browser;
|
||||
private final TracingImpl tracing;
|
||||
private final APIRequestContextImpl request;
|
||||
private final ClockImpl clock;
|
||||
final List<PageImpl> pages = new ArrayList<>();
|
||||
final List<PageImpl> backgroundPages = new ArrayList<>();
|
||||
|
||||
final Router routes = new Router();
|
||||
private boolean closeWasCalled;
|
||||
private final WaitableEvent<EventType, ?> closePromise;
|
||||
@@ -80,6 +83,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
BACKGROUNDPAGE,
|
||||
CLOSE,
|
||||
CONSOLE,
|
||||
DIALOG,
|
||||
@@ -100,6 +104,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
|
||||
clock = new ClockImpl(this);
|
||||
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
|
||||
}
|
||||
|
||||
@@ -127,6 +132,16 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackgroundPage(Consumer<Page> handler) {
|
||||
listeners.add(EventType.BACKGROUNDPAGE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offBackgroundPage(Consumer<Page> handler) {
|
||||
listeners.remove(EventType.BACKGROUNDPAGE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<BrowserContext> handler) {
|
||||
listeners.add(EventType.CLOSE, handler);
|
||||
@@ -217,6 +232,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.remove(EventType.RESPONSE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClockImpl clock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
private <T> T waitForEventWithTimeout(EventType eventType, Runnable code, Predicate<T> predicate, Double timeout) {
|
||||
List<Waitable<T>> waitables = new ArrayList<>();
|
||||
waitables.add(new WaitableEvent<>(listeners, eventType, predicate));
|
||||
@@ -270,6 +290,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
request.dispose(convertType(options, APIRequestContext.DisposeOptions.class));
|
||||
for (Map.Entry<String, HarRecorder> entry : harRecorders.entrySet()) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("harId", entry.getKey());
|
||||
@@ -323,6 +344,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Page> backgroundPages() {
|
||||
return new ArrayList<>(backgroundPages);
|
||||
}
|
||||
|
||||
private void addInitScriptImpl(String script) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("source", script);
|
||||
@@ -335,8 +361,29 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCookies() {
|
||||
withLogging("BrowserContext.clearCookies", () -> sendMessage("clearCookies"));
|
||||
public void clearCookies(ClearCookiesOptions options) {
|
||||
withLogging("BrowserContext.clearCookies", () -> clearCookiesImpl(options));
|
||||
}
|
||||
|
||||
private void clearCookiesImpl(ClearCookiesOptions options) {
|
||||
if (options == null) {
|
||||
options = new ClearCookiesOptions();
|
||||
}
|
||||
JsonObject params = new JsonObject();
|
||||
setStringOrRegex(params, "name", options.name);
|
||||
setStringOrRegex(params, "domain", options.domain);
|
||||
setStringOrRegex(params, "path", options.path);
|
||||
sendMessage("clearCookies", params);
|
||||
}
|
||||
|
||||
private static void setStringOrRegex(JsonObject params, String name, Object value) {
|
||||
if (value instanceof String) {
|
||||
params.addProperty(name, (String) value);
|
||||
} else if (value instanceof Pattern) {
|
||||
Pattern pattern = (Pattern) value;
|
||||
params.addProperty(name + "RegexSource", pattern.pattern());
|
||||
params.addProperty(name + "RegexFlags", toJsRegexFlags(pattern));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -690,6 +737,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
if (page.opener() != null && !page.opener().isClosed()) {
|
||||
page.opener().notifyPopup(page);
|
||||
}
|
||||
} else if ("backgroundPage".equals(event)) {
|
||||
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
backgroundPages.add(page);
|
||||
listeners.notify(EventType.BACKGROUNDPAGE, page);
|
||||
} else if ("bindingCall".equals(event)) {
|
||||
BindingCall bindingCall = connection.getExistingObject(params.getAsJsonObject("binding").get("guid").getAsString());
|
||||
BindingCallback binding = bindings.get(bindingCall.name());
|
||||
|
||||
@@ -208,6 +208,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
params.addProperty("noDefaultViewport", true);
|
||||
}
|
||||
}
|
||||
addToProtocol(params, options.clientCertificates);
|
||||
params.remove("acceptDownloads");
|
||||
if (options.acceptDownloads != null) {
|
||||
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.addHarUrlFilter;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.addToProtocol;
|
||||
import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
|
||||
class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
@@ -221,6 +222,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
params.addProperty("noDefaultViewport", true);
|
||||
}
|
||||
}
|
||||
addToProtocol(params, options.clientCertificates);
|
||||
params.remove("acceptDownloads");
|
||||
if (options.acceptDownloads != null) {
|
||||
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
|
||||
|
||||
@@ -35,7 +35,10 @@ public class CDPSessionImpl extends ChannelOwner implements CDPSession {
|
||||
super.handleEvent(event, parameters);
|
||||
if ("event".equals(event)) {
|
||||
String method = parameters.get("method").getAsString();
|
||||
JsonObject params = parameters.get("params").getAsJsonObject();
|
||||
JsonObject params = null;
|
||||
if (parameters.has("params")) {
|
||||
params = parameters.get("params").getAsJsonObject();
|
||||
}
|
||||
listeners.notify(method, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Clock;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
class ClockImpl implements Clock {
|
||||
private final ChannelOwner browserContext;
|
||||
|
||||
ClockImpl(BrowserContextImpl browserContext) {
|
||||
this.browserContext = browserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForward(long ticks) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("ticksNumber", ticks);
|
||||
browserContext.sendMessage("clockFastForward", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fastForward(String ticks) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("ticksString", ticks);
|
||||
browserContext.sendMessage("clockFastForward", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(InstallOptions options) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (options != null) {
|
||||
parseTime(options.time, params);
|
||||
}
|
||||
browserContext.sendMessage("clockInstall", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runFor(long ticks) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("ticksNumber", ticks);
|
||||
browserContext.sendMessage("clockRunFor", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runFor(String ticks) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("ticksString", ticks);
|
||||
browserContext.sendMessage("clockRunFor", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseAt(long time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeNumber", time);
|
||||
browserContext.sendMessage("clockPauseAt", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseAt(String time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeString", time);
|
||||
browserContext.sendMessage("clockPauseAt", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseAt(Date time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeNumber", time.getTime());
|
||||
browserContext.sendMessage("clockPauseAt", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
browserContext.sendMessage("clockResume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedTime(long time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeNumber", time);
|
||||
browserContext.sendMessage("clockSetFixedTime", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedTime(String time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeString", time);
|
||||
browserContext.sendMessage("clockSetFixedTime", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedTime(Date time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeNumber", time.getTime());
|
||||
browserContext.sendMessage("clockSetFixedTime", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemTime(long time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeNumber", time);
|
||||
browserContext.sendMessage("clockSetSystemTime", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemTime(String time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeString", time);
|
||||
browserContext.sendMessage("clockSetSystemTime", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemTime(Date time) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("timeNumber", time.getTime());
|
||||
browserContext.sendMessage("clockSetSystemTime", params);
|
||||
}
|
||||
|
||||
private static void parseTime(Object time, JsonObject params) {
|
||||
if (time instanceof Long) {
|
||||
params.addProperty("timeNumber", (Long) time);
|
||||
} else if (time instanceof Date) {
|
||||
params.addProperty("timeNumber", ((Date) time).getTime());
|
||||
} else if (time instanceof String) {
|
||||
params.addProperty("timeString", (String) time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,13 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.ElementHandle;
|
||||
import com.microsoft.playwright.Frame;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.BoundingBox;
|
||||
import com.microsoft.playwright.options.ElementState;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.SelectOption;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
|
||||
@@ -20,39 +20,93 @@ import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.FormData;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FormDataImpl implements FormData {
|
||||
Map<String, Object> fields = new LinkedHashMap<>();
|
||||
static class Field implements Map.Entry<String, Object> {
|
||||
final String name;
|
||||
final Object value;
|
||||
|
||||
private Field(String name, Object value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object setValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
List<Field> fields = new ArrayList();
|
||||
|
||||
@Override
|
||||
public FormData append(String name, String value) {
|
||||
return appendImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData append(String name, boolean value) {
|
||||
return appendImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData append(String name, int value) {
|
||||
return appendImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData append(String name, Path value) {
|
||||
return appendImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData append(String name, FilePayload value) {
|
||||
return appendImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData set(String name, String value) {
|
||||
fields.put(name, value);
|
||||
return this;
|
||||
return setImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData set(String name, boolean value) {
|
||||
fields.put(name, value);
|
||||
return this;
|
||||
return setImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData set(String name, int value) {
|
||||
fields.put(name, value);
|
||||
return this;
|
||||
return setImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData set(String name, Path value) {
|
||||
fields.put(name, value);
|
||||
return this;
|
||||
return setImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormData set(String name, FilePayload value) {
|
||||
fields.put(name, value);
|
||||
return setImpl(name, value);
|
||||
}
|
||||
|
||||
private FormData setImpl(String name, Object value) {
|
||||
fields = fields.stream().filter(f -> !name.equals(f.name)).collect(Collectors.toList());
|
||||
return appendImpl(name, value);
|
||||
}
|
||||
|
||||
private FormData appendImpl(String name, Object value) {
|
||||
fields.add(new Field(name, value));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,4 +133,9 @@ class FrameLocatorImpl implements FrameLocator {
|
||||
public FrameLocator nth(int index) {
|
||||
return new FrameLocatorImpl(frame, frameSelector + " >> nth=" + index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator owner() {
|
||||
return new LocatorImpl(frame, frameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,12 @@ public class JSHandleImpl extends ChannelOwner implements JSHandle {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
withLogging("JSHandle.dispose", () -> sendMessage("dispose"));
|
||||
withLogging("JSHandle.dispose", () -> {
|
||||
try {
|
||||
sendMessage("dispose");
|
||||
} catch (TargetClosedError e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,7 @@ class JsonPipe extends ChannelOwner implements Transport {
|
||||
private ListenerCollection<EventType> listeners = new ListenerCollection<>();
|
||||
private enum EventType { CLOSE }
|
||||
private boolean isClosed;
|
||||
private String closeReason = "Browser has been closed";
|
||||
|
||||
JsonPipe(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
@@ -97,13 +98,19 @@ class JsonPipe extends ChannelOwner implements Transport {
|
||||
incoming.add(params.get("message").getAsJsonObject());
|
||||
} else if ("closed".equals(event)) {
|
||||
isClosed = true;
|
||||
if (params.has("reason")) {
|
||||
String reason = params.get("reason").getAsString();
|
||||
if (reason.trim().length() > 0) {
|
||||
closeReason = reason;
|
||||
}
|
||||
}
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfClosed() {
|
||||
if (isClosed) {
|
||||
throw new PlaywrightException("Browser has been closed");
|
||||
throw new PlaywrightException(closeReason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
@@ -46,6 +47,9 @@ class ListenerCollection <EventType> {
|
||||
}
|
||||
|
||||
void add(EventType type, Consumer<?> listener) {
|
||||
if (listener == null) {
|
||||
throw new PlaywrightException("Can't add a null listener");
|
||||
}
|
||||
List<Consumer<?>> list = listeners.get(type);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.Locator;
|
||||
import com.microsoft.playwright.assertions.LocatorAssertions;
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@@ -82,6 +83,36 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
expectImpl("to.contain.text.array", list, patterns, "Locator expected to contain text", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAccessibleDescription(String description, HasAccessibleDescriptionOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
expected.string = description;
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
expectImpl("to.have.accessible.description", expected, description, "Locator expected to have accessible description", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAccessibleDescription(Pattern pattern, HasAccessibleDescriptionOptions options) {
|
||||
ExpectedTextValue expected = expectedRegex(pattern);
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
expectImpl("to.have.accessible.description", expected, pattern, "Locator expected to have accessible description", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAccessibleName(String name, HasAccessibleNameOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
expected.string = name;
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
expectImpl("to.have.accessible.name", expected, name, "Locator expected to have accessible name", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAccessibleName(Pattern pattern, HasAccessibleNameOptions options) {
|
||||
ExpectedTextValue expected = expectedRegex(pattern);
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
expectImpl("to.have.accessible.name", expected, pattern, "Locator expected to have accessible name", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAttribute(String name, String text, HasAttributeOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
@@ -206,6 +237,13 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
expectImpl("to.have.property", list, value, "Locator expected to have JavaScript property '" + name + "'", commonOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasRole(AriaRole role, HasRoleOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
expected.string = role.toString().toLowerCase();
|
||||
expectImpl("to.have.role", expected, expected.string, "Locator expected to have role", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasText(String text, HasTextOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
@@ -366,17 +404,4 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
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;
|
||||
}
|
||||
try {
|
||||
Field fromField = options.getClass().getDeclaredField("ignoreCase");
|
||||
Object value = fromField.get(options);
|
||||
return (Boolean) value;
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ class LocatorImpl implements Locator {
|
||||
final FrameImpl frame;
|
||||
final String selector;
|
||||
|
||||
LocatorImpl(FrameImpl frame, String frameSelector) {
|
||||
this(frame, frameSelector, null);
|
||||
}
|
||||
|
||||
public LocatorImpl(FrameImpl frame, String selector, LocatorOptions options) {
|
||||
this.frame = frame;
|
||||
if (options != null) {
|
||||
@@ -203,6 +207,11 @@ class LocatorImpl implements Locator {
|
||||
return frame.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameLocator contentFrame() {
|
||||
return new FrameLocatorImpl(frame, selector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object evaluate(String expression, Object arg, EvaluateOptions options) {
|
||||
return withElement((h, o) -> h.evaluate(expression, arg), options);
|
||||
@@ -615,6 +624,20 @@ class LocatorImpl implements Locator {
|
||||
return "Locator@" + selector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof LocatorImpl)) {
|
||||
return false;
|
||||
}
|
||||
LocatorImpl locator = (LocatorImpl) obj;
|
||||
return frame.equals(locator.frame) && selector.equals(locator.selector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return frame.hashCode() ^ selector.hashCode();
|
||||
}
|
||||
|
||||
FrameExpectResult expect(String expression, FrameExpectOptions options) {
|
||||
return frame.withLogging("Locator.expect", () -> expectImpl(expression, options));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.microsoft.playwright.assertions.PageAssertions;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.LocatorAssertionsImpl.shouldIgnoreCase;
|
||||
import static com.microsoft.playwright.impl.UrlMatcher.resolveUrl;
|
||||
import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
|
||||
@@ -57,6 +58,7 @@ public class PageAssertionsImpl extends AssertionsBase implements PageAssertions
|
||||
url = resolveUrl(actualPage.context().baseUrl, url);
|
||||
}
|
||||
expected.string = url;
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
expectImpl("to.have.url", expected, url, "Page URL expected to be", convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,34 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private ViewportSize viewport;
|
||||
private final Router routes = new Router();
|
||||
private final Set<FrameImpl> frames = new LinkedHashSet<>();
|
||||
private final Map<Integer, Runnable> locatorHandlers = new HashMap<>();
|
||||
private final Map<Integer, LocatorHandler> locatorHandlers = new HashMap<>();
|
||||
|
||||
private static class LocatorHandler {
|
||||
private final Locator locator;
|
||||
private final Consumer<Locator> handler;
|
||||
private Integer times;
|
||||
|
||||
LocatorHandler(Locator locator, Consumer<Locator> handler, Integer times) {
|
||||
this.locator = locator;
|
||||
this.handler = handler;
|
||||
this.times = times;
|
||||
}
|
||||
|
||||
boolean call() {
|
||||
if (shouldRemove()) {
|
||||
return true;
|
||||
}
|
||||
if (times != null) {
|
||||
--times;
|
||||
}
|
||||
handler.accept(locator);
|
||||
return shouldRemove();
|
||||
}
|
||||
|
||||
private boolean shouldRemove() {
|
||||
return times != null && times == 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<EventType, String> eventSubscriptions() {
|
||||
Map<EventType, String> result = new HashMap<>();
|
||||
@@ -203,6 +230,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
void didClose() {
|
||||
isClosed = true;
|
||||
browserContext.pages.remove(this);
|
||||
browserContext.backgroundPages.remove(this);
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
|
||||
@@ -403,6 +431,11 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
listeners.remove(EventType.WORKER, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClockImpl clock() {
|
||||
return browserContext.clock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page waitForClose(WaitForCloseOptions options, Runnable code) {
|
||||
return withWaitLogging("Page.waitForClose", logger -> waitForCloseImpl(options, code));
|
||||
@@ -529,29 +562,58 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLocatorHandler(Locator locator, Runnable handler) {
|
||||
public void addLocatorHandler(Locator locator, Consumer<Locator> handler, AddLocatorHandlerOptions options) {
|
||||
LocatorImpl locatorImpl = (LocatorImpl) locator;
|
||||
if (locatorImpl.frame != mainFrame) {
|
||||
throw new PlaywrightException("Locator must belong to the main frame of this page");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new AddLocatorHandlerOptions();
|
||||
}
|
||||
if (options.times != null && options.times == 0) {
|
||||
return;
|
||||
}
|
||||
AddLocatorHandlerOptions finalOptions = options;
|
||||
withLogging("Page.addLocatorHandler", () -> {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("selector", locatorImpl.selector);
|
||||
if (finalOptions.noWaitAfter != null && finalOptions.noWaitAfter) {
|
||||
params.addProperty("noWaitAfter", true);
|
||||
}
|
||||
params.addProperty("selector", locatorImpl.selector);
|
||||
JsonObject json = (JsonObject) sendMessage("registerLocatorHandler", params);
|
||||
int uid = json.get("uid").getAsInt();
|
||||
locatorHandlers.put(uid, handler);
|
||||
locatorHandlers.put(uid, new LocatorHandler(locator, handler, finalOptions.times));
|
||||
});
|
||||
}
|
||||
|
||||
private void onLocatorHandlerTriggered(int uid) {
|
||||
try {
|
||||
Runnable handler = locatorHandlers.get(uid);
|
||||
if (handler != null) {
|
||||
handler.run();
|
||||
@Override
|
||||
public void removeLocatorHandler(Locator locator) {
|
||||
for (Map.Entry<Integer, LocatorHandler> entry: locatorHandlers.entrySet()) {
|
||||
if (entry.getValue().locator.equals(locator)) {
|
||||
locatorHandlers.remove(locator);
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("uid", entry.getKey());
|
||||
try {
|
||||
sendMessage("unregisterLocatorHandler", params);
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onLocatorHandlerTriggered(int uid) {
|
||||
boolean remove = false;
|
||||
try {
|
||||
LocatorHandler handler = locatorHandlers.get(uid);
|
||||
remove = handler != null && handler.call();
|
||||
} finally {
|
||||
if (remove) {
|
||||
locatorHandlers.remove(uid);
|
||||
}
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("uid", uid);
|
||||
params.addProperty("remove", remove);
|
||||
sendMessageAsync("resolveLocatorHandlerNoReply", params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ class SerializedValue{
|
||||
String d;
|
||||
String u;
|
||||
String bi;
|
||||
public static class E {
|
||||
String m;
|
||||
String n;
|
||||
String s;
|
||||
}
|
||||
E e;
|
||||
public static class R {
|
||||
String p;
|
||||
String f;
|
||||
|
||||
@@ -33,6 +33,7 @@ public class RequestOptionsImpl implements RequestOptions {
|
||||
Boolean ignoreHTTPSErrors;
|
||||
Double timeout;
|
||||
Integer maxRedirects;
|
||||
Integer maxRetries;
|
||||
|
||||
@Override
|
||||
public RequestOptions setHeader(String name, String value) {
|
||||
@@ -125,4 +126,10 @@ public class RequestOptionsImpl implements RequestOptions {
|
||||
this.maxRedirects = maxRedirects;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestOptions setMaxRetries(int maxRetries) {
|
||||
this.maxRetries = maxRetries;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@ import com.microsoft.playwright.ElementHandle;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigInteger;
|
||||
import java.net.MalformedURLException;
|
||||
@@ -35,11 +33,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -55,6 +49,7 @@ class Serialization {
|
||||
.registerTypeAdapter(ColorScheme.class, new ToLowerCaseAndDashSerializer<ColorScheme>())
|
||||
.registerTypeAdapter(Media.class, new ToLowerCaseSerializer<Media>())
|
||||
.registerTypeAdapter(ForcedColors.class, new ToLowerCaseSerializer<ForcedColors>())
|
||||
.registerTypeAdapter(HttpCredentialsSend.class, new ToLowerCaseSerializer<HttpCredentialsSend>())
|
||||
.registerTypeAdapter(ReducedMotion.class, new ToLowerCaseAndDashSerializer<ReducedMotion>())
|
||||
.registerTypeAdapter(ScreenshotAnimations.class, new ToLowerCaseSerializer<ScreenshotAnimations>())
|
||||
.registerTypeAdapter(ScreenshotType.class, new ToLowerCaseSerializer<ScreenshotType>())
|
||||
@@ -76,6 +71,12 @@ class Serialization {
|
||||
return gson;
|
||||
}
|
||||
|
||||
static final Gson jsonDataSerializer = new GsonBuilder().disableHtmlEscaping()
|
||||
.registerTypeAdapter(Date.class, new DateSerializer())
|
||||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer())
|
||||
.registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer())
|
||||
.serializeNulls().create();
|
||||
|
||||
static SerializedError serializeError(Throwable e) {
|
||||
SerializedError result = new SerializedError();
|
||||
result.error = new SerializedError.Error();
|
||||
@@ -169,6 +170,14 @@ class Serialization {
|
||||
result.r = new SerializedValue.R();
|
||||
result.r.p = ((Pattern)value).pattern();
|
||||
result.r.f = toJsRegexFlags(((Pattern)value));
|
||||
} else if (value instanceof Exception) {
|
||||
Exception exception = (Exception) value;
|
||||
result.e = new SerializedValue.E();
|
||||
result.e.m = exception.getMessage();
|
||||
result.e.n = exception.getClass().getSimpleName();
|
||||
StringWriter sw = new StringWriter();
|
||||
exception.printStackTrace(new PrintWriter(sw));
|
||||
result.e.s = sw.toString();
|
||||
} else {
|
||||
HashableValue mapKey = new HashableValue(value);
|
||||
Integer id = valueToId.get(mapKey);
|
||||
@@ -246,6 +255,9 @@ class Serialization {
|
||||
return (T)(Date.from(Instant.parse(value.d)));
|
||||
if (value.r != null)
|
||||
return (T)(Pattern.compile(value.r.p, fromJsRegexFlags(value.r.f)));
|
||||
if (value.e != null) {
|
||||
return (T)new Exception(value.e.s);
|
||||
}
|
||||
if (value.v != null) {
|
||||
switch (value.v) {
|
||||
case "undefined":
|
||||
@@ -303,6 +315,9 @@ class Serialization {
|
||||
if (modifiers.contains(KeyboardModifier.CONTROL)) {
|
||||
result.add("Control");
|
||||
}
|
||||
if (modifiers.contains(KeyboardModifier.CONTROLORMETA)) {
|
||||
result.add("ControlOrMeta");
|
||||
}
|
||||
if (modifiers.contains(KeyboardModifier.META)) {
|
||||
result.add("Meta");
|
||||
}
|
||||
@@ -351,7 +366,7 @@ class Serialization {
|
||||
throw new PlaywrightException("Value cannot be null");
|
||||
}
|
||||
}
|
||||
return toNameValueArray(map);
|
||||
return toNameValueArray(map.entrySet());
|
||||
}
|
||||
|
||||
static void addHarUrlFilter(JsonObject options, Object urlFilter) {
|
||||
@@ -364,9 +379,9 @@ class Serialization {
|
||||
}
|
||||
}
|
||||
|
||||
static JsonArray toNameValueArray(Map<String, ?> map) {
|
||||
static JsonArray toNameValueArray(Iterable<? extends Map.Entry<String, ?>> collection) {
|
||||
JsonArray array = new JsonArray();
|
||||
for (Map.Entry<String, ?> e : map.entrySet()) {
|
||||
for (Map.Entry<String, ?> e : collection) {
|
||||
JsonObject item = new JsonObject();
|
||||
item.addProperty("name", e.getKey());
|
||||
if (e.getValue() instanceof FilePayload) {
|
||||
@@ -514,6 +529,13 @@ class Serialization {
|
||||
}
|
||||
}
|
||||
|
||||
private static class OffsetDateTimeSerializer implements JsonSerializer<OffsetDateTime> {
|
||||
@Override
|
||||
public JsonElement serialize(OffsetDateTime src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(dateFormat.format(Date.from(src.toInstant())));
|
||||
}
|
||||
}
|
||||
|
||||
private static class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime> {
|
||||
@Override
|
||||
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
|
||||
@@ -24,6 +24,10 @@ public class TargetClosedError extends PlaywrightException {
|
||||
}
|
||||
|
||||
public TargetClosedError(String message) {
|
||||
super(message != null ? message : "Target page, context or browser has been closed");
|
||||
this(message, null);
|
||||
}
|
||||
|
||||
public TargetClosedError(String message, Throwable cause) {
|
||||
super(message != null ? message : "Target page, context or browser has been closed", cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.ClientCertificate;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.HttpHeader;
|
||||
|
||||
@@ -33,8 +35,10 @@ import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.toJsonArray;
|
||||
import static java.nio.file.Files.readAllBytes;
|
||||
|
||||
public class Utils {
|
||||
static <F, T> T convertType(F f, Class<T> t) {
|
||||
@@ -173,42 +177,107 @@ public class Utils {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
static void addFilePathUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
|
||||
if (files.length == 0) {
|
||||
static void addFilePathUploadParams(Path[] items, JsonObject params, BrowserContextImpl context) {
|
||||
List<Path> localPaths = new ArrayList<>();
|
||||
Path localDirectory = resolvePathsAndDirectoryForInputFiles(items, localPaths);
|
||||
if (items.length == 0) {
|
||||
// FIXME: shouldBeAbleToResetSelectedFilesWithEmptyFileList tesst hangs in Chromium if we pass empty paths list.
|
||||
params.add("payloads", new JsonArray());
|
||||
} else if (context.connection.isRemote) {
|
||||
List<WritableStream> streams = new ArrayList<>();
|
||||
JsonArray jsonStreams = new JsonArray();
|
||||
for (Path path : files) {
|
||||
long lastModifiedMs;
|
||||
try {
|
||||
lastModifiedMs = Files.getLastModifiedTime(path).toMillis();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot read file timestamp: " + path, e);
|
||||
}
|
||||
WritableStream temp = context.createTempFile(path.getFileName().toString(), lastModifiedMs);
|
||||
streams.add(temp);
|
||||
try (OutputStream out = temp.stream()) {
|
||||
Files.copy(path, out);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to copy file to remote server.", e);
|
||||
}
|
||||
jsonStreams.add(temp.toProtocolRef());
|
||||
if (localDirectory != null) {
|
||||
localPaths = collectFiles(localDirectory);
|
||||
}
|
||||
JsonObject json = createTempFiles(context, localDirectory, localPaths);
|
||||
JsonArray writableStreams = json.getAsJsonArray("writableStreams");
|
||||
JsonArray jsonStreams = copyLocalToTempFiles(context, localPaths, writableStreams);
|
||||
if (json.has("rootDir")) {
|
||||
params.add("directoryStream", json.get("rootDir"));
|
||||
} else {
|
||||
params.add("streams", jsonStreams);
|
||||
}
|
||||
params.add("streams", jsonStreams);
|
||||
} else {
|
||||
Path[] absolute = Arrays.stream(files).map(f -> {
|
||||
try {
|
||||
return f.toRealPath();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot get absolute file path", e);
|
||||
}
|
||||
}).toArray(Path[]::new);
|
||||
params.add("localPaths", toJsonArray(absolute));
|
||||
if (!localPaths.isEmpty()) {
|
||||
params.add("localPaths", toJsonArray(localPaths.toArray(new Path[0])));
|
||||
}
|
||||
if (localDirectory != null) {
|
||||
params.addProperty("localDirectory", localDirectory.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Path resolvePathsAndDirectoryForInputFiles(Path[] items, List<Path> outLocalPaths) {
|
||||
Path localDirectory = null;
|
||||
try {
|
||||
for (Path item : items) {
|
||||
if (Files.isDirectory(item)) {
|
||||
if (localDirectory != null) {
|
||||
throw new PlaywrightException("Multiple directories are not supported");
|
||||
}
|
||||
localDirectory = item.toRealPath();
|
||||
} else {
|
||||
outLocalPaths.add(item.toRealPath());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot get absolute file path", e);
|
||||
}
|
||||
if (!outLocalPaths.isEmpty() && localDirectory != null) {
|
||||
throw new PlaywrightException("File paths must be all files or a single directory");
|
||||
}
|
||||
return localDirectory;
|
||||
}
|
||||
|
||||
private static List<Path> collectFiles(Path localDirectory) {
|
||||
try {
|
||||
return Files.walk(localDirectory).filter(e -> Files.isRegularFile(e)).collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to traverse directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static JsonArray copyLocalToTempFiles(BrowserContextImpl context, List<Path> localPaths, JsonArray writableStreams) {
|
||||
JsonArray jsonStreams = new JsonArray();
|
||||
for (int i = 0; i < localPaths.size(); i++) {
|
||||
JsonObject jsonStream = writableStreams.get(i).getAsJsonObject();
|
||||
WritableStream temp = context.connection.getExistingObject(jsonStream.get("guid").getAsString());
|
||||
try (OutputStream out = temp.stream()) {
|
||||
Files.copy(localPaths.get(i), out);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to copy file to remote server.", e);
|
||||
}
|
||||
jsonStreams.add(temp.toProtocolRef());
|
||||
}
|
||||
return jsonStreams;
|
||||
}
|
||||
|
||||
private static JsonObject createTempFiles(BrowserContextImpl context, Path localDirectory, List<Path> localPaths) {
|
||||
JsonObject tempFilesParams = new JsonObject();
|
||||
if (localDirectory != null) {
|
||||
tempFilesParams.addProperty("rootDirName", localDirectory.getFileName().toString());
|
||||
}
|
||||
JsonArray items = new JsonArray();
|
||||
for (Path path : localPaths) {
|
||||
long lastModifiedMs;
|
||||
try {
|
||||
lastModifiedMs = Files.getLastModifiedTime(path).toMillis();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot read file timestamp: " + path, e);
|
||||
}
|
||||
Path name;
|
||||
if (localDirectory == null) {
|
||||
name = path.getFileName();
|
||||
} else {
|
||||
name = localDirectory.relativize(path);
|
||||
}
|
||||
JsonObject item = new JsonObject();
|
||||
item.addProperty("name", name.toString());
|
||||
item.addProperty("lastModifiedMs", lastModifiedMs);
|
||||
items.add(item);
|
||||
}
|
||||
tempFilesParams.add("items", items);
|
||||
return context.sendMessage("createTempFiles", tempFilesParams).getAsJsonObject();
|
||||
}
|
||||
|
||||
static void checkFilePayloadSize(FilePayload[] files) {
|
||||
long totalSize = 0;
|
||||
for (FilePayload file: files) {
|
||||
@@ -345,4 +414,47 @@ public class Utils {
|
||||
static String addSourceUrlToScript(String source, Path path) {
|
||||
return source + "\n//# sourceURL=" + path.toString().replace("\n", "");
|
||||
}
|
||||
|
||||
static void addToProtocol(JsonObject params, List<ClientCertificate> clientCertificateList) {
|
||||
if (clientCertificateList == null) {
|
||||
return;
|
||||
}
|
||||
JsonArray clientCertificates = new JsonArray();
|
||||
for (ClientCertificate cert: clientCertificateList) {
|
||||
JsonObject jsonCert = new JsonObject();
|
||||
jsonCert.addProperty("origin", cert.origin);
|
||||
try {
|
||||
String certBase64 = base64Buffer(cert.cert, cert.certPath);
|
||||
if (certBase64 != null) {
|
||||
jsonCert.addProperty("cert", certBase64);
|
||||
}
|
||||
String keyBase64 = base64Buffer(cert.key, cert.keyPath);
|
||||
if (keyBase64 != null) {
|
||||
jsonCert.addProperty("key", keyBase64);
|
||||
}
|
||||
String pfxBase64 = base64Buffer(cert.pfx, cert.pfxPath);
|
||||
if (pfxBase64 != null) {
|
||||
params.addProperty("pfx", pfxBase64);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read from file", e);
|
||||
}
|
||||
if (cert.passphrase != null) {
|
||||
jsonCert.addProperty("passphrase", cert.passphrase);
|
||||
}
|
||||
clientCertificates.add(jsonCert);
|
||||
}
|
||||
params.remove("clientCertificates");
|
||||
params.add("clientCertificates", clientCertificates);
|
||||
}
|
||||
|
||||
private static String base64Buffer(byte[] bytes, Path path) throws IOException {
|
||||
if (path != null) {
|
||||
bytes = readAllBytes(path);
|
||||
}
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
return Base64.getEncoder().encodeToString(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ class WaitableResult<T> implements Waitable<T> {
|
||||
if (exception != null) {
|
||||
if (exception instanceof TimeoutError) {
|
||||
throw new TimeoutError(exception.getMessage(), exception);
|
||||
} if (exception instanceof TargetClosedError) {
|
||||
throw new TargetClosedError(exception.getMessage(), exception);
|
||||
}
|
||||
throw new PlaywrightException(exception.getMessage(), exception);
|
||||
}
|
||||
|
||||
+9
-3
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.APIRequest;
|
||||
import com.microsoft.playwright.APIRequestContext;
|
||||
@@ -23,7 +23,7 @@ import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
import static com.microsoft.playwright.impl.junit.ExtensionUtils.isParameterSupported;
|
||||
|
||||
public class APIRequestContextExtension implements ParameterResolver, BeforeEachCallback, AfterAllCallback {
|
||||
private static final ThreadLocal<APIRequestContext> threadLocalAPIRequestContext = new ThreadLocal<>();
|
||||
@@ -48,7 +48,13 @@ public class APIRequestContextExtension implements ParameterResolver, BeforeEach
|
||||
return getOrCreateAPIRequestContext(extensionContext);
|
||||
}
|
||||
|
||||
static APIRequestContext getOrCreateAPIRequestContext(ExtensionContext extensionContext) {
|
||||
/**
|
||||
* Returns the APIRequestContext that belongs to the current test. Will be created if it doesn't already exist.
|
||||
* <strong>NOTE:</strong> this method is subject to change.
|
||||
* @param extensionContext the context in which the current test or container is being executed.
|
||||
* @return The APIRequestContext that belongs to the current test.
|
||||
*/
|
||||
public static APIRequestContext getOrCreateAPIRequestContext(ExtensionContext extensionContext) {
|
||||
APIRequestContext apiRequestContext = threadLocalAPIRequestContext.get();
|
||||
if (apiRequestContext != null) {
|
||||
return apiRequestContext;
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.*;
|
||||
import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static com.microsoft.playwright.impl.junit.ExtensionUtils.*;
|
||||
import static com.microsoft.playwright.impl.junit.PageExtension.cleanUpPage;
|
||||
|
||||
public class BrowserContextExtension implements ParameterResolver, TestWatcher {
|
||||
private static final ThreadLocal<BrowserContext> threadLocalBrowserContext = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return !isClassHook(extensionContext) && isParameterSupported(parameterContext, extensionContext, BrowserContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return getOrCreateBrowserContext(extensionContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the BrowserContext that belongs to the current test. Will be created if it doesn't already exist.
|
||||
* <strong>NOTE:</strong> this method is subject to change.
|
||||
*
|
||||
* @param extensionContext the context in which the current test or container is being executed.
|
||||
* @return The BrowserContext that belongs to the current test.
|
||||
*/
|
||||
public static BrowserContext getOrCreateBrowserContext(ExtensionContext extensionContext) {
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
if (browserContext != null) {
|
||||
return browserContext;
|
||||
}
|
||||
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
||||
setTestIdAttribute(playwright, options);
|
||||
Browser browser = BrowserExtension.getOrCreateBrowser(extensionContext);
|
||||
Browser.NewContextOptions contextOptions = getContextOptions(playwright, options);
|
||||
browserContext = browser.newContext(contextOptions);
|
||||
if (shouldRecordTrace(options)) {
|
||||
Tracing.StartOptions startOptions = new Tracing.StartOptions().setSnapshots(true).setScreenshots(true).setTitle(extensionContext.getDisplayName());
|
||||
if (System.getenv("PLAYWRIGHT_JAVA_SRC") != null) {
|
||||
startOptions.setSources(true);
|
||||
}
|
||||
browserContext.tracing().start(startOptions);
|
||||
}
|
||||
threadLocalBrowserContext.set(browserContext);
|
||||
return browserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSuccessful(ExtensionContext extensionContext) {
|
||||
saveTraceWhenOn(extensionContext);
|
||||
closeBrowserContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testAborted(ExtensionContext extensionContext, Throwable cause) {
|
||||
saveTraceWhenOn(extensionContext);
|
||||
closeBrowserContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testFailed(ExtensionContext extensionContext, Throwable cause) {
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
if (shouldRecordTrace(options)) {
|
||||
saveTrace(extensionContext);
|
||||
}
|
||||
closeBrowserContext();
|
||||
}
|
||||
|
||||
private static void saveTraceWhenOn(ExtensionContext extensionContext) {
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
if (options.trace.equals(Options.Trace.ON)) {
|
||||
saveTrace(extensionContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveTrace(ExtensionContext extensionContext) {
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
if (browserContext == null) {
|
||||
return;
|
||||
}
|
||||
Path outputPath = getOutputPath(extensionContext);
|
||||
createOutputPath(outputPath);
|
||||
Tracing.StopOptions stopOptions = new Tracing.StopOptions().setPath(outputPath.resolve("trace.zip"));
|
||||
browserContext.tracing().stop(stopOptions);
|
||||
}
|
||||
|
||||
private static void createOutputPath(Path outputPath) {
|
||||
if (!Files.exists(outputPath)) {
|
||||
try {
|
||||
Files.createDirectories(outputPath);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Path getOutputPath(ExtensionContext extensionContext) {
|
||||
BrowserType browserType = BrowserExtension.getBrowser().browserType();
|
||||
Path defaultOutputPath = getDefaultOutputPath(extensionContext);
|
||||
String outputDirName = extensionContext.getRequiredTestClass().getName() + "." +
|
||||
extensionContext.getRequiredTestMethod().getName() + "-" +
|
||||
browserType.name();
|
||||
return defaultOutputPath.resolve(outputDirName);
|
||||
}
|
||||
|
||||
private static Path getDefaultOutputPath(ExtensionContext extensionContext) {
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Path outputPath = options.outputDir;
|
||||
if (outputPath == null) {
|
||||
outputPath = Paths.get(System.getProperty("user.dir")).resolve("test-results");
|
||||
}
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
private void closeBrowserContext() {
|
||||
cleanUpPage();
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
threadLocalBrowserContext.remove();
|
||||
if (browserContext != null) {
|
||||
browserContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldRecordTrace(Options options) {
|
||||
return options.trace.equals(Options.Trace.ON) || options.trace.equals(Options.Trace.RETAIN_ON_FAILURE);
|
||||
}
|
||||
|
||||
private static Browser.NewContextOptions getContextOptions(Playwright playwright, Options options) {
|
||||
Browser.NewContextOptions contextOptions = Utils.clone(options.contextOptions);
|
||||
if (contextOptions == null) {
|
||||
contextOptions = new Browser.NewContextOptions();
|
||||
}
|
||||
|
||||
if (options.baseUrl != null) {
|
||||
contextOptions.setBaseURL(options.baseUrl);
|
||||
}
|
||||
|
||||
if (options.deviceName != null) {
|
||||
DeviceDescriptor deviceDescriptor = DeviceDescriptor.findByName(playwright, options.deviceName);
|
||||
if (deviceDescriptor == null) {
|
||||
throw new PlaywrightException("Unknown device name: " + options.deviceName);
|
||||
}
|
||||
contextOptions.userAgent = deviceDescriptor.userAgent;
|
||||
if (deviceDescriptor.viewport != null) {
|
||||
contextOptions.setViewportSize(deviceDescriptor.viewport.width, deviceDescriptor.viewport.height);
|
||||
}
|
||||
contextOptions.deviceScaleFactor = deviceDescriptor.deviceScaleFactor;
|
||||
contextOptions.isMobile = deviceDescriptor.isMobile;
|
||||
contextOptions.hasTouch = deviceDescriptor.hasTouch;
|
||||
}
|
||||
|
||||
if (options.ignoreHTTPSErrors != null) {
|
||||
contextOptions.setIgnoreHTTPSErrors(options.ignoreHTTPSErrors);
|
||||
}
|
||||
|
||||
return contextOptions;
|
||||
}
|
||||
}
|
||||
+31
-5
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
@@ -24,7 +24,8 @@ import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
import static com.microsoft.playwright.impl.junit.ExtensionUtils.*;
|
||||
|
||||
public class BrowserExtension implements ParameterResolver, AfterAllCallback {
|
||||
private static final ThreadLocal<Browser> threadLocalBrowser = new ThreadLocal<>();
|
||||
|
||||
@@ -47,7 +48,13 @@ public class BrowserExtension implements ParameterResolver, AfterAllCallback {
|
||||
return getOrCreateBrowser(extensionContext);
|
||||
}
|
||||
|
||||
static Browser getOrCreateBrowser(ExtensionContext extensionContext) {
|
||||
/**
|
||||
* Returns the Browser that belongs to the current test. Will be created if it doesn't already exist.
|
||||
* <strong>NOTE:</strong> this method is subject to change.
|
||||
* @param extensionContext the context in which the current test or container is being executed.
|
||||
* @return The Browser that belongs to the current test.
|
||||
*/
|
||||
public static Browser getOrCreateBrowser(ExtensionContext extensionContext) {
|
||||
Browser browser = threadLocalBrowser.get();
|
||||
if (browser != null) {
|
||||
return browser;
|
||||
@@ -55,7 +62,7 @@ public class BrowserExtension implements ParameterResolver, AfterAllCallback {
|
||||
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
||||
BrowserType.LaunchOptions launchOptions = getLaunchOptions(options);
|
||||
|
||||
|
||||
BrowserType browserType = playwright.chromium();
|
||||
if (options.browserName != null) {
|
||||
@@ -66,12 +73,31 @@ public class BrowserExtension implements ParameterResolver, AfterAllCallback {
|
||||
browserType = getBrowserTypeForName(playwright, deviceDescriptor.defaultBrowserType);
|
||||
}
|
||||
}
|
||||
browser = browserType.launch(launchOptions);
|
||||
|
||||
if(options.wsEndpoint != null && !options.wsEndpoint.isEmpty()) {
|
||||
BrowserType.ConnectOptions connectOptions = getConnectOptions(options);
|
||||
browser = browserType.connect(options.wsEndpoint, connectOptions);
|
||||
} else {
|
||||
BrowserType.LaunchOptions launchOptions = getLaunchOptions(options);
|
||||
browser = browserType.launch(launchOptions);
|
||||
}
|
||||
|
||||
threadLocalBrowser.set(browser);
|
||||
return browser;
|
||||
}
|
||||
|
||||
static Browser getBrowser() {
|
||||
return threadLocalBrowser.get();
|
||||
}
|
||||
|
||||
private static BrowserType.ConnectOptions getConnectOptions(Options options) {
|
||||
BrowserType.ConnectOptions connectOptions = options.connectOptions;
|
||||
if(connectOptions == null) {
|
||||
connectOptions = new BrowserType.ConnectOptions();
|
||||
}
|
||||
return connectOptions;
|
||||
}
|
||||
|
||||
private static BrowserType getBrowserTypeForName(Playwright playwright, String name) {
|
||||
switch (name) {
|
||||
case "webkit":
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import com.microsoft.playwright.junit.OptionsFactory;
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
+12
-3
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
@@ -27,11 +27,13 @@ import static org.junit.platform.commons.support.AnnotationSupport.findAnnotatio
|
||||
|
||||
class ExtensionUtils {
|
||||
static boolean hasUsePlaywrightAnnotation(ExtensionContext extensionContext) {
|
||||
return AnnotationSupport.isAnnotated(extensionContext.getTestClass(), UsePlaywright.class);
|
||||
Class<?> outerClass = getOuterClass(extensionContext.getRequiredTestClass());
|
||||
return AnnotationSupport.isAnnotated(outerClass, UsePlaywright.class);
|
||||
}
|
||||
|
||||
static UsePlaywright getUsePlaywrightAnnotation(ExtensionContext extensionContext) {
|
||||
return findAnnotation(extensionContext.getTestClass(), UsePlaywright.class).get();
|
||||
Class<?> topLevelClass = getOuterClass(extensionContext.getRequiredTestClass());
|
||||
return findAnnotation(topLevelClass, UsePlaywright.class).get();
|
||||
}
|
||||
|
||||
static boolean isClassHook(ExtensionContext extensionContext) {
|
||||
@@ -49,6 +51,13 @@ class ExtensionUtils {
|
||||
static void setTestIdAttribute(Playwright playwright, Options options) {
|
||||
String testIdAttribute = options.testIdAttribute == null ? "data-testid" : options.testIdAttribute;
|
||||
playwright.selectors().setTestIdAttribute(testIdAttribute);
|
||||
}
|
||||
|
||||
private static Class<?> getOuterClass(Class<?> clazz) {
|
||||
if (clazz.getDeclaringClass() == null) {
|
||||
return clazz;
|
||||
} else {
|
||||
return getOuterClass(clazz.getDeclaringClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -14,16 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import com.microsoft.playwright.junit.OptionsFactory;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.getUsePlaywrightAnnotation;
|
||||
import static com.microsoft.playwright.impl.junit.ExtensionUtils.*;
|
||||
|
||||
public class OptionsExtension implements AfterAllCallback {
|
||||
private static final ThreadLocal<Options> threadLocalOptions = new ThreadLocal<>();
|
||||
+16
-15
@@ -14,26 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.BrowserContext;
|
||||
import com.microsoft.playwright.Page;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isClassHook;
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
import static com.microsoft.playwright.impl.junit.ExtensionUtils.*;
|
||||
|
||||
public class PageExtension implements ParameterResolver, AfterEachCallback {
|
||||
private static final ThreadLocal<Page> threadLocalPage = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext extensionContext) {
|
||||
Page page = threadLocalPage.get();
|
||||
threadLocalPage.remove();
|
||||
if (page != null) {
|
||||
page.close();
|
||||
}
|
||||
}
|
||||
public class PageExtension implements ParameterResolver {
|
||||
private static final ThreadLocal<Page> threadLocalPage = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
@@ -45,7 +35,14 @@ public class PageExtension implements ParameterResolver, AfterEachCallback {
|
||||
return getOrCreatePage(extensionContext);
|
||||
}
|
||||
|
||||
static Page getOrCreatePage(ExtensionContext extensionContext) {
|
||||
/**
|
||||
* Returns the Page that belongs to the current test. Will be created if it doesn't already exist.
|
||||
* <strong>NOTE:</strong> this method is subject to change.
|
||||
*
|
||||
* @param extensionContext the context in which the current test or container is being executed.
|
||||
* @return The Page that belongs to the current test.
|
||||
*/
|
||||
public static Page getOrCreatePage(ExtensionContext extensionContext) {
|
||||
Page page = threadLocalPage.get();
|
||||
if (page != null) {
|
||||
return page;
|
||||
@@ -56,4 +53,8 @@ public class PageExtension implements ParameterResolver, AfterEachCallback {
|
||||
threadLocalPage.set(page);
|
||||
return page;
|
||||
}
|
||||
|
||||
static void cleanUpPage() {
|
||||
threadLocalPage.remove();
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
package com.microsoft.playwright.impl.junit;
|
||||
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
@@ -27,8 +27,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.setTestIdAttribute;
|
||||
import static com.microsoft.playwright.impl.junit.ExtensionUtils.*;
|
||||
|
||||
public class PlaywrightExtension implements ParameterResolver {
|
||||
private static final ThreadLocal<Playwright> threadLocalPlaywright = new ThreadLocal<>();
|
||||
@@ -79,7 +78,13 @@ public class PlaywrightExtension implements ParameterResolver {
|
||||
return getOrCreatePlaywright(extensionContext);
|
||||
}
|
||||
|
||||
static Playwright getOrCreatePlaywright(ExtensionContext extensionContext) {
|
||||
/**
|
||||
* Returns the Playwright that belongs to the current test. Will be created if it doesn't already exist.
|
||||
* <strong>NOTE:</strong> this method is subject to change.
|
||||
* @param extensionContext the context in which the current test or container is being executed.
|
||||
* @return The Playwright that belongs to the current test.
|
||||
*/
|
||||
public static Playwright getOrCreatePlaywright(ExtensionContext extensionContext) {
|
||||
Playwright playwright = threadLocalPlaywright.get();
|
||||
if (playwright != null) {
|
||||
return playwright;
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package com.microsoft.playwright.junit;
|
||||
|
||||
import com.microsoft.playwright.APIRequest;
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> this API is experimental and is subject to changes.
|
||||
@@ -43,6 +42,40 @@ public class Options {
|
||||
public Browser.NewContextOptions contextOptions;
|
||||
public APIRequest.NewContextOptions apiRequestOptions;
|
||||
public Playwright.CreateOptions playwrightCreateOptions;
|
||||
// WebSocket endpoint to be used when connecting to a remote browser.
|
||||
// If this is set, BrowserType.connect will be used. Otherwise, BrowserType.launch will be used.
|
||||
public String wsEndpoint;
|
||||
public BrowserType.ConnectOptions connectOptions;
|
||||
// The dir where test artifacts will be stored
|
||||
public Path outputDir;
|
||||
// When to record traces. Default is OFF.
|
||||
public Trace trace = Trace.OFF;
|
||||
|
||||
public enum Trace {
|
||||
OFF,
|
||||
ON,
|
||||
RETAIN_ON_FAILURE;
|
||||
}
|
||||
|
||||
public Options setTrace(Trace trace) {
|
||||
this.trace = trace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setOutputDir(Path outputDir) {
|
||||
this.outputDir = outputDir;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setWsEndpoint(String wsEndpoint) {
|
||||
this.wsEndpoint = wsEndpoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setConnectOptions(BrowserType.ConnectOptions connectOptions) {
|
||||
this.connectOptions = connectOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setPlaywrightCreateOptions(Playwright.CreateOptions playwrightCreateOptions) {
|
||||
this.playwrightCreateOptions = playwrightCreateOptions;
|
||||
|
||||
@@ -16,14 +16,10 @@
|
||||
|
||||
package com.microsoft.playwright.junit;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.junit.impl.*;
|
||||
import com.microsoft.playwright.impl.junit.*;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> this API is experimental and is subject to changes.
|
||||
@@ -80,6 +76,7 @@ import java.lang.annotation.Target;
|
||||
PageExtension.class, APIRequestContextExtension.class})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
public @interface UsePlaywright {
|
||||
Class<? extends OptionsFactory> value() default DefaultOptions.class;
|
||||
}
|
||||
|
||||
-97
@@ -1,97 +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.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserContext;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.*;
|
||||
|
||||
public class BrowserContextExtension implements ParameterResolver, AfterEachCallback {
|
||||
private static final ThreadLocal<BrowserContext> threadLocalBrowserContext = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext extensionContext) {
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
threadLocalBrowserContext.remove();
|
||||
if (browserContext != null) {
|
||||
browserContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return !isClassHook(extensionContext) && isParameterSupported(parameterContext, extensionContext, BrowserContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return getOrCreateBrowserContext(extensionContext);
|
||||
}
|
||||
|
||||
static BrowserContext getOrCreateBrowserContext(ExtensionContext extensionContext) {
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
if (browserContext != null) {
|
||||
return browserContext;
|
||||
}
|
||||
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
||||
setTestIdAttribute(playwright, options);
|
||||
Browser browser = BrowserExtension.getOrCreateBrowser(extensionContext);
|
||||
Browser.NewContextOptions contextOptions = getContextOptions(playwright, options);
|
||||
browserContext = browser.newContext(contextOptions);
|
||||
threadLocalBrowserContext.set(browserContext);
|
||||
return browserContext;
|
||||
}
|
||||
|
||||
private static Browser.NewContextOptions getContextOptions(Playwright playwright, Options options) {
|
||||
Browser.NewContextOptions contextOptions = Utils.clone(options.contextOptions);
|
||||
if (contextOptions == null) {
|
||||
contextOptions = new Browser.NewContextOptions();
|
||||
}
|
||||
|
||||
if (options.baseUrl != null) {
|
||||
contextOptions.setBaseURL(options.baseUrl);
|
||||
}
|
||||
|
||||
if (options.deviceName != null) {
|
||||
DeviceDescriptor deviceDescriptor = DeviceDescriptor.findByName(playwright, options.deviceName);
|
||||
if (deviceDescriptor == null) {
|
||||
throw new PlaywrightException("Unknown device name: " + options.deviceName);
|
||||
}
|
||||
contextOptions.userAgent = deviceDescriptor.userAgent;
|
||||
if (deviceDescriptor.viewport != null) {
|
||||
contextOptions.setViewportSize(deviceDescriptor.viewport.width, deviceDescriptor.viewport.height);
|
||||
}
|
||||
contextOptions.deviceScaleFactor = deviceDescriptor.deviceScaleFactor;
|
||||
contextOptions.isMobile = deviceDescriptor.isMobile;
|
||||
contextOptions.hasTouch = deviceDescriptor.hasTouch;
|
||||
}
|
||||
|
||||
if(options.ignoreHTTPSErrors != null) {
|
||||
contextOptions.setIgnoreHTTPSErrors(options.ignoreHTTPSErrors);
|
||||
}
|
||||
|
||||
return contextOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ClientCertificate {
|
||||
/**
|
||||
* Exact origin that the certificate is valid for. Origin includes {@code https} protocol, a hostname and optionally a
|
||||
* port.
|
||||
*/
|
||||
public String origin;
|
||||
/**
|
||||
* Path to the file with the certificate in PEM format.
|
||||
*/
|
||||
public Path certPath;
|
||||
/**
|
||||
* Direct value of the certificate in PEM format.
|
||||
*/
|
||||
public byte[] cert;
|
||||
/**
|
||||
* Path to the file with the private key in PEM format.
|
||||
*/
|
||||
public Path keyPath;
|
||||
/**
|
||||
* Direct value of the private key in PEM format.
|
||||
*/
|
||||
public byte[] key;
|
||||
/**
|
||||
* Path to the PFX or PKCS12 encoded private key and certificate chain.
|
||||
*/
|
||||
public Path pfxPath;
|
||||
/**
|
||||
* Direct value of the PFX or PKCS12 encoded private key and certificate chain.
|
||||
*/
|
||||
public byte[] pfx;
|
||||
/**
|
||||
* Passphrase for the private key (PEM or PFX).
|
||||
*/
|
||||
public String passphrase;
|
||||
|
||||
public ClientCertificate(String origin) {
|
||||
this.origin = origin;
|
||||
}
|
||||
/**
|
||||
* Path to the file with the certificate in PEM format.
|
||||
*/
|
||||
public ClientCertificate setCertPath(Path certPath) {
|
||||
this.certPath = certPath;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Direct value of the certificate in PEM format.
|
||||
*/
|
||||
public ClientCertificate setCert(byte[] cert) {
|
||||
this.cert = cert;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Path to the file with the private key in PEM format.
|
||||
*/
|
||||
public ClientCertificate setKeyPath(Path keyPath) {
|
||||
this.keyPath = keyPath;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Direct value of the private key in PEM format.
|
||||
*/
|
||||
public ClientCertificate setKey(byte[] key) {
|
||||
this.key = key;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Path to the PFX or PKCS12 encoded private key and certificate chain.
|
||||
*/
|
||||
public ClientCertificate setPfxPath(Path pfxPath) {
|
||||
this.pfxPath = pfxPath;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Direct value of the PFX or PKCS12 encoded private key and certificate chain.
|
||||
*/
|
||||
public ClientCertificate setPfx(byte[] pfx) {
|
||||
this.pfx = pfx;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Passphrase for the private key (PEM or PFX).
|
||||
*/
|
||||
public ClientCertificate setPassphrase(String passphrase) {
|
||||
this.passphrase = passphrase;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -20,15 +20,16 @@ public class Cookie {
|
||||
public String name;
|
||||
public String value;
|
||||
/**
|
||||
* either url or domain / path are required. Optional.
|
||||
* Either url or domain / path are required. Optional.
|
||||
*/
|
||||
public String url;
|
||||
/**
|
||||
* either url or domain / path are required Optional.
|
||||
* For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com". Either url or
|
||||
* domain / path are required. Optional.
|
||||
*/
|
||||
public String domain;
|
||||
/**
|
||||
* either url or domain / path are required Optional.
|
||||
* Either url or domain / path are required Optional.
|
||||
*/
|
||||
public String path;
|
||||
/**
|
||||
@@ -53,21 +54,22 @@ public class Cookie {
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* either url or domain / path are required. Optional.
|
||||
* Either url or domain / path are required. Optional.
|
||||
*/
|
||||
public Cookie setUrl(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* either url or domain / path are required Optional.
|
||||
* For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com". Either url or
|
||||
* domain / path are required. Optional.
|
||||
*/
|
||||
public Cookie setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* either url or domain / path are required Optional.
|
||||
* Either url or domain / path are required Optional.
|
||||
*/
|
||||
public Cookie setPath(String path) {
|
||||
this.path = path;
|
||||
|
||||
@@ -32,6 +32,141 @@ import java.nio.file.Path;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface FormData {
|
||||
/**
|
||||
* Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File
|
||||
* values can be passed either as {@code Path} or as {@code FilePayload}. Multiple fields with the same name can be added.
|
||||
*
|
||||
* <p> The difference between {@link com.microsoft.playwright.FormData#set FormData.set()} and {@link
|
||||
* com.microsoft.playwright.FormData#append FormData.append()} is that if the specified key already exists, {@link
|
||||
* com.microsoft.playwright.FormData#set FormData.set()} will overwrite all existing values with the new one, whereas
|
||||
* {@link com.microsoft.playwright.FormData#append FormData.append()} will append the new value onto the end of the
|
||||
* existing set of values.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .append("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .append("attachment", Paths.get("pic.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .append("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv"))));
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
* @since v1.44
|
||||
*/
|
||||
FormData append(String name, String value);
|
||||
/**
|
||||
* Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File
|
||||
* values can be passed either as {@code Path} or as {@code FilePayload}. Multiple fields with the same name can be added.
|
||||
*
|
||||
* <p> The difference between {@link com.microsoft.playwright.FormData#set FormData.set()} and {@link
|
||||
* com.microsoft.playwright.FormData#append FormData.append()} is that if the specified key already exists, {@link
|
||||
* com.microsoft.playwright.FormData#set FormData.set()} will overwrite all existing values with the new one, whereas
|
||||
* {@link com.microsoft.playwright.FormData#append FormData.append()} will append the new value onto the end of the
|
||||
* existing set of values.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .append("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .append("attachment", Paths.get("pic.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .append("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv"))));
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
* @since v1.44
|
||||
*/
|
||||
FormData append(String name, boolean value);
|
||||
/**
|
||||
* Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File
|
||||
* values can be passed either as {@code Path} or as {@code FilePayload}. Multiple fields with the same name can be added.
|
||||
*
|
||||
* <p> The difference between {@link com.microsoft.playwright.FormData#set FormData.set()} and {@link
|
||||
* com.microsoft.playwright.FormData#append FormData.append()} is that if the specified key already exists, {@link
|
||||
* com.microsoft.playwright.FormData#set FormData.set()} will overwrite all existing values with the new one, whereas
|
||||
* {@link com.microsoft.playwright.FormData#append FormData.append()} will append the new value onto the end of the
|
||||
* existing set of values.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .append("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .append("attachment", Paths.get("pic.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .append("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv"))));
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
* @since v1.44
|
||||
*/
|
||||
FormData append(String name, int value);
|
||||
/**
|
||||
* Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File
|
||||
* values can be passed either as {@code Path} or as {@code FilePayload}. Multiple fields with the same name can be added.
|
||||
*
|
||||
* <p> The difference between {@link com.microsoft.playwright.FormData#set FormData.set()} and {@link
|
||||
* com.microsoft.playwright.FormData#append FormData.append()} is that if the specified key already exists, {@link
|
||||
* com.microsoft.playwright.FormData#set FormData.set()} will overwrite all existing values with the new one, whereas
|
||||
* {@link com.microsoft.playwright.FormData#append FormData.append()} will append the new value onto the end of the
|
||||
* existing set of values.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .append("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .append("attachment", Paths.get("pic.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .append("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv"))));
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
* @since v1.44
|
||||
*/
|
||||
FormData append(String name, Path value);
|
||||
/**
|
||||
* Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File
|
||||
* values can be passed either as {@code Path} or as {@code FilePayload}. Multiple fields with the same name can be added.
|
||||
*
|
||||
* <p> The difference between {@link com.microsoft.playwright.FormData#set FormData.set()} and {@link
|
||||
* com.microsoft.playwright.FormData#append FormData.append()} is that if the specified key already exists, {@link
|
||||
* com.microsoft.playwright.FormData#set FormData.set()} will overwrite all existing values with the new one, whereas
|
||||
* {@link com.microsoft.playwright.FormData#append FormData.append()} will append the new value onto the end of the
|
||||
* existing set of values.
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.options.FormData;
|
||||
* ...
|
||||
* FormData form = FormData.create()
|
||||
* // Only name and value are set.
|
||||
* .append("firstName", "John")
|
||||
* // Name and value are set, filename and Content-Type are inferred from the file path.
|
||||
* .append("attachment", Paths.get("pic.jpg"))
|
||||
* // Name, value, filename and Content-Type are set.
|
||||
* .append("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv"))));
|
||||
* page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Field name.
|
||||
* @param value Field value.
|
||||
* @since v1.44
|
||||
*/
|
||||
FormData append(String name, FilePayload value);
|
||||
/**
|
||||
* Creates new instance of {@code FormData}.
|
||||
*
|
||||
@@ -51,7 +186,7 @@ public interface FormData {
|
||||
* // 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("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>
|
||||
@@ -72,7 +207,7 @@ public interface FormData {
|
||||
* // 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("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>
|
||||
@@ -93,7 +228,7 @@ public interface FormData {
|
||||
* // 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("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>
|
||||
@@ -114,7 +249,7 @@ public interface FormData {
|
||||
* // 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("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>
|
||||
@@ -135,7 +270,7 @@ public interface FormData {
|
||||
* // 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("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>
|
||||
|
||||
@@ -23,6 +23,13 @@ public class HttpCredentials {
|
||||
* Restrain sending http credentials on specific origin (scheme://host:port).
|
||||
*/
|
||||
public String origin;
|
||||
/**
|
||||
* This option only applies to the requests sent from corresponding {@code APIRequestContext} and does not affect requests
|
||||
* sent from the browser. {@code "always"} - {@code Authorization} header with basic authentication credentials will be
|
||||
* sent with the each API request. {@code 'unauthorized} - the credentials are only sent when 401 (Unauthorized) response
|
||||
* with {@code WWW-Authenticate} header is received. Defaults to {@code "unauthorized"}.
|
||||
*/
|
||||
public HttpCredentialsSend send;
|
||||
|
||||
public HttpCredentials(String username, String password) {
|
||||
this.username = username;
|
||||
@@ -35,4 +42,14 @@ public class HttpCredentials {
|
||||
this.origin = origin;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* This option only applies to the requests sent from corresponding {@code APIRequestContext} and does not affect requests
|
||||
* sent from the browser. {@code "always"} - {@code Authorization} header with basic authentication credentials will be
|
||||
* sent with the each API request. {@code 'unauthorized} - the credentials are only sent when 401 (Unauthorized) response
|
||||
* with {@code WWW-Authenticate} header is received. Defaults to {@code "unauthorized"}.
|
||||
*/
|
||||
public HttpCredentials setSend(HttpCredentialsSend send) {
|
||||
this.send = send;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 HttpCredentialsSend {
|
||||
UNAUTHORIZED,
|
||||
ALWAYS
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.microsoft.playwright.options;
|
||||
public enum KeyboardModifier {
|
||||
ALT,
|
||||
CONTROL,
|
||||
CONTROLORMETA,
|
||||
META,
|
||||
SHIFT
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import com.microsoft.playwright.impl.RequestOptionsImpl;
|
||||
* .setData("My data"));
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Uploading html form data**
|
||||
* <p> <strong>Uploading html form data</strong>
|
||||
*
|
||||
* <p> {@code FormData} class can be used to send a form to the server, by default the request will use {@code
|
||||
* application/x-www-form-urlencoded} encoding:
|
||||
@@ -133,6 +133,15 @@ public interface RequestOptions {
|
||||
* @since v1.26
|
||||
*/
|
||||
RequestOptions setMaxRedirects(int maxRedirects);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param maxRetries Maximum number of times network errors should be retried. Currently only {@code ECONNRESET} error is retried. Does not
|
||||
* retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to {@code 0} - no
|
||||
* retries.
|
||||
* @since v1.46
|
||||
*/
|
||||
RequestOptions setMaxRetries(int maxRetries);
|
||||
/**
|
||||
* Changes the request method (e.g. <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT">PUT</a> or <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST">POST</a>).
|
||||
|
||||
@@ -19,11 +19,15 @@ package com.microsoft.playwright;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
class HttpsConfiguratorImpl extends HttpsConfigurator {
|
||||
|
||||
@@ -31,7 +35,7 @@ class HttpsConfiguratorImpl extends HttpsConfigurator {
|
||||
return new HttpsConfiguratorImpl(createSSLContext());
|
||||
}
|
||||
|
||||
private HttpsConfiguratorImpl(SSLContext context) {
|
||||
HttpsConfiguratorImpl(SSLContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -39,8 +43,8 @@ class HttpsConfiguratorImpl extends HttpsConfigurator {
|
||||
public void configure(HttpsParameters params) {
|
||||
SSLContext sslContext = getSSLContext();
|
||||
SSLParameters sslParams = sslContext.getDefaultSSLParameters();
|
||||
sslParams.setNeedClientAuth(true);
|
||||
params.setNeedClientAuth(true);
|
||||
sslParams.setWantClientAuth(true);
|
||||
params.setWantClientAuth(true);
|
||||
params.setSSLParameters(sslParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.sun.net.httpserver.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -73,11 +72,8 @@ public class Server implements HttpHandler {
|
||||
} else {
|
||||
server = HttpServer.create(new InetSocketAddress("localhost", port), 0);
|
||||
}
|
||||
|
||||
server.createContext("/", this);
|
||||
server.setExecutor(null); // creates a default executor
|
||||
|
||||
File cwd = FileSystems.getDefault().getPath(".").toFile();
|
||||
server.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.cert.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ServerWithClientCertificate implements HttpHandler {
|
||||
private final HttpServer server;
|
||||
final String origin;
|
||||
final String crossOrigin;
|
||||
final String url;
|
||||
KeyStore keyStore;
|
||||
|
||||
static ServerWithClientCertificate create(int port) throws IOException {
|
||||
return new ServerWithClientCertificate(port);
|
||||
}
|
||||
|
||||
private ServerWithClientCertificate(int port) throws IOException {
|
||||
origin = "https://localhost:" + port;
|
||||
crossOrigin = "https://127.0.0.1:" + port;;
|
||||
url = origin + "/index.html";
|
||||
HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress("localhost", port), 0);
|
||||
httpsServer.setHttpsConfigurator(new HttpsConfiguratorImpl(loadCertificates()));
|
||||
server = httpsServer;
|
||||
server.createContext("/", this);
|
||||
server.setExecutor(null); // creates a default executor
|
||||
server.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
server.stop(0);
|
||||
}
|
||||
|
||||
private SSLContext loadCertificates() {
|
||||
try {
|
||||
// Create an SSL context
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
||||
// Load the keystore from file
|
||||
char[] password = "".toCharArray(); // the password you set during the PKCS12 export
|
||||
keyStore = KeyStore.getInstance("PKCS12");
|
||||
InputStream fis = HttpsConfiguratorImpl.class.getClassLoader().getResourceAsStream(
|
||||
"resources/client-certificates/server/server_keystore.p12");
|
||||
keyStore.load(fis, password);
|
||||
|
||||
// Set up the KeyManagerFactory to use the keystore
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
|
||||
kmf.init(keyStore, password);
|
||||
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
List<X509Certificate> certs = new ArrayList<>();
|
||||
try {
|
||||
for (String alias : Collections.list(keyStore.aliases())) {
|
||||
certs.add((X509Certificate) keyStore.getCertificate(alias));
|
||||
}
|
||||
} catch (KeyStoreException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return certs.toArray(new X509Certificate[0]);
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] clientCerts, String authType) throws CertificateException {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize the SSL context
|
||||
sslContext.init(kmf.getKeyManagers(), trustAllCerts, null);
|
||||
return sslContext;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateCertChain(Certificate[] clientCerts) {
|
||||
try {
|
||||
// Create CertPath from the provided client certificates
|
||||
CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||
CertPath certPath = factory.generateCertPath(Arrays.asList(clientCerts));
|
||||
|
||||
// Extract Trust Anchors from the trust store
|
||||
Set<TrustAnchor> trustAnchors = new HashSet<>();
|
||||
for (String alias : Collections.list(keyStore.aliases())) {
|
||||
X509Certificate trustedCert = (X509Certificate) keyStore.getCertificate(alias);
|
||||
if (trustedCert != null) {
|
||||
trustAnchors.add(new TrustAnchor(trustedCert, null));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize PKIX parameters
|
||||
PKIXParameters params = new PKIXParameters(trustAnchors);
|
||||
params.setRevocationEnabled(false); // Set to true if you want to enable CRL checking
|
||||
|
||||
// Validate the certification path
|
||||
CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType());
|
||||
certPathValidator.validate(certPath, params);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String div(String testId, String message) {
|
||||
return "<div data-testid='" + testId + "'>" + message + "</div>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException {
|
||||
SSLSession sslSession = ((HttpsExchange) exchange).getSSLSession();
|
||||
String response = div("servername", sslSession.getPeerHost());
|
||||
try {
|
||||
Certificate[] certs = sslSession.getPeerCertificates();
|
||||
X509Certificate cert = (X509Certificate) certs[0];
|
||||
exchange.getResponseHeaders().add("Content-Type", "text/html");
|
||||
if (validateCertChain(certs)) {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
response += div("message", String.format("Hello %s, your certificate was issued by %s!",
|
||||
cert.getSubjectX500Principal().getName(), cert.getIssuerX500Principal().getName()));
|
||||
} else {
|
||||
response += div("message", String.format("Sorry %s, certificates from %s are not welcome here.",
|
||||
cert.getSubjectX500Principal().getName(), cert.getIssuerX500Principal().getName()));
|
||||
exchange.sendResponseHeaders(403, 0);
|
||||
}
|
||||
} catch (SSLPeerUnverifiedException e) {
|
||||
response += div("message", "Sorry, but you need to provide a client certificate to continue.");
|
||||
exchange.sendResponseHeaders(401, 0);
|
||||
}
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.AssertionFailedError;
|
||||
|
||||
@@ -25,21 +27,23 @@ import java.io.Writer;
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestAPIResponseAssertions extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestAPIResponseAssertions {
|
||||
@Test
|
||||
void passWithResponse() {
|
||||
void passWithResponse(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.EMPTY_PAGE);
|
||||
assertThat(res).isOK();
|
||||
}
|
||||
|
||||
@Test
|
||||
void passWithNot() {
|
||||
void passWithNot(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.PREFIX + "/unknown");
|
||||
assertThat(res).not().isOK();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fail() {
|
||||
void fail(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.PREFIX + "/unknown");
|
||||
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(res).isOK());
|
||||
assertTrue(e.getMessage().contains("→ GET " + server.PREFIX + "/unknown"), "Actual error: " + e.toString());
|
||||
@@ -47,14 +51,14 @@ public class TestAPIResponseAssertions extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPrintResponseTextIfIdOkFails() {
|
||||
void shouldPrintResponseTextIfIdOkFails(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.PREFIX + "/unknown");
|
||||
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(res).isOK());
|
||||
assertTrue(e.getMessage().contains("File not found"), "Actual error: " + e.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldOnlyPrintResponseWithTextContentTypeIfIsOkFails() {
|
||||
void shouldOnlyPrintResponseWithTextContentTypeIfIsOkFails(Page page, Server server) {
|
||||
{
|
||||
server.setRoute("/text-content-type", exchange -> {
|
||||
exchange.getResponseHeaders().set("Content-type", "text/plain");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user