Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c949d8398d | |||
| 793b1d3d61 | |||
| 8f66ef1f13 | |||
| dc66e4d1a3 | |||
| d84a2db0b3 | |||
| f081667e44 | |||
| 5b33729849 | |||
| b01bf64e64 | |||
| 7dbd6cac3b | |||
| c3e4b92982 | |||
| 9e73db411c | |||
| 10ed7e036d | |||
| 5ccdd3e4b9 | |||
| afd80add27 | |||
| 605e428fd7 | |||
| 932669036b | |||
| 480400793e | |||
| 647d8fc034 | |||
| b5c2160d32 |
@@ -0,0 +1,76 @@
|
||||
---
|
||||
name: playwright-java-release
|
||||
description: Prepare a Playwright Java release after the rolling PR has merged — cut the release branch, mark the Maven version, draft the GitHub release, and tick the Java boxes in the internal checklist.
|
||||
---
|
||||
|
||||
Use this skill once the `chore: roll driver to 1.X.0` PR has merged into `main` and the upstream JS `v1.X.0` is published. The rolling work itself is covered by the [[playwright-roll]] skill.
|
||||
|
||||
Throughout this doc, replace `X` with the minor version (e.g. `60` for `1.60.0`) and `<user>` with the fork owner (`gh api user --jq .login`).
|
||||
|
||||
The full release checklist lives in the private `microsoft/playwright-internal` repo as the `v1.X checklist` issue. Find its number once:
|
||||
|
||||
```bash
|
||||
unset GITHUB_TOKEN
|
||||
ISSUE=$(gh search issues --repo microsoft/playwright-internal "v1.X checklist" --json number --jq '.[0].number')
|
||||
```
|
||||
|
||||
Tick each Java box incrementally (one PATCH per item) so the issue reflects accurate state if the flow is interrupted:
|
||||
|
||||
```bash
|
||||
gh api repos/microsoft/playwright-internal/issues/$ISSUE --jq '.body' > /tmp/body.md
|
||||
# edit /tmp/body.md to flip "- [ ]" → "- [x]" on the relevant Java item
|
||||
gh api repos/microsoft/playwright-internal/issues/$ISSUE -X PATCH --field body=@/tmp/body.md
|
||||
```
|
||||
|
||||
## 1. Cut the release branch
|
||||
|
||||
Push `release-1.X` from current `upstream/main` (which now contains the merged roll commit):
|
||||
|
||||
```bash
|
||||
git fetch upstream main
|
||||
git push upstream upstream/main:refs/heads/release-1.X
|
||||
```
|
||||
|
||||
## 2. Draft the GitHub release
|
||||
|
||||
Generate the release notes from the upstream docs:
|
||||
|
||||
```bash
|
||||
cd ~/playwright
|
||||
node utils/render_release_notes.mjs java 1.X > /tmp/v1.X.0-release-notes.md
|
||||
```
|
||||
|
||||
The renderer leaves JS-isms that need fixing for Java. Apply these substitutions — the list is not exhaustive, eyeball the diff before publishing:
|
||||
|
||||
- `toMatchAriaSnapshot()` → `matchesAriaSnapshot()`
|
||||
- `toHaveCSS()` → `hasCSS()` (and other `toHaveX` matchers → `hasX`)
|
||||
- `browser.on('context')` → `browser.onContext()`
|
||||
- `browserContext.on('download' | 'frameattached' | ...)` → `browserContext.onDownload()` / `onFrameAttached()` / …
|
||||
|
||||
Create the draft directly against `release-1.X` — drafting against `main` and retargeting later is fragile because every `gh release edit` rotates the `untagged-<hash>` ID:
|
||||
|
||||
```bash
|
||||
gh release create v1.X.0 --repo microsoft/playwright-java --draft \
|
||||
--title "v1.X.0" --notes-file /tmp/v1.X.0-release-notes.md --target release-1.X
|
||||
```
|
||||
|
||||
## 3. Bump the Maven version on the release branch
|
||||
|
||||
Cut `mark-v-1.X.0` off `upstream/release-1.X`, run `set_maven_version.sh`, and PR back to the release branch:
|
||||
|
||||
```bash
|
||||
git checkout -b mark-v-1.X.0 upstream/release-1.X
|
||||
./scripts/set_maven_version.sh 1.X.0
|
||||
git add -u
|
||||
git commit -m "chore: mark 1.X.0"
|
||||
git push -u origin mark-v-1.X.0
|
||||
gh pr create --repo microsoft/playwright-java --head <user>:mark-v-1.X.0 --base release-1.X \
|
||||
--title "chore: mark 1.X.0" \
|
||||
--body "Updates Maven version in all modules to \`1.X.0\` for the v1.X release."
|
||||
```
|
||||
|
||||
`set_maven_version.sh` only invokes `mvn versions:set` on `pom.xml`, `tools/*/pom.xml`, and `examples/pom.xml`, but the root invocation cascades through the reactor, so the expected diff is 11 poms: root + `driver/` + `driver-bundle/` + `playwright/` (from the reactor cascade) + 6 under `tools/` + `examples/`, all flipping `1.<prev>.0-SNAPSHOT` → `1.X.0`. Any other file in the diff is a red flag.
|
||||
|
||||
## 4. Publish
|
||||
|
||||
The user publishes the draft release manually once the `mark-v-1.X.0` PR is merged. After publishing, CI pushes the artifacts to Maven Central and runs the Docker workflow automatically: https://github.com/microsoft/playwright-java/actions.
|
||||
@@ -0,0 +1,202 @@
|
||||
---
|
||||
name: playwright-roll
|
||||
description: Roll Playwright Java to a new version
|
||||
---
|
||||
|
||||
Help the user roll to a new version of Playwright.
|
||||
ROLLING.md contains general instructions and scripts.
|
||||
|
||||
Start with running ./scripts/roll_driver.sh to update the version and generate the API to see the state of things.
|
||||
Afterwards, walk through the upstream changes that affect the Java client and port the relevant ones.
|
||||
|
||||
## Determining what to port
|
||||
|
||||
List the upstream commits that touched a client-relevant path since the last release. The paths cover everything that can change the public Java surface or the wire protocol:
|
||||
|
||||
- `docs/src/api/` — the source of truth for `api.json`. Method/option additions, removals, and `langs:` filter changes flow from here.
|
||||
- `packages/playwright-core/src/client/` — the JS client implementation that the Java client mirrors.
|
||||
- `packages/isomorphic/` — selector engines, locator generation/parsing, and aria-snapshot logic shared between client and server. Changes here can affect client-side helpers like `getByRoleSelector`.
|
||||
- `packages/playwright/src/matchers/matchers.ts` — assertion-method definitions. Changes here usually correspond to new options on `LocatorAssertions` / `PageAssertions`.
|
||||
- `packages/protocol/src/protocol.yml` — the wire protocol schema. Method/event additions, parameter renames, and result-shape changes affect what the Java `*Impl` classes need to send/receive.
|
||||
|
||||
```bash
|
||||
cd ~/playwright
|
||||
PREV_TAG=$(git tag | grep -E '^v1\.[0-9]+\.[0-9]+$' | sort -V | tail -1) # e.g. v1.59.1
|
||||
git log "$PREV_TAG"..HEAD --oneline -- \
|
||||
'docs/src/api/' \
|
||||
'packages/playwright-core/src/client/' \
|
||||
'packages/isomorphic/' \
|
||||
'packages/playwright/src/matchers/matchers.ts' \
|
||||
'packages/protocol/src/protocol.yml'
|
||||
```
|
||||
|
||||
Walk that list top-to-bottom (oldest-first is easier — newest is at top, so reverse). For each commit:
|
||||
1. Read the commit (`git show <sha>`) to see what client/protocol/docs changed.
|
||||
2. If it's JS-internal (bundling, dispatcher conventions, electron, mcp, dashboard, trace-viewer, test-runner) — skip.
|
||||
3. If it touches `docs/src/api/` or types, check `langs:` annotations — features marked `langs: js`/`langs: js, python` don't apply to Java.
|
||||
4. If it adds/changes a public API method or option that applies to Java, port it. The api.json regenerated by `roll_driver.sh` already contains the new types/options, so the generated Java interfaces usually pick them up automatically — what's typically missing is the `*Impl` wiring.
|
||||
5. Watch for follow-up reverts — a "feat: X" commit might be undone by a later "Revert X". Check whether the change still exists in HEAD before porting.
|
||||
6. Maintain a running notes file (e.g. `/tmp/roll-notes.md`) listing each upstream PR as ported / skipped / verified-already-supported, with a one-line reason. This file becomes the body of the eventual PR.
|
||||
|
||||
## What to include in the rolling PR
|
||||
|
||||
- Driver version bump
|
||||
- Generated interface diffs from `roll_driver.sh`
|
||||
- `*Impl` wiring for each ported feature
|
||||
- Generator updates (import lists, special-cases) if new types appeared
|
||||
- A small test per new public API surface — listener for new events, basic call for new methods, regression for changed return types
|
||||
- PR description: list each upstream PR ported, each skipped (with reason), and each verified-already-supported
|
||||
|
||||
Rolling includes:
|
||||
- updating client implementation to match changes in the upstream JS implementation (see ../playwright/packages/playwright-core/src/client)
|
||||
- adding a couple of new tests to verify new/changed functionality
|
||||
|
||||
## Mimicking the JavaScript implementation
|
||||
|
||||
The Java client is a port of the JS client in `../playwright/packages/playwright-core/src/client/`. When implementing a new or changed method, always read the corresponding JS file first and mirror its logic:
|
||||
|
||||
```
|
||||
../playwright/packages/playwright-core/src/client/browserContext.ts
|
||||
../playwright/packages/playwright-core/src/client/page.ts
|
||||
../playwright/packages/playwright-core/src/client/tracing.ts
|
||||
../playwright/packages/playwright-core/src/client/video.ts
|
||||
../playwright/packages/playwright-core/src/client/locator.ts
|
||||
../playwright/packages/playwright-core/src/client/network.ts
|
||||
...
|
||||
```
|
||||
|
||||
Key translation rules:
|
||||
|
||||
**Protocol calls** — `await this._channel.methodName(params)` → `sendMessage("methodName", params, NO_TIMEOUT)`
|
||||
|
||||
**Extracting a returned channel object from a result** — JS uses `SomeClass.from(result.foo)` which resolves the JS-side object for a channel reference. In Java, the object was already created when the server sent `__create__`, so extract it from the connection: `connection.getExistingObject(result.getAsJsonObject("foo").get("guid").getAsString())`
|
||||
|
||||
**Async/await** — all `await` calls become synchronous `sendMessage(...)` calls since the Java client is synchronous.
|
||||
|
||||
**`undefined` / optional params** — JS `options?.foo` checks translate to `if (options != null && options.foo != null)` null checks before adding to the params `JsonObject`.
|
||||
|
||||
**`_channel` fields** — the JS `this._channel.foo` maps to calling `sendMessage("foo", ...)` on `this` in the Impl class.
|
||||
|
||||
**Channel object references in params** — when a JS call passes a channel object as a param (e.g. `{ frame: frame._channel }`), in Java pass the guid: `params.addProperty("frame", ((FrameImpl) frame).guid)`.
|
||||
|
||||
## Fixing generator and compilation errors
|
||||
|
||||
After running `./scripts/roll_driver.sh`, the build often fails because the generated Java interfaces reference new types or methods that the generator doesn't know how to handle yet, and the `*Impl` classes don't implement new interface methods.
|
||||
|
||||
### ApiGenerator.java fixes (tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java)
|
||||
|
||||
The generator has hardcoded lists that control which imports are added to each generated file. When new classes appear in the API, add them to the relevant lists in `Interface.writeTo`:
|
||||
- `options.*` import list — add new classes that use types from the options package
|
||||
- `java.util.*` import list — add new classes that use `List`, `Map`, etc.
|
||||
- `java.util.function.Consumer` list — add new classes with `Consumer`-typed event handlers
|
||||
|
||||
Type mapping: when JS-only types (like `Disposable`) are used as return types in Java-compatible methods, add a mapping in `convertBuiltinType`. For example, `Disposable` → `AutoCloseable`.
|
||||
|
||||
Event handler generation: events with `void` type generate invalid `Consumer<void>`. Handle this case in `Event.writeListenerMethods` by emitting `Runnable` instead.
|
||||
|
||||
After editing the generator, recompile and re-run it:
|
||||
```
|
||||
mvn -f tools/api-generator/pom.xml compile -q
|
||||
mvn -f tools/api-generator/pom.xml exec:java -Dexec.mainClass=com.microsoft.playwright.tools.ApiGenerator
|
||||
```
|
||||
|
||||
### Impl class fixes (playwright/src/main/java/com/microsoft/playwright/impl/)
|
||||
|
||||
After regenerating, compile `playwright/` to find what's missing:
|
||||
```
|
||||
mvn -f playwright/pom.xml compile 2>&1 | grep "ERROR"
|
||||
```
|
||||
|
||||
Common patterns:
|
||||
|
||||
**Return type changed (e.g. `void` → `AutoCloseable`):** Update the method signature in the Impl class and return an appropriate `AutoCloseable`. Check the JS client to see what kind of disposable is used:
|
||||
- If JS returns `DisposableObject.from(result.disposable)` — the server created a disposable channel object. Extract its guid from the protocol result and return `connection.getExistingObject(guid)` (a `DisposableObject`).
|
||||
- If JS returns `new DisposableStub(() => this.someCleanup())` — it's a local callback. Return `new DisposableStub(this::someCleanup)` in Java.
|
||||
- Examples: `addInitScript`/`exposeBinding`/`exposeFunction` → `DisposableObject`; `route(...)` → `DisposableStub(() -> unroute(...))`; `Tracing.group` → `DisposableStub(this::groupEnd)`; `Video.start` → `DisposableStub(this::stop)`.
|
||||
|
||||
**New method missing:** Add a stub implementation. Common patterns:
|
||||
- Simple protocol message: `sendMessage("methodName", params, NO_TIMEOUT)`
|
||||
- New property accessor (e.g. from initializer): `return initializer.get("fieldName").getAsString()`
|
||||
- Delegation to mainFrame (for Page methods): `return mainFrame.locator(":root").method(...)`
|
||||
|
||||
**New interface entirely (e.g. `Debugger`):** Create a new `*Impl` class extending `ChannelOwner`, implement the interface, and register the type in `Connection.java`'s switch statement. Initialize the field from the parent's initializer in the parent's constructor (e.g. `connection.getExistingObject(initializer.getAsJsonObject("debugger").get("guid").getAsString())`).
|
||||
|
||||
**Field visibility:** If a field needs to be accessed from a sibling Impl class (e.g. setting `existingResponse` on `RequestImpl` from `BrowserContextImpl`), change it from `private` to package-private.
|
||||
|
||||
**`ListenerCollection` only supports `Consumer<T>`, not `Runnable`.** For void events that use `Runnable` handlers, maintain a plain `List<Runnable>` instead.
|
||||
|
||||
**Protocol changes that remove events** — when a method's response now returns an object directly instead of via a subsequent event, update the Impl to capture it from the `sendMessage` result and remove the old event handler. Example: `videoStart` used to fire a `"video"` page event to deliver the artifact; it now returns the artifact directly in the response. Check git history of the upstream JS client when tests hang unexpectedly.
|
||||
|
||||
**Protocol parameter renames** — protocol parameter names can change between versions (e.g. `wsEndpoint` → `endpoint` in `BrowserType.connect`). When a test fails with `expected string, got undefined` or similar validation errors from the driver, check `packages/protocol/src/protocol.yml` for the current parameter names and update the corresponding `params.addProperty(...)` call in the Impl class. Also check the JS client (`src/client/`) to see how it builds the params object.
|
||||
|
||||
## Rebuilding the driver-bundle after a roll
|
||||
|
||||
`./scripts/roll_driver.sh` does the whole roll pipeline end-to-end: bumps `DRIVER_VERSION`, downloads new driver files into `driver-bundle/src/main/resources/driver/<platform>/`, regenerates `api.json` and the Java interfaces, and updates the README. When all of that succeeds, the next `mvn` invocation that touches `driver-bundle` will pick up the new files and you don't need to think about it.
|
||||
|
||||
But if any step in the pipeline fails (the very common case is the API generator throwing on a new type — see *Fixing generator and compilation errors*), the run aborts before `driver-bundle/target/classes/` has been refreshed. From that point on, until you manually rebuild `driver-bundle`, the test JVM will load the **old** driver from the cached `target/classes`/installed jar even though the source resources have already been swapped to the new version.
|
||||
|
||||
Fix — rebuild `driver-bundle` once before re-running tests:
|
||||
```
|
||||
mvn -f driver-bundle/pom.xml install -DskipTests
|
||||
```
|
||||
|
||||
## Porting and verifying tests
|
||||
|
||||
**Before porting an upstream test file, check the API exists in Java.** The upstream repo may have test files for brand-new APIs that haven't been added to the Java interface yet (e.g., `screencast.spec.ts` tests `page.screencast` which may not be in the generated `Page.java`). Check `git diff main --name-only` to see what interfaces were added this roll, and verify the method exists in the generated Java interface before porting.
|
||||
|
||||
**Java test file names don't always match upstream spec names.** `TestScreencast.java` tests `recordVideo` video-file recording (which corresponds to `video.spec.ts`), not the newer `page.screencast` streaming API (`screencast.spec.ts`). When comparing coverage, check test *content*, not just file names.
|
||||
|
||||
**Remove tests for behavior that was removed upstream.** When the JS client drops a client-side error check (e.g., "Page is not yet closed before saveAs", "Page did not produce any video frames"), delete the corresponding Java tests rather than trying to keep them passing. Check the upstream `tests/library/` spec to confirm the behavior is gone.
|
||||
|
||||
**Run the full suite to catch regressions, re-run flaky failures in isolation.** Some tests (e.g., `TestClientCertificates#shouldKeepSupportingHttp`) time out only under heavy parallel load. Run the failing test alone to confirm it's flaky before investigating further.
|
||||
|
||||
## Diagnosing hanging tests
|
||||
|
||||
When `mvn test` hangs and surefire eventually times the JVM out, it writes thread dumps to `playwright/target/surefire-reports/<timestamp>-jvmRun*.dump`. To find the stuck test:
|
||||
|
||||
```
|
||||
grep "com.microsoft.playwright.Test" playwright/target/surefire-reports/*-jvmRun1.dump | sort -u
|
||||
```
|
||||
|
||||
Each line is a stack frame inside a test method — typically you'll see one or two test methods blocked on a `Future.get()`, `waitForCondition`, or similar. That's the hanging test.
|
||||
|
||||
When you've identified a hanging test:
|
||||
1. Run it in isolation: `mvn -f playwright/pom.xml test -Dtest='TestClass#testMethod'`. If it passes alone, it's a parallel-load flake — note it but move on.
|
||||
2. If it still hangs in isolation, look for a recent fix in the upstream repo for the *same* test name. Use `git log --oneline tests/library/<spec>.spec.ts` in `~/playwright`. Upstream fixes for client-side hangs are often small and portable (e.g. `about:blank` → `server.EMPTY_PAGE` from microsoft/playwright#39840 fixed `route-web-socket.spec.ts` arraybuffer hangs — apparently some browser changed the WebSocket origin policy on `about:blank`).
|
||||
3. When porting an upstream fix, mirror the helper signature change rather than hard-coding workarounds. E.g. if upstream added a `server` parameter to `setupWS`, do the same in Java by injecting `Server server` via the JUnit fixture (`@FixtureTest` already wires up `ServerLifecycle`, so adding `Server server` to the test method signature is enough — no class-level boilerplate). Watch for local-variable shadowing when you add a `Server server` parameter to a method that already has a `WebSocketRoute server` local; rename the local.
|
||||
|
||||
## Commit Convention
|
||||
|
||||
Semantic commit messages: `label(scope): description`
|
||||
|
||||
Labels: `fix`, `feat`, `chore`, `docs`, `test`, `devops`
|
||||
|
||||
```bash
|
||||
git checkout -b fix-39562
|
||||
# ... make changes ...
|
||||
git add <changed-files>
|
||||
git commit -m "$(cat <<'EOF'
|
||||
fix(proxy): handle SOCKS proxy authentication
|
||||
|
||||
Fixes: https://github.com/microsoft/playwright-java/issues/39562
|
||||
EOF
|
||||
)"
|
||||
git push origin fix-39562
|
||||
gh pr create --repo microsoft/playwright-java --head username:fix-39562 \
|
||||
--title "fix(proxy): handle SOCKS proxy authentication" \
|
||||
--body "$(cat <<'EOF'
|
||||
## Summary
|
||||
- <describe the change very! briefly>
|
||||
|
||||
Fixes https://github.com/microsoft/playwright-java/issues/39562
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
Never add Co-Authored-By agents in commit message.
|
||||
Never add "Generated with" in commit message.
|
||||
Branch naming for issue fixes: `fix-<issue-number>`
|
||||
|
||||
## Tips & Tricks
|
||||
- Project checkouts are in the parent directory (`../`).
|
||||
- use the "gh" cli to interact with GitHub
|
||||
@@ -15,7 +15,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Azure login
|
||||
uses: azure/login@v2
|
||||
uses: azure/login@v3
|
||||
with:
|
||||
client-id: ${{ secrets.AZURE_DOCKER_CLIENT_ID }}
|
||||
tenant-id: ${{ secrets.AZURE_DOCKER_TENANT_ID }}
|
||||
@@ -23,7 +23,7 @@ jobs:
|
||||
- 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
|
||||
uses: docker/setup-qemu-action@v4
|
||||
with:
|
||||
platforms: arm64
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
@@ -18,6 +18,14 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
browser: [chromium, firefox, webkit]
|
||||
exclude:
|
||||
# macos-latest is the free M1 runner (3 vCPU / 7 GB); WebKit needs more headroom.
|
||||
# Upstream's webkit matrix runs on macos-15-xlarge for the same reason.
|
||||
- os: macos-latest
|
||||
browser: webkit
|
||||
include:
|
||||
- os: macos-15-xlarge
|
||||
browser: webkit
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
@@ -15,7 +15,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
|
||||
@@ -28,24 +28,49 @@ jobs:
|
||||
matrix:
|
||||
flavor: [jammy, noble]
|
||||
runs-on: [ubuntu-24.04, ubuntu-24.04-arm]
|
||||
include:
|
||||
- runs-on: ubuntu-24.04
|
||||
arch: amd64
|
||||
- runs-on: ubuntu-24.04-arm
|
||||
arch: arm64
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
ARCH="${{ matrix.runs-on == 'ubuntu-24.04-arm' && 'arm64' || 'amd64' }}"
|
||||
bash utils/docker/build.sh --$ARCH ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
|
||||
bash utils/docker/build.sh --${{ matrix.arch }} ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
|
||||
- name: Start container
|
||||
run: |
|
||||
CONTAINER_ID=$(docker run --rm -e CI -e PW_MAX_RETRIES --ipc=host -v "$(pwd)":/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash)
|
||||
CONTAINER_ID=$(docker run \
|
||||
--rm \
|
||||
--name playwright-docker-test \
|
||||
--platform linux/${{ matrix.arch }} \
|
||||
--user=pwuser \
|
||||
--workdir /home/pwuser \
|
||||
--shm-size=2g \
|
||||
-e CI \
|
||||
-e PW_MAX_RETRIES \
|
||||
-d -t \
|
||||
playwright-java:localbuild-${{ matrix.flavor }} /bin/bash)
|
||||
echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV
|
||||
|
||||
- name: Run test in container
|
||||
- name: Copy repository inside docker container
|
||||
run: |
|
||||
docker exec "$CONTAINER_ID" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh
|
||||
docker cp . "$CONTAINER_ID":/home/pwuser/playwright
|
||||
# /root/.m2 was populated as root during image build; move it to
|
||||
# pwuser so the locally-installed SNAPSHOT artifacts resolve.
|
||||
docker exec --user root "$CONTAINER_ID" bash -c '
|
||||
chown -R pwuser /home/pwuser/playwright
|
||||
mv /root/.m2 /home/pwuser/.m2
|
||||
chown -R pwuser /home/pwuser/.m2
|
||||
'
|
||||
|
||||
- name: Run smoke tests in container
|
||||
run: |
|
||||
docker exec "$CONTAINER_ID" /home/pwuser/playwright/tools/test-local-installation/create_project_and_run_tests.sh -Dgroups=smoke
|
||||
|
||||
- name: Test ClassLoader
|
||||
run: |
|
||||
docker exec "${CONTAINER_ID}" /root/playwright/tools/test-spring-boot-starter/package_and_run_async_test.sh
|
||||
docker exec "${CONTAINER_ID}" /home/pwuser/playwright/tools/test-spring-boot-starter/package_and_run_async_test.sh
|
||||
|
||||
- name: Stop container
|
||||
run: |
|
||||
|
||||
@@ -10,9 +10,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->143.0.7499.4<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->26.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->144.0.2<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->148.0.7778.96<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->26.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->150.0.2<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
## Documentation
|
||||
|
||||
|
||||
+2
-14
@@ -2,18 +2,6 @@
|
||||
|
||||
* make sure to have at least Java 8 and Maven 3.6.3
|
||||
* clone playwright for java: http://github.com/microsoft/playwright-java
|
||||
* `./scripts/roll_driver.sh 1.47.0-beta-1726138322000`
|
||||
* roll the driver and update generated sources: `./scripts/roll_driver.sh next`
|
||||
* fix any errors
|
||||
* commit & send PR with the roll
|
||||
|
||||
## Finding driver version
|
||||
|
||||
For development versions of Playwright, you can find the latest version by looking at [publish_canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) workflow -> `publish canary NPM & Publish canary Docker` -> `build & publish driver` step -> `PACKAGE_VERSION`
|
||||
<img width="960" alt="image" src="https://github.com/microsoft/playwright-java/assets/9798949/4f33a7f1-b39a-4179-8ae7-fb1d84094c75">
|
||||
|
||||
|
||||
# Updating Version
|
||||
|
||||
```bash
|
||||
./scripts/set_maven_version.sh 1.15.0
|
||||
```
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<playwright.version>1.57.0</playwright.version>
|
||||
<playwright.version>1.60.0</playwright.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -23,24 +23,23 @@ import java.nio.file.Path;
|
||||
* This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
|
||||
* 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 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> Each Playwright browser context has an associated {@code APIRequestContext}, accessible via {@link
|
||||
* com.microsoft.playwright.BrowserContext#request BrowserContext.request()} or {@link
|
||||
* com.microsoft.playwright.Page#request Page.request()} (these return the
|
||||
*
|
||||
* <p> **same instance** — {@code page.request} is a shortcut for {@code page.context().request}). You can also create a
|
||||
* standalone, isolated instance with {@link com.microsoft.playwright.APIRequest#newContext APIRequest.newContext()}.
|
||||
*
|
||||
* <p> <strong>Cookie management</strong>
|
||||
*
|
||||
* <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> The {@code APIRequestContext} returned by {@link com.microsoft.playwright.BrowserContext#request
|
||||
* BrowserContext.request()} and
|
||||
*
|
||||
* <p> If you want API requests to not interfere with the browser cookies you should create a new {@code APIRequestContext} by
|
||||
* calling {@link com.microsoft.playwright.APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext}
|
||||
* object will have its own isolated cookie storage.
|
||||
* <p> {@link com.microsoft.playwright.Page#request Page.request()} uses the same cookie jar as its {@code BrowserContext}:
|
||||
*
|
||||
* <p> If you want API requests that do **not** share cookies with the browser, create an isolated context via {@link
|
||||
* com.microsoft.playwright.APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext} object will have
|
||||
* its own isolated cookie storage.
|
||||
*/
|
||||
public interface APIRequestContext {
|
||||
class DisposeOptions {
|
||||
@@ -484,5 +483,11 @@ public interface APIRequestContext {
|
||||
* @since v1.16
|
||||
*/
|
||||
String storageState(StorageStateOptions options);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
Tracing tracing();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,15 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface Browser extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* Emitted when a new browser context is created.
|
||||
*/
|
||||
void onContext(Consumer<BrowserContext> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onContext onContext(handler)}.
|
||||
*/
|
||||
void offContext(Consumer<BrowserContext> handler);
|
||||
|
||||
/**
|
||||
* Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
|
||||
* <ul>
|
||||
@@ -1222,6 +1231,44 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class BindOptions {
|
||||
/**
|
||||
* Host to bind the web socket server to. When specified, a web socket server is created instead of a named pipe.
|
||||
*/
|
||||
public String host;
|
||||
/**
|
||||
* Port to bind the web socket server to. When specified, a web socket server is created instead of a named pipe. Use
|
||||
* {@code 0} to let the OS pick an available port.
|
||||
*/
|
||||
public Integer port;
|
||||
/**
|
||||
* Working directory associated with this browser server.
|
||||
*/
|
||||
public String workspaceDir;
|
||||
|
||||
/**
|
||||
* Host to bind the web socket server to. When specified, a web socket server is created instead of a named pipe.
|
||||
*/
|
||||
public BindOptions setHost(String host) {
|
||||
this.host = host;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Port to bind the web socket server to. When specified, a web socket server is created instead of a named pipe. Use
|
||||
* {@code 0} to let the OS pick an available port.
|
||||
*/
|
||||
public BindOptions setPort(int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Working directory associated with this browser server.
|
||||
*/
|
||||
public BindOptions setWorkspaceDir(String workspaceDir) {
|
||||
this.workspaceDir = workspaceDir;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class StartTracingOptions {
|
||||
/**
|
||||
* specify custom categories to use instead of default.
|
||||
@@ -1404,6 +1451,22 @@ public interface Browser extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
Page newPage(NewPageOptions options);
|
||||
/**
|
||||
* Binds the browser to a named pipe or web socket, making it available for other clients to connect to.
|
||||
*
|
||||
* @param title Title of the browser server, used for identification.
|
||||
* @since v1.59
|
||||
*/
|
||||
default BindResult bind(String title) {
|
||||
return bind(title, null);
|
||||
}
|
||||
/**
|
||||
* Binds the browser to a named pipe or web socket, making it available for other clients to connect to.
|
||||
*
|
||||
* @param title Title of the browser server, used for identification.
|
||||
* @since v1.59
|
||||
*/
|
||||
BindResult bind(String title, BindOptions options);
|
||||
/**
|
||||
* <strong>NOTE:</strong> This API controls <a href="https://www.chromium.org/developers/how-tos/trace-event-profiling-tool">Chromium Tracing</a>
|
||||
* which is a low-level chromium-specific debugging tool. API to control <a
|
||||
@@ -1484,6 +1547,12 @@ public interface Browser extends AutoCloseable {
|
||||
* @since v1.11
|
||||
*/
|
||||
byte[] stopTracing();
|
||||
/**
|
||||
* Unbinds the browser server previously bound with {@link com.microsoft.playwright.Browser#bind Browser.bind()}.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void unbind();
|
||||
/**
|
||||
* Returns the browser version.
|
||||
*
|
||||
|
||||
@@ -114,6 +114,48 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offDialog(Consumer<Dialog> handler);
|
||||
|
||||
/**
|
||||
* Emitted when attachment download started in any page belonging to this context. User can access basic file operations on
|
||||
* downloaded content via the passed {@code Download} instance. See also {@link com.microsoft.playwright.Page#onDownload
|
||||
* Page.onDownload()} to receive events about a specific page.
|
||||
*/
|
||||
void onDownload(Consumer<Download> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onDownload onDownload(handler)}.
|
||||
*/
|
||||
void offDownload(Consumer<Download> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a frame is attached in any page belonging to this context. See also {@link
|
||||
* com.microsoft.playwright.Page#onFrameAttached Page.onFrameAttached()} to receive events about a specific page.
|
||||
*/
|
||||
void onFrameAttached(Consumer<Frame> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onFrameAttached onFrameAttached(handler)}.
|
||||
*/
|
||||
void offFrameAttached(Consumer<Frame> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a frame is detached in any page belonging to this context. See also {@link
|
||||
* com.microsoft.playwright.Page#onFrameDetached Page.onFrameDetached()} to receive events about a specific page.
|
||||
*/
|
||||
void onFrameDetached(Consumer<Frame> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onFrameDetached onFrameDetached(handler)}.
|
||||
*/
|
||||
void offFrameDetached(Consumer<Frame> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a frame is navigated to a new url in any page belonging to this context. See also {@link
|
||||
* com.microsoft.playwright.Page#onFrameNavigated Page.onFrameNavigated()} to receive events about navigations in a
|
||||
* specific page.
|
||||
*/
|
||||
void onFrameNavigated(Consumer<Frame> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onFrameNavigated onFrameNavigated(handler)}.
|
||||
*/
|
||||
void offFrameNavigated(Consumer<Frame> handler);
|
||||
|
||||
/**
|
||||
* The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
|
||||
* also fire for popup pages. See also {@link com.microsoft.playwright.Page#onPopup Page.onPopup()} to receive events about
|
||||
@@ -141,6 +183,27 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offPage(Consumer<Page> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a page in this context is closed. See also {@link com.microsoft.playwright.Page#onClose Page.onClose()} to
|
||||
* receive events about a specific page.
|
||||
*/
|
||||
void onPageClose(Consumer<Page> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onPageClose onPageClose(handler)}.
|
||||
*/
|
||||
void offPageClose(Consumer<Page> handler);
|
||||
|
||||
/**
|
||||
* Emitted when the JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/Events/load">{@code load}</a> event is
|
||||
* dispatched in any page belonging to this context. See also {@link com.microsoft.playwright.Page#onLoad Page.onLoad()} to
|
||||
* receive events about a specific page.
|
||||
*/
|
||||
void onPageLoad(Consumer<Page> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onPageLoad onPageLoad(handler)}.
|
||||
*/
|
||||
void offPageLoad(Consumer<Page> handler);
|
||||
|
||||
/**
|
||||
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular page,
|
||||
* use {@link com.microsoft.playwright.Page#onPageError Page.onPageError()} instead.
|
||||
@@ -271,20 +334,6 @@ public interface BrowserContext extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* @deprecated This option will be removed in the future.
|
||||
*/
|
||||
public Boolean handle;
|
||||
|
||||
/**
|
||||
* @deprecated This option will be removed in the future.
|
||||
*/
|
||||
public ExposeBindingOptions setHandle(boolean handle) {
|
||||
this.handle = handle;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class GrantPermissionsOptions {
|
||||
/**
|
||||
* The [origin] to grant permissions to, e.g. "https://example.com".
|
||||
@@ -514,6 +563,12 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.45
|
||||
*/
|
||||
Clock clock();
|
||||
/**
|
||||
* Debugger allows to pause and resume the execution.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
Debugger debugger();
|
||||
/**
|
||||
* 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()}.
|
||||
@@ -552,7 +607,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void addInitScript(String script);
|
||||
AutoCloseable addInitScript(String script);
|
||||
/**
|
||||
* Adds a script which would be evaluated in one of the following scenarios:
|
||||
* <ul>
|
||||
@@ -579,7 +634,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void addInitScript(Path script);
|
||||
AutoCloseable addInitScript(Path script);
|
||||
/**
|
||||
* @deprecated Background pages have been removed from Chromium together with Manifest V2 extensions.
|
||||
*
|
||||
@@ -730,54 +785,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void exposeBinding(String name, BindingCallback callback) {
|
||||
exposeBinding(name, callback, null);
|
||||
}
|
||||
/**
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in every page in the context.
|
||||
* When called, the function executes {@code callback} and returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a> which
|
||||
* resolves to the return value of {@code callback}. If the {@code callback} returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, it will be
|
||||
* awaited.
|
||||
*
|
||||
* <p> The first argument of the {@code callback} function contains information about the caller: {@code { browserContext:
|
||||
* BrowserContext, page: Page, frame: Frame }}.
|
||||
*
|
||||
* <p> See {@link com.microsoft.playwright.Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of exposing page URL to all frames in all pages in the context:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
*
|
||||
* public class Example {
|
||||
* public static void main(String[] args) {
|
||||
* try (Playwright playwright = Playwright.create()) {
|
||||
* BrowserType webkit = playwright.webkit();
|
||||
* Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
|
||||
* BrowserContext context = browser.newContext();
|
||||
* context.exposeBinding("pageURL", (source, args) -> source.page().url());
|
||||
* Page page = context.newPage();
|
||||
* page.setContent("<script>\n" +
|
||||
* " async function onClick() {\n" +
|
||||
* " document.querySelector('div').textContent = await window.pageURL();\n" +
|
||||
* " }\n" +
|
||||
* "</script>\n" +
|
||||
* "<button onclick=\"onClick()\">Click me</button>\n" +
|
||||
* "<div></div>");
|
||||
* page.getByRole(AriaRole.BUTTON).click();
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }</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
|
||||
*/
|
||||
void exposeBinding(String name, BindingCallback callback, ExposeBindingOptions options);
|
||||
AutoCloseable exposeBinding(String name, BindingCallback callback);
|
||||
/**
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in every page in the context.
|
||||
* When called, the function executes {@code callback} and returns a <a
|
||||
@@ -836,7 +844,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void exposeFunction(String name, FunctionCallback callback);
|
||||
AutoCloseable exposeFunction(String name, FunctionCallback callback);
|
||||
/**
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
||||
* specified.
|
||||
@@ -865,6 +873,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <li> {@code "notifications"}</li>
|
||||
* <li> {@code "payment-handler"}</li>
|
||||
* <li> {@code "storage-access"}</li>
|
||||
* <li> {@code "screen-wake-lock"}</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -899,10 +908,17 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* <li> {@code "notifications"}</li>
|
||||
* <li> {@code "payment-handler"}</li>
|
||||
* <li> {@code "storage-access"}</li>
|
||||
* <li> {@code "screen-wake-lock"}</li>
|
||||
* </ul>
|
||||
* @since v1.8
|
||||
*/
|
||||
void grantPermissions(List<String> permissions, GrantPermissionsOptions options);
|
||||
/**
|
||||
* Indicates that the browser context is in the process of closing or has already been closed.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
boolean isClosed();
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
@@ -994,8 +1010,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void route(String url, Consumer<Route> handler) {
|
||||
route(url, handler, null);
|
||||
default AutoCloseable route(String url, Consumer<Route> handler) {
|
||||
return route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
@@ -1050,7 +1066,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
void route(String url, Consumer<Route> handler, RouteOptions options);
|
||||
AutoCloseable route(String url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* 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.
|
||||
@@ -1104,8 +1120,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void route(Pattern url, Consumer<Route> handler) {
|
||||
route(url, handler, null);
|
||||
default AutoCloseable route(Pattern url, Consumer<Route> handler) {
|
||||
return route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
@@ -1160,7 +1176,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
void route(Pattern url, Consumer<Route> handler, RouteOptions options);
|
||||
AutoCloseable route(Pattern url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* 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.
|
||||
@@ -1214,8 +1230,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void route(Predicate<String> url, Consumer<Route> handler) {
|
||||
route(url, handler, null);
|
||||
default AutoCloseable route(Predicate<String> url, Consumer<Route> handler) {
|
||||
return route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
@@ -1270,7 +1286,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
AutoCloseable route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
@@ -1459,6 +1475,21 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
String storageState(StorageStateOptions options);
|
||||
/**
|
||||
* Clears the existing cookies, local storage and IndexedDB entries for all origins and sets the new storage state.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* // Load storage state from a file and apply it to the context.
|
||||
* context.setStorageState(Paths.get("state.json"));
|
||||
* }</pre>
|
||||
*
|
||||
* @param storageState Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link com.microsoft.playwright.BrowserContext#storageState BrowserContext.storageState()}. Path to the
|
||||
* file with saved storage state.
|
||||
* @since v1.59
|
||||
*/
|
||||
void setStorageState(Path storageState);
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -1476,7 +1507,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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
|
||||
* @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
|
||||
*/
|
||||
@@ -1487,7 +1518,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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
|
||||
* @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()}.
|
||||
@@ -1498,7 +1529,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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
|
||||
* @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
|
||||
*/
|
||||
@@ -1509,7 +1540,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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
|
||||
* @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()}.
|
||||
@@ -1520,7 +1551,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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
|
||||
* @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
|
||||
*/
|
||||
@@ -1531,7 +1562,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* 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
|
||||
* @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()}.
|
||||
|
||||
@@ -128,6 +128,20 @@ public interface BrowserType {
|
||||
* Additional HTTP headers to be sent with connect request. Optional.
|
||||
*/
|
||||
public Map<String, String> headers;
|
||||
/**
|
||||
* Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely upon
|
||||
* the file system being the same between Playwright and the Browser.
|
||||
*/
|
||||
public Boolean isLocal;
|
||||
/**
|
||||
* When true, Playwright will not apply its default overrides to the existing default browser context. Specifically, {@code
|
||||
* acceptDownloads} is left at the browser's setting, focus emulation is not enabled, and media emulation options (such as
|
||||
* {@code colorScheme}, {@code reducedMotion}, {@code forcedColors}, and {@code contrast}) are not applied. Useful when
|
||||
* attaching to a user's daily-driver browser where these overrides would interfere with existing browser state. New
|
||||
* contexts created via {@link com.microsoft.playwright.Browser#newContext Browser.newContext()} are not affected. Defaults
|
||||
* to {@code false}.
|
||||
*/
|
||||
public Boolean noDefaults;
|
||||
/**
|
||||
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
|
||||
* Defaults to 0.
|
||||
@@ -146,6 +160,26 @@ public interface BrowserType {
|
||||
this.headers = headers;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely upon
|
||||
* the file system being the same between Playwright and the Browser.
|
||||
*/
|
||||
public ConnectOverCDPOptions setIsLocal(boolean isLocal) {
|
||||
this.isLocal = isLocal;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When true, Playwright will not apply its default overrides to the existing default browser context. Specifically, {@code
|
||||
* acceptDownloads} is left at the browser's setting, focus emulation is not enabled, and media emulation options (such as
|
||||
* {@code colorScheme}, {@code reducedMotion}, {@code forcedColors}, and {@code contrast}) are not applied. Useful when
|
||||
* attaching to a user's daily-driver browser where these overrides would interfere with existing browser state. New
|
||||
* contexts created via {@link com.microsoft.playwright.Browser#newContext Browser.newContext()} are not affected. Defaults
|
||||
* to {@code false}.
|
||||
*/
|
||||
public ConnectOverCDPOptions setNoDefaults(boolean noDefaults) {
|
||||
this.noDefaults = noDefaults;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
|
||||
* Defaults to 0.
|
||||
@@ -171,6 +205,12 @@ public interface BrowserType {
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
* If specified, artifacts (traces, videos, downloads, HAR files, etc.) are saved into this directory. The directory is not
|
||||
* cleaned up when the browser closes. If not specified, a temporary directory is used and cleaned up when the browser
|
||||
* closes.
|
||||
*/
|
||||
public Path artifactsDir;
|
||||
/**
|
||||
* Browser distribution channel.
|
||||
*
|
||||
@@ -186,10 +226,6 @@ public interface BrowserType {
|
||||
* Enable Chromium sandboxing. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean chromiumSandbox;
|
||||
/**
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
@@ -229,8 +265,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
@@ -271,6 +306,15 @@ public interface BrowserType {
|
||||
this.args = args;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, artifacts (traces, videos, downloads, HAR files, etc.) are saved into this directory. The directory is not
|
||||
* cleaned up when the browser closes. If not specified, a temporary directory is used and cleaned up when the browser
|
||||
* closes.
|
||||
*/
|
||||
public LaunchOptions setArtifactsDir(Path artifactsDir) {
|
||||
this.artifactsDir = artifactsDir;
|
||||
return this;
|
||||
}
|
||||
@Deprecated
|
||||
/**
|
||||
* Browser distribution channel.
|
||||
@@ -307,13 +351,6 @@ public interface BrowserType {
|
||||
this.chromiumSandbox = chromiumSandbox;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public LaunchOptions setDevtools(boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
@@ -374,8 +411,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true}.
|
||||
*/
|
||||
public LaunchOptions setHeadless(boolean headless) {
|
||||
this.headless = headless;
|
||||
@@ -445,6 +481,12 @@ public interface BrowserType {
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
* If specified, artifacts (traces, videos, downloads, HAR files, etc.) are saved into this directory. The directory is not
|
||||
* cleaned up when the browser closes. If not specified, a temporary directory is used and cleaned up when the browser
|
||||
* closes.
|
||||
*/
|
||||
public Path artifactsDir;
|
||||
/**
|
||||
* 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
|
||||
@@ -518,10 +560,6 @@ public interface BrowserType {
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
@@ -577,8 +615,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true}.
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
@@ -744,6 +781,15 @@ public interface BrowserType {
|
||||
this.args = args;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, artifacts (traces, videos, downloads, HAR files, etc.) are saved into this directory. The directory is not
|
||||
* cleaned up when the browser closes. If not specified, a temporary directory is used and cleaned up when the browser
|
||||
* closes.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setArtifactsDir(Path artifactsDir) {
|
||||
this.artifactsDir = artifactsDir;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
@@ -856,13 +902,6 @@ public interface BrowserType {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @deprecated Use <a href="https://playwright.dev/java/docs/debug">debugging tools</a> instead.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setDevtools(boolean devtools) {
|
||||
this.devtools = devtools;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
@@ -954,8 +993,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
* href="https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/">Firefox</a>. Defaults to {@code true}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHeadless(boolean headless) {
|
||||
this.headless = headless;
|
||||
@@ -1237,11 +1275,11 @@ public interface BrowserType {
|
||||
* <p> <strong>NOTE:</strong> The major and minor version of the Playwright instance that connects needs to match the version of Playwright that
|
||||
* launches the browser (1.2.3 → is compatible with 1.2.x).
|
||||
*
|
||||
* @param wsEndpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via {@code BrowserServer.wsEndpoint}.
|
||||
* @param endpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via {@code BrowserServer.wsEndpoint}.
|
||||
* @since v1.8
|
||||
*/
|
||||
default Browser connect(String wsEndpoint) {
|
||||
return connect(wsEndpoint, null);
|
||||
default Browser connect(String endpoint) {
|
||||
return connect(endpoint, null);
|
||||
}
|
||||
/**
|
||||
* This method attaches Playwright to an existing browser instance created via {@code BrowserType.launchServer} in Node.js.
|
||||
@@ -1249,10 +1287,10 @@ public interface BrowserType {
|
||||
* <p> <strong>NOTE:</strong> The major and minor version of the Playwright instance that connects needs to match the version of Playwright that
|
||||
* launches the browser (1.2.3 → is compatible with 1.2.x).
|
||||
*
|
||||
* @param wsEndpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via {@code BrowserServer.wsEndpoint}.
|
||||
* @param endpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via {@code BrowserServer.wsEndpoint}.
|
||||
* @since v1.8
|
||||
*/
|
||||
Browser connect(String wsEndpoint, ConnectOptions options);
|
||||
Browser connect(String endpoint, ConnectOptions options);
|
||||
/**
|
||||
* This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
|
||||
*
|
||||
|
||||
@@ -48,6 +48,16 @@ import com.google.gson.JsonObject;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface CDPSession {
|
||||
|
||||
/**
|
||||
* Emitted when the session is closed, either because the target was closed or {@code session.detach()} was called.
|
||||
*/
|
||||
void onClose(Consumer<CDPSession> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onClose onClose(handler)}.
|
||||
*/
|
||||
void offClose(Consumer<CDPSession> handler);
|
||||
|
||||
/**
|
||||
* Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
||||
* send messages.
|
||||
|
||||
@@ -69,6 +69,12 @@ public interface ConsoleMessage {
|
||||
* @since v1.8
|
||||
*/
|
||||
String text();
|
||||
/**
|
||||
* The timestamp of the console message in milliseconds since the Unix epoch.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
double timestamp();
|
||||
/**
|
||||
* One of the following values: {@code "log"}, {@code "debug"}, {@code "info"}, {@code "error"}, {@code "warning"}, {@code
|
||||
* "dir"}, {@code "dirxml"}, {@code "table"}, {@code "trace"}, {@code "clear"}, {@code "startGroup"}, {@code
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* API for controlling the Playwright debugger. The debugger allows pausing script execution and inspecting the page.
|
||||
* Obtain the debugger instance via {@link com.microsoft.playwright.BrowserContext#debugger BrowserContext.debugger()}.
|
||||
*/
|
||||
public interface Debugger {
|
||||
|
||||
/**
|
||||
* Emitted when the debugger pauses or resumes.
|
||||
*/
|
||||
void onPausedStateChanged(Runnable handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onPausedStateChanged onPausedStateChanged(handler)}.
|
||||
*/
|
||||
void offPausedStateChanged(Runnable handler);
|
||||
|
||||
/**
|
||||
* Returns details about the currently paused call. Returns {@code null} if the debugger is not paused.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
DebuggerPausedDetails pausedDetails();
|
||||
/**
|
||||
* Configures the debugger to pause before the next action is executed.
|
||||
*
|
||||
* <p> Throws if the debugger is already paused. Use {@link com.microsoft.playwright.Debugger#next Debugger.next()} or {@link
|
||||
* com.microsoft.playwright.Debugger#runTo Debugger.runTo()} to step while paused.
|
||||
*
|
||||
* <p> Note that {@link com.microsoft.playwright.Page#pause Page.pause()} is equivalent to a "debugger" statement — it pauses
|
||||
* execution at the call site immediately. On the contrary, {@link com.microsoft.playwright.Debugger#requestPause
|
||||
* Debugger.requestPause()} is equivalent to "pause on next statement" — it configures the debugger to pause before the
|
||||
* next action is executed.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void requestPause();
|
||||
/**
|
||||
* Resumes script execution. Throws if the debugger is not paused.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void resume();
|
||||
/**
|
||||
* Resumes script execution and pauses again before the next action. Throws if the debugger is not paused.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void next();
|
||||
/**
|
||||
* Resumes script execution and pauses when an action originates from the given source location. Throws if the debugger is
|
||||
* not paused.
|
||||
*
|
||||
* @param location The source location to pause at.
|
||||
* @since v1.59
|
||||
*/
|
||||
void runTo(Location location);
|
||||
}
|
||||
|
||||
@@ -867,6 +867,13 @@ public interface Frame {
|
||||
* <p> Learn more about <a href="https://www.w3.org/TR/wai-aria-1.2/#aria-checked">{@code aria-checked}</a>.
|
||||
*/
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public Object description;
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -875,8 +882,8 @@ public interface Frame {
|
||||
*/
|
||||
public Boolean disabled;
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public Boolean exact;
|
||||
/**
|
||||
@@ -928,6 +935,26 @@ public interface Frame {
|
||||
this.checked = checked;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(Pattern description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -939,8 +966,8 @@ public interface Frame {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public GetByRoleOptions setExact(boolean exact) {
|
||||
this.exact = exact;
|
||||
@@ -2272,7 +2299,7 @@ public interface Frame {
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -2302,7 +2329,7 @@ public interface Frame {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -2311,7 +2338,7 @@ public interface Frame {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -2320,7 +2347,7 @@ public interface Frame {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -3380,7 +3407,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -3423,7 +3450,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -3462,7 +3489,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -3484,7 +3511,7 @@ public interface Frame {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -5139,7 +5166,7 @@ public interface Frame {
|
||||
* frame.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -5156,7 +5183,7 @@ public interface Frame {
|
||||
* frame.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -5171,7 +5198,7 @@ public interface Frame {
|
||||
* frame.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -5188,7 +5215,7 @@ public interface Frame {
|
||||
* frame.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -5203,7 +5230,7 @@ public interface Frame {
|
||||
* frame.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -5220,7 +5247,7 @@ public interface Frame {
|
||||
* frame.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
|
||||
@@ -107,6 +107,13 @@ public interface FrameLocator {
|
||||
* <p> Learn more about <a href="https://www.w3.org/TR/wai-aria-1.2/#aria-checked">{@code aria-checked}</a>.
|
||||
*/
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public Object description;
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -115,8 +122,8 @@ public interface FrameLocator {
|
||||
*/
|
||||
public Boolean disabled;
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public Boolean exact;
|
||||
/**
|
||||
@@ -168,6 +175,26 @@ public interface FrameLocator {
|
||||
this.checked = checked;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(Pattern description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -179,8 +206,8 @@ public interface FrameLocator {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public GetByRoleOptions setExact(boolean exact) {
|
||||
this.exact = exact;
|
||||
@@ -602,7 +629,7 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -645,7 +672,7 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -684,7 +711,7 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -706,7 +733,7 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
|
||||
@@ -30,6 +30,22 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface Locator {
|
||||
class AriaSnapshotOptions {
|
||||
/**
|
||||
* When {@code true}, appends each element's bounding box as {@code [box=x,y,width,height]} to the snapshot. Coordinates
|
||||
* are relative to the viewport, in CSS pixels, as returned by <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect">{@code
|
||||
* Element.getBoundingClientRect()}</a>. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean boxes;
|
||||
/**
|
||||
* When specified, limits the depth of the snapshot.
|
||||
*/
|
||||
public Integer depth;
|
||||
/**
|
||||
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption. Defaults to {@code "default"}. See details
|
||||
* for more information.
|
||||
*/
|
||||
public AriaSnapshotMode mode;
|
||||
/**
|
||||
* 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 com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
@@ -38,6 +54,31 @@ public interface Locator {
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* When {@code true}, appends each element's bounding box as {@code [box=x,y,width,height]} to the snapshot. Coordinates
|
||||
* are relative to the viewport, in CSS pixels, as returned by <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect">{@code
|
||||
* Element.getBoundingClientRect()}</a>. Defaults to {@code false}.
|
||||
*/
|
||||
public AriaSnapshotOptions setBoxes(boolean boxes) {
|
||||
this.boxes = boxes;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When specified, limits the depth of the snapshot.
|
||||
*/
|
||||
public AriaSnapshotOptions setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption. Defaults to {@code "default"}. See details
|
||||
* for more information.
|
||||
*/
|
||||
public AriaSnapshotOptions setMode(AriaSnapshotMode mode) {
|
||||
this.mode = mode;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
@@ -621,6 +662,46 @@ public interface Locator {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class DropOptions {
|
||||
/**
|
||||
* A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
|
||||
* element.
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
|
||||
* element.
|
||||
*/
|
||||
public DropOptions setPosition(double x, double y) {
|
||||
return setPosition(new Position(x, y));
|
||||
}
|
||||
/**
|
||||
* A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
|
||||
* element.
|
||||
*/
|
||||
public DropOptions setPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public DropOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ElementHandleOptions {
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
@@ -919,6 +1000,13 @@ public interface Locator {
|
||||
* <p> Learn more about <a href="https://www.w3.org/TR/wai-aria-1.2/#aria-checked">{@code aria-checked}</a>.
|
||||
*/
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public Object description;
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -927,8 +1015,8 @@ public interface Locator {
|
||||
*/
|
||||
public Boolean disabled;
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public Boolean exact;
|
||||
/**
|
||||
@@ -980,6 +1068,26 @@ public interface Locator {
|
||||
this.checked = checked;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(Pattern description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -991,8 +1099,8 @@ public interface Locator {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public GetByRoleOptions setExact(boolean exact) {
|
||||
this.exact = exact;
|
||||
@@ -1098,6 +1206,20 @@ public interface Locator {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HighlightOptions {
|
||||
/**
|
||||
* Additional inline CSS applied to the highlight overlay, e.g. {@code "outline: 2px dashed red"}.
|
||||
*/
|
||||
public String style;
|
||||
|
||||
/**
|
||||
* Additional inline CSS applied to the highlight overlay, e.g. {@code "outline: 2px dashed red"}.
|
||||
*/
|
||||
public HighlightOptions setStyle(String style) {
|
||||
this.style = style;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HoverOptions {
|
||||
/**
|
||||
* Whether to bypass the <a href="https://playwright.dev/java/docs/actionability">actionability</a> checks. Defaults to
|
||||
@@ -2237,7 +2359,7 @@ public interface Locator {
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* String[] texts = page.getByRole(AriaRole.LINK).allInnerTexts();
|
||||
* List<String> texts = page.getByRole(AriaRole.LINK).allInnerTexts();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.14
|
||||
@@ -2252,7 +2374,7 @@ public interface Locator {
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* String[] texts = page.getByRole(AriaRole.LINK).allTextContents();
|
||||
* List<String> texts = page.getByRole(AriaRole.LINK).allTextContents();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.14
|
||||
@@ -2298,6 +2420,12 @@ public interface Locator {
|
||||
*
|
||||
* <p> Below is the HTML markup and the respective ARIA snapshot:
|
||||
*
|
||||
* <p> An AI-optimized snapshot, controlled by {@code mode}, is different from a default snapshot:
|
||||
* <ol>
|
||||
* <li> Includes element references {@code [ref=e2]}. 2. Does not wait for an element matching the locator, and throws when no
|
||||
* elements match. 3. Includes snapshots of {@code <iframe>}s inside the target.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @since v1.49
|
||||
*/
|
||||
default String ariaSnapshot() {
|
||||
@@ -2329,6 +2457,12 @@ public interface Locator {
|
||||
*
|
||||
* <p> Below is the HTML markup and the respective ARIA snapshot:
|
||||
*
|
||||
* <p> An AI-optimized snapshot, controlled by {@code mode}, is different from a default snapshot:
|
||||
* <ol>
|
||||
* <li> Includes element references {@code [ref=e2]}. 2. Does not wait for an element matching the locator, and throws when no
|
||||
* elements match. 3. Includes snapshots of {@code <iframe>}s inside the target.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @since v1.49
|
||||
*/
|
||||
String ariaSnapshot(AriaSnapshotOptions options);
|
||||
@@ -2661,8 +2795,7 @@ public interface Locator {
|
||||
Locator describe(String description);
|
||||
/**
|
||||
* Returns locator description previously set with {@link com.microsoft.playwright.Locator#describe Locator.describe()}.
|
||||
* Returns {@code null} if no custom description has been set. Prefer {@code Locator.toString()} for a human-readable
|
||||
* representation, as it uses the description when available.
|
||||
* Returns {@code null} if no custom description has been set.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
@@ -2865,6 +2998,54 @@ public interface Locator {
|
||||
* @since v1.18
|
||||
*/
|
||||
void dragTo(Locator target, DragToOptions options);
|
||||
/**
|
||||
* Simulate an external drag-and-drop of files or clipboard-like data onto this locator.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> Dispatches the native {@code dragenter}, {@code dragover}, and {@code drop} events at the center of the target element
|
||||
* with a synthetic [DataTransfer] carrying the provided files and/or data entries. Works cross-browser by constructing the
|
||||
* [DataTransfer] in the page context.
|
||||
*
|
||||
* <p> If the target element's {@code dragover} listener does not call {@code preventDefault()}, the target is considered to
|
||||
* have rejected the drop: Playwright dispatches {@code dragleave} and this method throws.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Drop a file buffer onto an upload area:
|
||||
*
|
||||
* <p> Drop plain text and a URL together:
|
||||
*
|
||||
* @param payload Data to drop onto the target. Provide {@code files} (file paths or in-memory buffers), {@code data} (a mime-type →
|
||||
* string map for clipboard-like content such as {@code text/plain}, {@code text/html}, {@code text/uri-list}), or both.
|
||||
* @since v1.60
|
||||
*/
|
||||
default void drop(DropPayload payload) {
|
||||
drop(payload, null);
|
||||
}
|
||||
/**
|
||||
* Simulate an external drag-and-drop of files or clipboard-like data onto this locator.
|
||||
*
|
||||
* <p> <strong>Details</strong>
|
||||
*
|
||||
* <p> Dispatches the native {@code dragenter}, {@code dragover}, and {@code drop} events at the center of the target element
|
||||
* with a synthetic [DataTransfer] carrying the provided files and/or data entries. Works cross-browser by constructing the
|
||||
* [DataTransfer] in the page context.
|
||||
*
|
||||
* <p> If the target element's {@code dragover} listener does not call {@code preventDefault()}, the target is considered to
|
||||
* have rejected the drop: Playwright dispatches {@code dragleave} and this method throws.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> Drop a file buffer onto an upload area:
|
||||
*
|
||||
* <p> Drop plain text and a URL together:
|
||||
*
|
||||
* @param payload Data to drop onto the target. Provide {@code files} (file paths or in-memory buffers), {@code data} (a mime-type →
|
||||
* string map for clipboard-like content such as {@code text/plain}, {@code text/html}, {@code text/uri-list}), or both.
|
||||
* @since v1.60
|
||||
*/
|
||||
void drop(DropPayload payload, DropOptions options);
|
||||
/**
|
||||
* Resolves given locator to the first matching DOM element. If there are no matching elements, waits for one. If multiple
|
||||
* elements match the locator, throws.
|
||||
@@ -3493,7 +3674,7 @@ public interface Locator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -3536,7 +3717,7 @@ public interface Locator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -3575,7 +3756,7 @@ public interface Locator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -3597,7 +3778,7 @@ public interface Locator {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -3844,13 +4025,28 @@ public interface Locator {
|
||||
* @since v1.27
|
||||
*/
|
||||
Locator getByTitle(Pattern text, GetByTitleOptions options);
|
||||
/**
|
||||
* Hides the element highlight previously added by {@link com.microsoft.playwright.Locator#highlight Locator.highlight()}.
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
void hideHighlight();
|
||||
/**
|
||||
* Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses {@link
|
||||
* com.microsoft.playwright.Locator#highlight Locator.highlight()}.
|
||||
*
|
||||
* @since v1.20
|
||||
*/
|
||||
void highlight();
|
||||
default AutoCloseable highlight() {
|
||||
return highlight(null);
|
||||
}
|
||||
/**
|
||||
* Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses {@link
|
||||
* com.microsoft.playwright.Locator#highlight Locator.highlight()}.
|
||||
*
|
||||
* @since v1.20
|
||||
*/
|
||||
AutoCloseable highlight(HighlightOptions options);
|
||||
/**
|
||||
* Hover over the matching element.
|
||||
*
|
||||
@@ -4246,6 +4442,14 @@ public interface Locator {
|
||||
* @since v1.14
|
||||
*/
|
||||
Locator locator(Locator selectorOrLocator, LocatorOptions options);
|
||||
/**
|
||||
* Returns a new locator that uses best practices for referencing the matched element, prioritizing test ids, aria roles,
|
||||
* and other user-facing attributes over CSS selectors. This is useful for converting implementation-detail selectors into
|
||||
* more resilient, human-readable locators.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
Locator normalize();
|
||||
/**
|
||||
* Returns locator to the n-th matching element. It's zero based, {@code nth(0)} selects the first element.
|
||||
*
|
||||
|
||||
@@ -1058,20 +1058,6 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* @deprecated This option will be removed in the future.
|
||||
*/
|
||||
public Boolean handle;
|
||||
|
||||
/**
|
||||
* @deprecated This option will be removed in the future.
|
||||
*/
|
||||
public ExposeBindingOptions setHandle(boolean handle) {
|
||||
this.handle = handle;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class FillOptions {
|
||||
/**
|
||||
* Whether to bypass the <a href="https://playwright.dev/java/docs/actionability">actionability</a> checks. Defaults to
|
||||
@@ -1250,6 +1236,13 @@ public interface Page extends AutoCloseable {
|
||||
* <p> Learn more about <a href="https://www.w3.org/TR/wai-aria-1.2/#aria-checked">{@code aria-checked}</a>.
|
||||
*/
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public Object description;
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -1258,8 +1251,8 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
public Boolean disabled;
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public Boolean exact;
|
||||
/**
|
||||
@@ -1311,6 +1304,26 @@ public interface Page extends AutoCloseable {
|
||||
this.checked = checked;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Option to match the <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>. By
|
||||
* default, matching is case-insensitive and searches for a substring, use {@code exact} to control this behavior.
|
||||
*
|
||||
* <p> Learn more about <a href="https://w3c.github.io/accname/#dfn-accessible-description">accessible description</a>.
|
||||
*/
|
||||
public GetByRoleOptions setDescription(Pattern description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An attribute that is usually set by {@code aria-disabled} or {@code disabled}.
|
||||
*
|
||||
@@ -1322,8 +1335,8 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether {@code name} is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when {@code name}
|
||||
* is a regular expression. Note that exact match still trims whitespace.
|
||||
* Whether {@code name} and {@code description} are matched exactly: case-sensitive and whole-string. Defaults to false.
|
||||
* Ignored when the value is a regular expression. Note that exact match still trims whitespace.
|
||||
*/
|
||||
public GetByRoleOptions setExact(boolean exact) {
|
||||
this.exact = exact;
|
||||
@@ -1987,6 +2000,20 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ConsoleMessagesOptions {
|
||||
/**
|
||||
* Controls which messages are returned:
|
||||
*/
|
||||
public ConsoleMessagesFilter filter;
|
||||
|
||||
/**
|
||||
* Controls which messages are returned:
|
||||
*/
|
||||
public ConsoleMessagesOptions setFilter(ConsoleMessagesFilter filter) {
|
||||
this.filter = filter;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class LocatorOptions {
|
||||
/**
|
||||
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
|
||||
@@ -2966,6 +2993,67 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class AriaSnapshotOptions {
|
||||
/**
|
||||
* When {@code true}, appends each element's bounding box as {@code [box=x,y,width,height]} to the snapshot. Coordinates
|
||||
* are relative to the viewport, in CSS pixels, as returned by <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect">{@code
|
||||
* Element.getBoundingClientRect()}</a>. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean boxes;
|
||||
/**
|
||||
* When specified, limits the depth of the snapshot.
|
||||
*/
|
||||
public Integer depth;
|
||||
/**
|
||||
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption: including element references like {@code
|
||||
* [ref=e2]} and snapshots of {@code <iframe>}s. Defaults to {@code "default"}.
|
||||
*/
|
||||
public AriaSnapshotMode mode;
|
||||
/**
|
||||
* 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 com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* When {@code true}, appends each element's bounding box as {@code [box=x,y,width,height]} to the snapshot. Coordinates
|
||||
* are relative to the viewport, in CSS pixels, as returned by <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect">{@code
|
||||
* Element.getBoundingClientRect()}</a>. Defaults to {@code false}.
|
||||
*/
|
||||
public AriaSnapshotOptions setBoxes(boolean boxes) {
|
||||
this.boxes = boxes;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When specified, limits the depth of the snapshot.
|
||||
*/
|
||||
public AriaSnapshotOptions setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption: including element references like {@code
|
||||
* [ref=e2]} and snapshots of {@code <iframe>}s. Defaults to {@code "default"}.
|
||||
*/
|
||||
public AriaSnapshotOptions setMode(AriaSnapshotMode mode) {
|
||||
this.mode = mode;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
|
||||
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
|
||||
* methods.
|
||||
*/
|
||||
public AriaSnapshotOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class TapOptions {
|
||||
/**
|
||||
* Whether to bypass the <a href="https://playwright.dev/java/docs/actionability">actionability</a> checks. Defaults to
|
||||
@@ -3428,7 +3516,7 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -3458,7 +3546,7 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -3467,7 +3555,7 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -3476,7 +3564,7 @@ public interface Page extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
*/
|
||||
@@ -3812,7 +3900,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void addInitScript(String script);
|
||||
AutoCloseable addInitScript(String script);
|
||||
/**
|
||||
* Adds a script which would be evaluated in one of the following scenarios:
|
||||
* <ul>
|
||||
@@ -3839,7 +3927,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param script Script to be evaluated in all pages in the browser context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void addInitScript(Path script);
|
||||
AutoCloseable addInitScript(Path script);
|
||||
/**
|
||||
* Adds a {@code <script>} tag into the page with the desired url or content. Returns the added tag when the script's
|
||||
* onload fires or when the script content was injected into frame.
|
||||
@@ -3880,6 +3968,13 @@ public interface Page extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
void bringToFront();
|
||||
/**
|
||||
* Cancels an ongoing {@link com.microsoft.playwright.Page#pickLocator Page.pickLocator()} call by deactivating pick
|
||||
* locator mode. If no pick locator mode is active, this method is a no-op.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void cancelPickLocator();
|
||||
/**
|
||||
* This method checks an element matching {@code selector} by performing the following steps:
|
||||
* <ol>
|
||||
@@ -4611,57 +4706,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void exposeBinding(String name, BindingCallback callback) {
|
||||
exposeBinding(name, callback, null);
|
||||
}
|
||||
/**
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in this page. When called,
|
||||
* the function executes {@code callback} and returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a> which
|
||||
* resolves to the return value of {@code callback}. If the {@code callback} returns a <a
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, it will be
|
||||
* awaited.
|
||||
*
|
||||
* <p> The first argument of the {@code callback} function contains information about the caller: {@code { browserContext:
|
||||
* BrowserContext, page: Page, frame: Frame }}.
|
||||
*
|
||||
* <p> See {@link com.microsoft.playwright.BrowserContext#exposeBinding BrowserContext.exposeBinding()} for the context-wide
|
||||
* version.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Functions installed via {@link com.microsoft.playwright.Page#exposeBinding Page.exposeBinding()} survive navigations.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> An example of exposing page URL to all frames in a page:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
*
|
||||
* public class Example {
|
||||
* public static void main(String[] args) {
|
||||
* try (Playwright playwright = Playwright.create()) {
|
||||
* BrowserType webkit = playwright.webkit();
|
||||
* Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
|
||||
* BrowserContext context = browser.newContext();
|
||||
* Page page = context.newPage();
|
||||
* page.exposeBinding("pageURL", (source, args) -> source.page().url());
|
||||
* page.setContent("<script>\n" +
|
||||
* " async function onClick() {\n" +
|
||||
* " document.querySelector('div').textContent = await window.pageURL();\n" +
|
||||
* " }\n" +
|
||||
* "</script>\n" +
|
||||
* "<button onclick=\"onClick()\">Click me</button>\n" +
|
||||
* "<div></div>");
|
||||
* page.click("button");
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }</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
|
||||
*/
|
||||
void exposeBinding(String name, BindingCallback callback, ExposeBindingOptions options);
|
||||
AutoCloseable exposeBinding(String name, BindingCallback callback);
|
||||
/**
|
||||
* The method adds a function called {@code name} on the {@code window} object of every frame in the page. When called, the
|
||||
* function executes {@code callback} and returns a <a
|
||||
@@ -4723,7 +4768,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param callback Callback function which will be called in Playwright's context.
|
||||
* @since v1.8
|
||||
*/
|
||||
void exposeFunction(String name, FunctionCallback callback);
|
||||
AutoCloseable exposeFunction(String name, FunctionCallback callback);
|
||||
/**
|
||||
* This method waits for an element matching {@code selector}, waits for <a
|
||||
* href="https://playwright.dev/java/docs/actionability">actionability</a> checks, focuses the element, fills it and
|
||||
@@ -5062,7 +5107,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -5105,7 +5150,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate each element by it's implicit role:
|
||||
* <p> You can locate each element by its implicit role:
|
||||
* <pre>{@code
|
||||
* assertThat(page
|
||||
* .getByRole(AriaRole.HEADING,
|
||||
@@ -5144,7 +5189,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -5166,7 +5211,7 @@ public interface Page extends AutoCloseable {
|
||||
*
|
||||
* <p> Consider the following DOM structure.
|
||||
*
|
||||
* <p> You can locate the element by it's test id:
|
||||
* <p> You can locate the element by its test id:
|
||||
* <pre>{@code
|
||||
* page.getByTestId("directions").click();
|
||||
* }</pre>
|
||||
@@ -5532,6 +5577,13 @@ public interface Page extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
Response navigate(String url, NavigateOptions options);
|
||||
/**
|
||||
* Hide all locator highlight overlays previously added by {@link com.microsoft.playwright.Locator#highlight
|
||||
* Locator.highlight()} on this page.
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
void hideHighlight();
|
||||
/**
|
||||
* This method hovers over an element matching {@code selector} by performing the following steps:
|
||||
* <ol>
|
||||
@@ -5742,13 +5794,36 @@ public interface Page extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
Keyboard keyboard();
|
||||
/**
|
||||
* Clears all stored console messages from this page. Subsequent calls to {@link
|
||||
* com.microsoft.playwright.Page#consoleMessages Page.consoleMessages()} will only return messages logged after the clear.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void clearConsoleMessages();
|
||||
/**
|
||||
* Clears all stored page errors from this page. Subsequent calls to {@link com.microsoft.playwright.Page#pageErrors
|
||||
* Page.pageErrors()} will only return errors thrown after the clear.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void clearPageErrors();
|
||||
/**
|
||||
* Returns up to (currently) 200 last console messages from this page. See {@link
|
||||
* com.microsoft.playwright.Page#onConsoleMessage Page.onConsoleMessage()} for more details.
|
||||
*
|
||||
* @since v1.56
|
||||
*/
|
||||
List<ConsoleMessage> consoleMessages();
|
||||
default List<ConsoleMessage> consoleMessages() {
|
||||
return consoleMessages(null);
|
||||
}
|
||||
/**
|
||||
* Returns up to (currently) 200 last console messages from this page. See {@link
|
||||
* com.microsoft.playwright.Page#onConsoleMessage Page.onConsoleMessage()} for more details.
|
||||
*
|
||||
* @since v1.56
|
||||
*/
|
||||
List<ConsoleMessage> consoleMessages(ConsoleMessagesOptions options);
|
||||
/**
|
||||
* Returns up to (currently) 200 last page errors from this page. See {@link com.microsoft.playwright.Page#onPageError
|
||||
* Page.onPageError()} for more details.
|
||||
@@ -5964,6 +6039,19 @@ public interface Page extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
byte[] pdf(PdfOptions options);
|
||||
/**
|
||||
* Enters pick locator mode where hovering over page elements highlights them and shows the corresponding locator. Once the
|
||||
* user clicks an element, the mode is deactivated and the {@code Locator} for the picked element is returned.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* Locator locator = page.pickLocator();
|
||||
* System.out.println(locator);
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
Locator pickLocator();
|
||||
/**
|
||||
* Focuses the element, and then uses {@link com.microsoft.playwright.Keyboard#down Keyboard.down()} and {@link
|
||||
* com.microsoft.playwright.Keyboard#up Keyboard.up()}.
|
||||
@@ -6352,6 +6440,8 @@ public interface Page extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> If a request matches multiple registered routes, the most recently registered route takes precedence.
|
||||
*
|
||||
* <p> Page routes take precedence over browser context routes (set up with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}) when request matches both handlers.
|
||||
*
|
||||
@@ -6365,8 +6455,8 @@ public interface Page extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void route(String url, Consumer<Route> handler) {
|
||||
route(url, handler, null);
|
||||
default AutoCloseable route(String url, Consumer<Route> handler) {
|
||||
return route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by a page.
|
||||
@@ -6411,6 +6501,8 @@ public interface Page extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> If a request matches multiple registered routes, the most recently registered route takes precedence.
|
||||
*
|
||||
* <p> Page routes take precedence over browser context routes (set up with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}) when request matches both handlers.
|
||||
*
|
||||
@@ -6424,7 +6516,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
void route(String url, Consumer<Route> handler, RouteOptions options);
|
||||
AutoCloseable route(String url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by a page.
|
||||
*
|
||||
@@ -6468,6 +6560,8 @@ public interface Page extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> If a request matches multiple registered routes, the most recently registered route takes precedence.
|
||||
*
|
||||
* <p> Page routes take precedence over browser context routes (set up with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}) when request matches both handlers.
|
||||
*
|
||||
@@ -6481,8 +6575,8 @@ public interface Page extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void route(Pattern url, Consumer<Route> handler) {
|
||||
route(url, handler, null);
|
||||
default AutoCloseable route(Pattern url, Consumer<Route> handler) {
|
||||
return route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by a page.
|
||||
@@ -6527,6 +6621,8 @@ public interface Page extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> If a request matches multiple registered routes, the most recently registered route takes precedence.
|
||||
*
|
||||
* <p> Page routes take precedence over browser context routes (set up with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}) when request matches both handlers.
|
||||
*
|
||||
@@ -6540,7 +6636,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
void route(Pattern url, Consumer<Route> handler, RouteOptions options);
|
||||
AutoCloseable route(Pattern url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by a page.
|
||||
*
|
||||
@@ -6584,6 +6680,8 @@ public interface Page extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> If a request matches multiple registered routes, the most recently registered route takes precedence.
|
||||
*
|
||||
* <p> Page routes take precedence over browser context routes (set up with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}) when request matches both handlers.
|
||||
*
|
||||
@@ -6597,8 +6695,8 @@ public interface Page extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void route(Predicate<String> url, Consumer<Route> handler) {
|
||||
route(url, handler, null);
|
||||
default AutoCloseable route(Predicate<String> url, Consumer<Route> handler) {
|
||||
return route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by a page.
|
||||
@@ -6643,6 +6741,8 @@ public interface Page extends AutoCloseable {
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> If a request matches multiple registered routes, the most recently registered route takes precedence.
|
||||
*
|
||||
* <p> Page routes take precedence over browser context routes (set up with {@link
|
||||
* com.microsoft.playwright.BrowserContext#route BrowserContext.route()}) when request matches both handlers.
|
||||
*
|
||||
@@ -6656,7 +6756,7 @@ public interface Page extends AutoCloseable {
|
||||
* @param handler handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
AutoCloseable route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* If specified the network requests that are made in the page will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
@@ -6760,6 +6860,14 @@ public interface Page extends AutoCloseable {
|
||||
* @since v1.48
|
||||
*/
|
||||
void routeWebSocket(Predicate<String> url, Consumer<WebSocketRoute> handler);
|
||||
/**
|
||||
* {@code Screencast} object associated with this page.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
Screencast screencast();
|
||||
/**
|
||||
* Returns the buffer with the captured screenshot.
|
||||
*
|
||||
@@ -7414,6 +7522,22 @@ public interface Page extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
void setViewportSize(int width, int height);
|
||||
/**
|
||||
* Captures the aria snapshot of the page. Read more about <a href="https://playwright.dev/java/docs/aria-snapshots">aria
|
||||
* snapshots</a>.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
default String ariaSnapshot() {
|
||||
return ariaSnapshot(null);
|
||||
}
|
||||
/**
|
||||
* Captures the aria snapshot of the page. Read more about <a href="https://playwright.dev/java/docs/aria-snapshots">aria
|
||||
* snapshots</a>.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
String ariaSnapshot(AriaSnapshotOptions options);
|
||||
/**
|
||||
* This method taps an element matching {@code selector} by performing the following steps:
|
||||
* <ol>
|
||||
@@ -7561,7 +7685,7 @@ public interface Page extends AutoCloseable {
|
||||
* Removes a route created with {@link com.microsoft.playwright.Page#route Page.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] to match while routing.
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while routing.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void unroute(String url) {
|
||||
@@ -7571,7 +7695,7 @@ public interface Page extends AutoCloseable {
|
||||
* Removes a route created with {@link com.microsoft.playwright.Page#route Page.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] to match while routing.
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while routing.
|
||||
* @param handler Optional handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -7580,7 +7704,7 @@ public interface Page extends AutoCloseable {
|
||||
* Removes a route created with {@link com.microsoft.playwright.Page#route Page.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] to match while routing.
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while routing.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void unroute(Pattern url) {
|
||||
@@ -7590,7 +7714,7 @@ public interface Page extends AutoCloseable {
|
||||
* Removes a route created with {@link com.microsoft.playwright.Page#route Page.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] to match while routing.
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while routing.
|
||||
* @param handler Optional handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -7599,7 +7723,7 @@ public interface Page extends AutoCloseable {
|
||||
* Removes a route created with {@link com.microsoft.playwright.Page#route Page.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] to match while routing.
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while routing.
|
||||
* @since v1.8
|
||||
*/
|
||||
default void unroute(Predicate<String> url) {
|
||||
@@ -7609,7 +7733,7 @@ public interface Page extends AutoCloseable {
|
||||
* Removes a route created with {@link com.microsoft.playwright.Page#route Page.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] to match while routing.
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while routing.
|
||||
* @param handler Optional handler function to route the request.
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -7621,7 +7745,8 @@ public interface Page extends AutoCloseable {
|
||||
*/
|
||||
String url();
|
||||
/**
|
||||
* Video object associated with this page.
|
||||
* Video object associated with this page. Can be used to access the video file when using the {@code recordVideo} context
|
||||
* option.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -8447,7 +8572,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -8464,7 +8589,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -8479,7 +8604,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -8496,7 +8621,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -8511,7 +8636,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
@@ -8528,7 +8653,7 @@ public interface Page extends AutoCloseable {
|
||||
* page.waitForURL("**\/target.html");
|
||||
* }</pre>
|
||||
*
|
||||
* @param url A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* @param url A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if the
|
||||
* parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to
|
||||
* the string.
|
||||
* @since v1.11
|
||||
|
||||
@@ -183,6 +183,16 @@ public interface Request {
|
||||
* @since v1.8
|
||||
*/
|
||||
Response response();
|
||||
/**
|
||||
* Returns the {@code Response} object if the response has already been received, {@code null} otherwise.
|
||||
*
|
||||
* <p> Unlike {@link com.microsoft.playwright.Request#response Request.response()}, this method does not wait for the response
|
||||
* to arrive. It returns immediately with the response object if the response has been received, or {@code null} if the
|
||||
* response has not been received yet.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
Response existingResponse();
|
||||
/**
|
||||
* Returns resource size information for given request.
|
||||
*
|
||||
|
||||
@@ -86,6 +86,12 @@ public interface Response {
|
||||
* @since v1.15
|
||||
*/
|
||||
List<String> headerValues(String name);
|
||||
/**
|
||||
* Returns the http version used by the response.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
String httpVersion();
|
||||
/**
|
||||
* Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
||||
*
|
||||
|
||||
@@ -370,9 +370,10 @@ public interface Route {
|
||||
* 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.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code Cookie} header cannot be overridden using this method. If a value is provided, it will be ignored, and the
|
||||
* cookie will be loaded from the browser's cookie store. To set custom cookies, use {@link
|
||||
* com.microsoft.playwright.BrowserContext#addCookies BrowserContext.addCookies()}.
|
||||
* <p> <strong>NOTE:</strong> Some request headers are **forbidden** and cannot be overridden (for example, {@code Cookie}, {@code Host}, {@code
|
||||
* Content-Length} and others, see <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header">this MDN page</a> for full list). If
|
||||
* an override is provided for a forbidden header, it will be ignored and the original request header will be used.To set custom cookies, use {@link com.microsoft.playwright.BrowserContext#addCookies BrowserContext.addCookies()}.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -402,9 +403,10 @@ public interface Route {
|
||||
* 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.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code Cookie} header cannot be overridden using this method. If a value is provided, it will be ignored, and the
|
||||
* cookie will be loaded from the browser's cookie store. To set custom cookies, use {@link
|
||||
* com.microsoft.playwright.BrowserContext#addCookies BrowserContext.addCookies()}.
|
||||
* <p> <strong>NOTE:</strong> Some request headers are **forbidden** and cannot be overridden (for example, {@code Cookie}, {@code Host}, {@code
|
||||
* Content-Length} and others, see <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header">this MDN page</a> for full list). If
|
||||
* an override is provided for a forbidden header, it will be ignored and the original request header will be used.To set custom cookies, use {@link com.microsoft.playwright.BrowserContext#addCookies BrowserContext.addCookies()}.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Interface for capturing screencast frames from a page.
|
||||
*/
|
||||
public interface Screencast {
|
||||
class StartOptions {
|
||||
/**
|
||||
* Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.
|
||||
*/
|
||||
public Consumer<ScreencastFrame> onFrame;
|
||||
/**
|
||||
* Path where the video should be saved when the screencast is stopped. When provided, video recording is started.
|
||||
*/
|
||||
public Path path;
|
||||
/**
|
||||
* The quality of the image, between 0-100.
|
||||
*/
|
||||
public Integer quality;
|
||||
|
||||
/**
|
||||
* Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.
|
||||
*/
|
||||
public StartOptions setOnFrame(Consumer<ScreencastFrame> onFrame) {
|
||||
this.onFrame = onFrame;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Path where the video should be saved when the screencast is stopped. When provided, video recording is started.
|
||||
*/
|
||||
public StartOptions setPath(Path path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* The quality of the image, between 0-100.
|
||||
*/
|
||||
public StartOptions setQuality(int quality) {
|
||||
this.quality = quality;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ShowOverlayOptions {
|
||||
/**
|
||||
* Duration in milliseconds after which the overlay is automatically removed. Overlay stays until dismissed if not
|
||||
* provided.
|
||||
*/
|
||||
public Double duration;
|
||||
|
||||
/**
|
||||
* Duration in milliseconds after which the overlay is automatically removed. Overlay stays until dismissed if not
|
||||
* provided.
|
||||
*/
|
||||
public ShowOverlayOptions setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ShowChapterOptions {
|
||||
/**
|
||||
* Optional description text displayed below the title.
|
||||
*/
|
||||
public String description;
|
||||
/**
|
||||
* Duration in milliseconds after which the overlay is automatically removed. Defaults to {@code 2000}.
|
||||
*/
|
||||
public Double duration;
|
||||
|
||||
/**
|
||||
* Optional description text displayed below the title.
|
||||
*/
|
||||
public ShowChapterOptions setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Duration in milliseconds after which the overlay is automatically removed. Defaults to {@code 2000}.
|
||||
*/
|
||||
public ShowChapterOptions setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ShowActionsOptions {
|
||||
/**
|
||||
* How long each annotation is displayed in milliseconds. Defaults to {@code 500}.
|
||||
*/
|
||||
public Double duration;
|
||||
/**
|
||||
* Font size of the action title in pixels. Defaults to {@code 24}.
|
||||
*/
|
||||
public Integer fontSize;
|
||||
/**
|
||||
* Position of the action title overlay. Defaults to {@code "top-right"}.
|
||||
*/
|
||||
public AnnotatePosition position;
|
||||
|
||||
/**
|
||||
* How long each annotation is displayed in milliseconds. Defaults to {@code 500}.
|
||||
*/
|
||||
public ShowActionsOptions setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Font size of the action title in pixels. Defaults to {@code 24}.
|
||||
*/
|
||||
public ShowActionsOptions setFontSize(int fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Position of the action title overlay. Defaults to {@code "top-right"}.
|
||||
*/
|
||||
public ShowActionsOptions setPosition(AnnotatePosition position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Starts the screencast. When {@code path} is provided, it saves video recording to the specified file. When {@code
|
||||
* onFrame} is provided, delivers JPEG-encoded frames to the callback. Both can be used together.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
default AutoCloseable start() {
|
||||
return start(null);
|
||||
}
|
||||
/**
|
||||
* Starts the screencast. When {@code path} is provided, it saves video recording to the specified file. When {@code
|
||||
* onFrame} is provided, delivers JPEG-encoded frames to the callback. Both can be used together.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
AutoCloseable start(StartOptions options);
|
||||
/**
|
||||
* Stops the screencast and video recording if active. If a video was being recorded, saves it to the path specified in
|
||||
* {@link com.microsoft.playwright.Screencast#start Screencast.start()}.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void stop();
|
||||
/**
|
||||
* Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a
|
||||
* disposable that removes the overlay when disposed.
|
||||
*
|
||||
* @param html HTML content for the overlay.
|
||||
* @since v1.59
|
||||
*/
|
||||
default AutoCloseable showOverlay(String html) {
|
||||
return showOverlay(html, null);
|
||||
}
|
||||
/**
|
||||
* Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a
|
||||
* disposable that removes the overlay when disposed.
|
||||
*
|
||||
* @param html HTML content for the overlay.
|
||||
* @since v1.59
|
||||
*/
|
||||
AutoCloseable showOverlay(String html, ShowOverlayOptions options);
|
||||
/**
|
||||
* Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for
|
||||
* narrating video recordings. The overlay is removed after the specified duration, or 2000ms.
|
||||
*
|
||||
* @param title Title text displayed prominently in the overlay.
|
||||
* @since v1.59
|
||||
*/
|
||||
default void showChapter(String title) {
|
||||
showChapter(title, null);
|
||||
}
|
||||
/**
|
||||
* Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for
|
||||
* narrating video recordings. The overlay is removed after the specified duration, or 2000ms.
|
||||
*
|
||||
* @param title Title text displayed prominently in the overlay.
|
||||
* @since v1.59
|
||||
*/
|
||||
void showChapter(String title, ShowChapterOptions options);
|
||||
/**
|
||||
* Enables visual annotations on interacted elements. Returns a disposable that stops showing actions when disposed.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
default AutoCloseable showActions() {
|
||||
return showActions(null);
|
||||
}
|
||||
/**
|
||||
* Enables visual annotations on interacted elements. Returns a disposable that stops showing actions when disposed.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
AutoCloseable showActions(ShowActionsOptions options);
|
||||
/**
|
||||
* Shows overlays.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void showOverlays();
|
||||
/**
|
||||
* Removes action decorations.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void hideActions();
|
||||
/**
|
||||
* Hides overlays without removing them.
|
||||
*
|
||||
* @since v1.59
|
||||
*/
|
||||
void hideOverlays();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface ScreencastFrame {
|
||||
/**
|
||||
* JPEG-encoded frame data.
|
||||
*/
|
||||
byte[] data();
|
||||
|
||||
/**
|
||||
* Width of the page viewport at the time the frame was captured.
|
||||
*/
|
||||
int viewportWidth();
|
||||
|
||||
/**
|
||||
* Height of the page viewport at the time the frame was captured.
|
||||
*/
|
||||
int viewportHeight();
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* API for collecting and saving Playwright traces. Playwright traces can be opened in <a
|
||||
@@ -44,6 +45,12 @@ import java.nio.file.Path;
|
||||
*/
|
||||
public interface Tracing {
|
||||
class StartOptions {
|
||||
/**
|
||||
* When enabled, the trace is written to an unarchived file that is updated in real time as actions occur, instead of
|
||||
* caching changes and archiving them into a zip file at the end. This is useful for live trace viewing during test
|
||||
* execution.
|
||||
*/
|
||||
public Boolean live;
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} directory specified in {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. To specify
|
||||
@@ -74,6 +81,15 @@ public interface Tracing {
|
||||
*/
|
||||
public String title;
|
||||
|
||||
/**
|
||||
* When enabled, the trace is written to an unarchived file that is updated in real time as actions occur, instead of
|
||||
* caching changes and archiving them into a zip file at the end. This is useful for live trace viewing during test
|
||||
* execution.
|
||||
*/
|
||||
public StartOptions setLive(boolean live) {
|
||||
this.live = live;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} directory specified in {@link com.microsoft.playwright.BrowserType#launch BrowserType.launch()}. To specify
|
||||
@@ -150,6 +166,59 @@ public interface Tracing {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class StartHarOptions {
|
||||
/**
|
||||
* Optional setting to control resource content management. If {@code omit} is specified, content is not persisted. If
|
||||
* {@code attach} is specified, resources are persisted as separate files or entries in the ZIP archive. If {@code embed}
|
||||
* is specified, content is stored inline the HAR file as per HAR specification. Defaults to {@code attach} for {@code
|
||||
* .zip} output files and to {@code embed} for all other file extensions.
|
||||
*/
|
||||
public HarContentPolicy content;
|
||||
/**
|
||||
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
|
||||
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
|
||||
* full}.
|
||||
*/
|
||||
public HarMode mode;
|
||||
/**
|
||||
* A glob or regex pattern to filter requests that are stored in the HAR. Defaults to none.
|
||||
*/
|
||||
public Object urlFilter;
|
||||
|
||||
/**
|
||||
* Optional setting to control resource content management. If {@code omit} is specified, content is not persisted. If
|
||||
* {@code attach} is specified, resources are persisted as separate files or entries in the ZIP archive. If {@code embed}
|
||||
* is specified, content is stored inline the HAR file as per HAR specification. Defaults to {@code attach} for {@code
|
||||
* .zip} output files and to {@code embed} for all other file extensions.
|
||||
*/
|
||||
public StartHarOptions setContent(HarContentPolicy content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
|
||||
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
|
||||
* full}.
|
||||
*/
|
||||
public StartHarOptions setMode(HarMode mode) {
|
||||
this.mode = mode;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob or regex pattern to filter requests that are stored in the HAR. Defaults to none.
|
||||
*/
|
||||
public StartHarOptions setUrlFilter(String urlFilter) {
|
||||
this.urlFilter = urlFilter;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob or regex pattern to filter requests that are stored in the HAR. Defaults to none.
|
||||
*/
|
||||
public StartHarOptions setUrlFilter(Pattern urlFilter) {
|
||||
this.urlFilter = urlFilter;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class GroupOptions {
|
||||
/**
|
||||
* Specifies a custom location for the group to be shown in the trace viewer. Defaults to the location of the {@link
|
||||
@@ -313,6 +382,48 @@ public interface Tracing {
|
||||
* @since v1.15
|
||||
*/
|
||||
void startChunk(StartChunkOptions options);
|
||||
/**
|
||||
* Start recording a HAR (HTTP Archive) of network activity in this context. The HAR file is written to disk when {@link
|
||||
* com.microsoft.playwright.Tracing#stopHar Tracing.stopHar()} is called, or when the returned {@code Disposable} is
|
||||
* disposed.
|
||||
*
|
||||
* <p> Only one HAR recording can be active at a time per {@code BrowserContext}.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.tracing().startHar(Paths.get("trace.har"));
|
||||
* Page page = context.newPage();
|
||||
* page.navigate("https://playwright.dev");
|
||||
* context.tracing().stopHar();
|
||||
* }</pre>
|
||||
*
|
||||
* @param path Path on the filesystem to write the HAR file to. If the file name ends with {@code .zip}, the HAR is saved as a zip
|
||||
* archive with response bodies attached as separate files.
|
||||
* @since v1.60
|
||||
*/
|
||||
default AutoCloseable startHar(Path path) {
|
||||
return startHar(path, null);
|
||||
}
|
||||
/**
|
||||
* Start recording a HAR (HTTP Archive) of network activity in this context. The HAR file is written to disk when {@link
|
||||
* com.microsoft.playwright.Tracing#stopHar Tracing.stopHar()} is called, or when the returned {@code Disposable} is
|
||||
* disposed.
|
||||
*
|
||||
* <p> Only one HAR recording can be active at a time per {@code BrowserContext}.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* context.tracing().startHar(Paths.get("trace.har"));
|
||||
* Page page = context.newPage();
|
||||
* page.navigate("https://playwright.dev");
|
||||
* context.tracing().stopHar();
|
||||
* }</pre>
|
||||
*
|
||||
* @param path Path on the filesystem to write the HAR file to. If the file name ends with {@code .zip}, the HAR is saved as a zip
|
||||
* archive with response bodies attached as separate files.
|
||||
* @since v1.60
|
||||
*/
|
||||
AutoCloseable startHar(Path path, StartHarOptions options);
|
||||
/**
|
||||
* <strong>NOTE:</strong> Use {@code test.step} instead when available.
|
||||
*
|
||||
@@ -333,8 +444,8 @@ public interface Tracing {
|
||||
* @param name Group name shown in the trace viewer.
|
||||
* @since v1.49
|
||||
*/
|
||||
default void group(String name) {
|
||||
group(name, null);
|
||||
default AutoCloseable group(String name) {
|
||||
return group(name, null);
|
||||
}
|
||||
/**
|
||||
* <strong>NOTE:</strong> Use {@code test.step} instead when available.
|
||||
@@ -356,7 +467,7 @@ public interface Tracing {
|
||||
* @param name Group name shown in the trace viewer.
|
||||
* @since v1.49
|
||||
*/
|
||||
void group(String name, GroupOptions options);
|
||||
AutoCloseable group(String name, GroupOptions options);
|
||||
/**
|
||||
* Closes the last group created by {@link com.microsoft.playwright.Tracing#group Tracing.group()}.
|
||||
*
|
||||
@@ -393,5 +504,12 @@ public interface Tracing {
|
||||
* @since v1.15
|
||||
*/
|
||||
void stopChunk(StopChunkOptions options);
|
||||
/**
|
||||
* Stop HAR recording and save the HAR file to the path given to {@link com.microsoft.playwright.Tracing#startHar
|
||||
* Tracing.startHar()}.
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
void stopHar();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.*;
|
||||
|
||||
/**
|
||||
* {@code WebError} class represents an unhandled exception thrown in the page. It is dispatched via the {@link
|
||||
@@ -43,5 +44,11 @@ public interface WebError {
|
||||
* @since v1.38
|
||||
*/
|
||||
String error();
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
WebErrorLocation location();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -213,6 +214,27 @@ public interface WebSocketRoute {
|
||||
* @since v1.48
|
||||
*/
|
||||
void send(byte[] message);
|
||||
/**
|
||||
* The list of WebSocket subprotocols requested by the page, as passed via the second argument to the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket">{@code WebSocket} constructor</a>.
|
||||
* Corresponds to the {@code Sec-WebSocket-Protocol} request header.
|
||||
*
|
||||
* <p> Returns an empty array if no protocols were specified.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.routeWebSocket("wss://example.com/ws", ws -> {
|
||||
* if (ws.protocols().contains("chat.v2")) {
|
||||
* ws.onMessage(frame -> ws.send("v2:" + frame.text()));
|
||||
* } else {
|
||||
* ws.close(1002, "Unsupported protocol");
|
||||
* }
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
List<String> protocols();
|
||||
/**
|
||||
* URL of the WebSocket created in the page.
|
||||
*
|
||||
|
||||
+5
-2
@@ -37,8 +37,11 @@ package com.microsoft.playwright.assertions;
|
||||
*/
|
||||
public interface APIResponseAssertions {
|
||||
/**
|
||||
* Makes the assertion check for the opposite condition. For example, this code tests that the response status is not
|
||||
* successful:
|
||||
* Makes the assertion check for the opposite condition.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this code tests that the response status is not successful:
|
||||
* <pre>{@code
|
||||
* assertThat(response).not().isOK();
|
||||
* }</pre>
|
||||
|
||||
+29
-14
@@ -19,6 +19,7 @@ package com.microsoft.playwright.assertions;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
import com.microsoft.playwright.options.PseudoElement;
|
||||
|
||||
/**
|
||||
* The {@code LocatorAssertions} class provides assertion methods that can be used to make assertions about the {@code
|
||||
@@ -427,11 +428,22 @@ public interface LocatorAssertions {
|
||||
}
|
||||
}
|
||||
class HasCSSOptions {
|
||||
/**
|
||||
* Pseudo-element to read computed styles from.
|
||||
*/
|
||||
public PseudoElement pseudo;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Pseudo-element to read computed styles from.
|
||||
*/
|
||||
public HasCSSOptions setPseudo(PseudoElement pseudo) {
|
||||
this.pseudo = pseudo;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
@@ -563,8 +575,11 @@ public interface LocatorAssertions {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain text
|
||||
* {@code "error"}:
|
||||
* Makes the assertion check for the opposite condition.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this code tests that the Locator doesn't contain text {@code "error"}:
|
||||
* <pre>{@code
|
||||
* assertThat(locator).not().containsText("error");
|
||||
* }</pre>
|
||||
@@ -885,7 +900,7 @@ public interface LocatorAssertions {
|
||||
* <p> When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected
|
||||
* class lists. Each element's class attribute is matched against the corresponding class in the array:
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".list > .component")).containsClass(new String[] {"inactive", "active", "inactive"});
|
||||
* assertThat(page.locator(".list > .component")).containsClass(Arrays.asList("inactive", "active", "inactive"));
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected A string containing expected class names, separated by spaces, or a list of such strings to assert multiple elements.
|
||||
@@ -909,7 +924,7 @@ public interface LocatorAssertions {
|
||||
* <p> When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected
|
||||
* class lists. Each element's class attribute is matched against the corresponding class in the array:
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".list > .component")).containsClass(new String[] {"inactive", "active", "inactive"});
|
||||
* assertThat(page.locator(".list > .component")).containsClass(Arrays.asList("inactive", "active", "inactive"));
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected A string containing expected class names, separated by spaces, or a list of such strings to assert multiple elements.
|
||||
@@ -931,7 +946,7 @@ public interface LocatorAssertions {
|
||||
* <p> When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected
|
||||
* class lists. Each element's class attribute is matched against the corresponding class in the array:
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".list > .component")).containsClass(new String[] {"inactive", "active", "inactive"});
|
||||
* assertThat(page.locator(".list > .component")).containsClass(Arrays.asList("inactive", "active", "inactive"));
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected A string containing expected class names, separated by spaces, or a list of such strings to assert multiple elements.
|
||||
@@ -955,7 +970,7 @@ public interface LocatorAssertions {
|
||||
* <p> When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected
|
||||
* class lists. Each element's class attribute is matched against the corresponding class in the array:
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".list > .component")).containsClass(new String[] {"inactive", "active", "inactive"});
|
||||
* assertThat(page.locator(".list > .component")).containsClass(Arrays.asList("inactive", "active", "inactive"));
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected A string containing expected class names, separated by spaces, or a list of such strings to assert multiple elements.
|
||||
@@ -989,7 +1004,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1034,7 +1049,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1077,7 +1092,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1122,7 +1137,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1165,7 +1180,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1210,7 +1225,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1253,7 +1268,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
@@ -1298,7 +1313,7 @@ public interface LocatorAssertions {
|
||||
* <p> Let's see how we can use the assertion:
|
||||
* <pre>{@code
|
||||
* // ✓ Contains the right items in the right order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3"});
|
||||
*
|
||||
* // ✖ Wrong order
|
||||
* assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
|
||||
|
||||
@@ -37,6 +37,20 @@ import java.util.regex.Pattern;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface PageAssertions {
|
||||
class MatchesAriaSnapshotOptions {
|
||||
/**
|
||||
* 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 MatchesAriaSnapshotOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class HasTitleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
@@ -79,8 +93,11 @@ public interface PageAssertions {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain
|
||||
* {@code "error"}:
|
||||
* Makes the assertion check for the opposite condition.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
*
|
||||
* <p> For example, this code tests that the page URL doesn't contain {@code "error"}:
|
||||
* <pre>{@code
|
||||
* assertThat(page).not().hasURL("error");
|
||||
* }</pre>
|
||||
@@ -88,6 +105,40 @@ public interface PageAssertions {
|
||||
* @since v1.20
|
||||
*/
|
||||
PageAssertions not();
|
||||
/**
|
||||
* Asserts that the page body matches the given <a href="https://playwright.dev/java/docs/aria-snapshots">accessibility
|
||||
* snapshot</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.navigate("https://demo.playwright.dev/todomvc/");
|
||||
* assertThat(page).matchesAriaSnapshot("""
|
||||
* - heading "todos"
|
||||
* - textbox "What needs to be done?"
|
||||
* """);
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
default void matchesAriaSnapshot(String expected) {
|
||||
matchesAriaSnapshot(expected, null);
|
||||
}
|
||||
/**
|
||||
* Asserts that the page body matches the given <a href="https://playwright.dev/java/docs/aria-snapshots">accessibility
|
||||
* snapshot</a>.
|
||||
*
|
||||
* <p> <strong>Usage</strong>
|
||||
* <pre>{@code
|
||||
* page.navigate("https://demo.playwright.dev/todomvc/");
|
||||
* assertThat(page).matchesAriaSnapshot("""
|
||||
* - heading "todos"
|
||||
* - textbox "What needs to be done?"
|
||||
* """);
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.60
|
||||
*/
|
||||
void matchesAriaSnapshot(String expected, MatchesAriaSnapshotOptions options);
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
|
||||
@@ -46,6 +46,11 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
this.tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.microsoft.playwright.Tracing tracing() {
|
||||
return tracing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public APIResponse delete(String url, RequestOptions options) {
|
||||
return fetch(url, ensureOptions(options, "DELETE"));
|
||||
|
||||
@@ -57,7 +57,14 @@ abstract class AssertionsBase {
|
||||
}
|
||||
FrameExpectResult result = doExpect(expression, expectOptions, title);
|
||||
if (result.matches == isNot) {
|
||||
Object actual = result.received == null ? null : Serialization.deserialize(result.received);
|
||||
Object actual;
|
||||
if (result.received == null) {
|
||||
actual = null;
|
||||
} else if (result.received.value != null) {
|
||||
actual = Serialization.deserialize(result.received.value);
|
||||
} else {
|
||||
actual = result.received.ariaSnapshot;
|
||||
}
|
||||
String log = (result.log == null) ? "" : String.join("\n", result.log);
|
||||
if (!log.isEmpty()) {
|
||||
log = "\nCall log:\n" + log;
|
||||
|
||||
@@ -43,6 +43,7 @@ import static java.util.Arrays.asList;
|
||||
class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
protected BrowserImpl browser;
|
||||
private final TracingImpl tracing;
|
||||
private final DebuggerImpl debugger;
|
||||
private final APIRequestContextImpl request;
|
||||
private final ClockImpl clock;
|
||||
final List<PageImpl> pages = new ArrayList<>();
|
||||
@@ -67,23 +68,18 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
private final ListenerCollection<EventType> listeners = new ListenerCollection<>(eventSubscriptions(), this);
|
||||
final TimeoutSettings timeoutSettings = new TimeoutSettings();
|
||||
final Map<String, HarRecorder> harRecorders = new HashMap<>();
|
||||
|
||||
static class HarRecorder {
|
||||
final Path path;
|
||||
final HarContentPolicy contentPolicy;
|
||||
|
||||
HarRecorder(Path har, HarContentPolicy policy) {
|
||||
path = har;
|
||||
contentPolicy = policy;
|
||||
}
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
CONSOLE,
|
||||
DIALOG,
|
||||
DOWNLOAD,
|
||||
FRAMEATTACHED,
|
||||
FRAMEDETACHED,
|
||||
FRAMENAVIGATED,
|
||||
PAGE,
|
||||
PAGECLOSE,
|
||||
PAGELOAD,
|
||||
WEBERROR,
|
||||
REQUEST,
|
||||
REQUESTFAILED,
|
||||
@@ -94,6 +90,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
BrowserContextImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
debugger = connection.getExistingObject(initializer.getAsJsonObject("debugger").get("guid").getAsString());
|
||||
request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
|
||||
request.timeoutSettings = timeoutSettings;
|
||||
clock = new ClockImpl(this);
|
||||
@@ -137,6 +134,20 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
public void offBackgroundPage(Consumer<Page> handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownload(Consumer<Download> handler) {
|
||||
listeners.add(EventType.DOWNLOAD, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offDownload(Consumer<Download> handler) {
|
||||
listeners.remove(EventType.DOWNLOAD, handler);
|
||||
}
|
||||
|
||||
void notifyDownload(Download download) {
|
||||
listeners.notify(EventType.DOWNLOAD, download);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<BrowserContext> handler) {
|
||||
listeners.add(EventType.CLOSE, handler);
|
||||
@@ -177,6 +188,76 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.remove(EventType.PAGE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrameAttached(Consumer<Frame> handler) {
|
||||
listeners.add(EventType.FRAMEATTACHED, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offFrameAttached(Consumer<Frame> handler) {
|
||||
listeners.remove(EventType.FRAMEATTACHED, handler);
|
||||
}
|
||||
|
||||
void notifyFrameAttached(FrameImpl frame) {
|
||||
listeners.notify(EventType.FRAMEATTACHED, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrameDetached(Consumer<Frame> handler) {
|
||||
listeners.add(EventType.FRAMEDETACHED, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offFrameDetached(Consumer<Frame> handler) {
|
||||
listeners.remove(EventType.FRAMEDETACHED, handler);
|
||||
}
|
||||
|
||||
void notifyFrameDetached(FrameImpl frame) {
|
||||
listeners.notify(EventType.FRAMEDETACHED, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrameNavigated(Consumer<Frame> handler) {
|
||||
listeners.add(EventType.FRAMENAVIGATED, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offFrameNavigated(Consumer<Frame> handler) {
|
||||
listeners.remove(EventType.FRAMENAVIGATED, handler);
|
||||
}
|
||||
|
||||
void notifyFrameNavigated(FrameImpl frame) {
|
||||
listeners.notify(EventType.FRAMENAVIGATED, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageClose(Consumer<Page> handler) {
|
||||
listeners.add(EventType.PAGECLOSE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offPageClose(Consumer<Page> handler) {
|
||||
listeners.remove(EventType.PAGECLOSE, handler);
|
||||
}
|
||||
|
||||
void notifyPageClose(PageImpl page) {
|
||||
listeners.notify(EventType.PAGECLOSE, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageLoad(Consumer<Page> handler) {
|
||||
listeners.add(EventType.PAGELOAD, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offPageLoad(Consumer<Page> handler) {
|
||||
listeners.remove(EventType.PAGELOAD, handler);
|
||||
}
|
||||
|
||||
void notifyPageLoad(PageImpl page) {
|
||||
listeners.notify(EventType.PAGELOAD, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebError(Consumer<WebError> handler) {
|
||||
listeners.add(EventType.WEBERROR, handler);
|
||||
@@ -268,6 +349,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return closingOrClosed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
if (!closingOrClosed) {
|
||||
@@ -277,27 +363,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
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());
|
||||
JsonObject json = sendMessage("harExport", params, NO_TIMEOUT).getAsJsonObject();
|
||||
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject("artifact").get("guid").getAsString());
|
||||
// Server side will compress artifact if content is attach or if file is .zip.
|
||||
HarRecorder harParams = entry.getValue();
|
||||
boolean isCompressed = harParams.contentPolicy == HarContentPolicy.ATTACH || harParams.path.toString().endsWith(".zip");
|
||||
boolean needCompressed = harParams.path.toString().endsWith(".zip");
|
||||
if (isCompressed && !needCompressed) {
|
||||
String tmpPath = harParams.path + ".tmp";
|
||||
artifact.saveAs(Paths.get(tmpPath));
|
||||
JsonObject unzipParams = new JsonObject();
|
||||
unzipParams.addProperty("zipFile", tmpPath);
|
||||
unzipParams.addProperty("harFile", harParams.path.toString());
|
||||
connection.localUtils.sendMessage("harUnzip", unzipParams, NO_TIMEOUT);
|
||||
} else {
|
||||
artifact.saveAs(harParams.path);
|
||||
}
|
||||
artifact.delete();
|
||||
}
|
||||
tracing.exportAllHars();
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("close", params, NO_TIMEOUT);
|
||||
}
|
||||
@@ -318,17 +384,18 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInitScript(String script) {
|
||||
public AutoCloseable addInitScript(String script) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("source", script);
|
||||
sendMessage("addInitScript", params, NO_TIMEOUT);
|
||||
JsonObject result = sendMessage("addInitScript", params, NO_TIMEOUT).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("disposable").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInitScript(Path path) {
|
||||
public AutoCloseable addInitScript(Path path) {
|
||||
try {
|
||||
byte[] bytes = readAllBytes(path);
|
||||
addInitScript(new String(bytes, UTF_8));
|
||||
return addInitScript(new String(bytes, UTF_8));
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read script from file", e);
|
||||
}
|
||||
@@ -384,11 +451,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exposeBinding(String name, BindingCallback playwrightBinding, ExposeBindingOptions options) {
|
||||
exposeBindingImpl(name, playwrightBinding, options);
|
||||
public AutoCloseable exposeBinding(String name, BindingCallback playwrightBinding) {
|
||||
return exposeBindingImpl(name, playwrightBinding);
|
||||
}
|
||||
|
||||
private void exposeBindingImpl(String name, BindingCallback playwrightBinding, ExposeBindingOptions options) {
|
||||
private AutoCloseable exposeBindingImpl(String name, BindingCallback playwrightBinding) {
|
||||
if (bindings.containsKey(name)) {
|
||||
throw new PlaywrightException("Function \"" + name + "\" has been already registered");
|
||||
}
|
||||
@@ -401,15 +468,13 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("name", name);
|
||||
if (options != null && options.handle != null && options.handle) {
|
||||
params.addProperty("needsHandle", true);
|
||||
}
|
||||
sendMessage("exposeBinding", params, NO_TIMEOUT);
|
||||
JsonObject result = sendMessage("exposeBinding", params, NO_TIMEOUT).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("disposable").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exposeFunction(String name, FunctionCallback playwrightFunction) {
|
||||
exposeBindingImpl(name, (BindingCallback.Source source, Object... args) -> playwrightFunction.call(args), null);
|
||||
public AutoCloseable exposeFunction(String name, FunctionCallback playwrightFunction) {
|
||||
return exposeBindingImpl(name, (BindingCallback.Source source, Object... args) -> playwrightFunction.call(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -445,18 +510,21 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void route(String url, Consumer<Route> handler, RouteOptions options) {
|
||||
public AutoCloseable route(String url, Consumer<Route> handler, RouteOptions options) {
|
||||
route(UrlMatcher.forGlob(baseUrl(), url, this.connection.localUtils, false), handler, options);
|
||||
return new DisposableStub(() -> unroute(url, handler));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void route(Pattern url, Consumer<Route> handler, RouteOptions options) {
|
||||
public AutoCloseable route(Pattern url, Consumer<Route> handler, RouteOptions options) {
|
||||
route(new UrlMatcher(url), handler, options);
|
||||
return new DisposableStub(() -> unroute(url, handler));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options) {
|
||||
public AutoCloseable route(Predicate<String> url, Consumer<Route> handler, RouteOptions options) {
|
||||
route(new UrlMatcher(url), handler, options);
|
||||
return new DisposableStub(() -> unroute(url, handler));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -503,24 +571,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
if (contentPolicy == null) {
|
||||
contentPolicy = Utils.convertType(options.updateContent, HarContentPolicy.class);
|
||||
}
|
||||
if (contentPolicy == null) {
|
||||
contentPolicy = HarContentPolicy.ATTACH;
|
||||
}
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
if (page != null) {
|
||||
params.add("page", page.toProtocolRef());
|
||||
}
|
||||
JsonObject recordHarArgs = new JsonObject();
|
||||
recordHarArgs.addProperty("zip", har.toString().endsWith(".zip"));
|
||||
recordHarArgs.addProperty("content", contentPolicy.name().toLowerCase());
|
||||
recordHarArgs.addProperty("mode", (options.updateMode == null ? HarMode.MINIMAL : options.updateMode).name().toLowerCase());
|
||||
addHarUrlFilter(recordHarArgs, options.url);
|
||||
|
||||
params.add("options", recordHarArgs);
|
||||
JsonObject json = sendMessage("harStart", params, NO_TIMEOUT).getAsJsonObject();
|
||||
String harId = json.get("harId").getAsString();
|
||||
harRecorders.put(harId, new HarRecorder(har, contentPolicy));
|
||||
tracing.recordIntoHar(page, har, options.url, contentPolicy, options.updateMode, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -563,6 +614,18 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
sendMessage("setOffline", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStorageState(Path storageState) {
|
||||
try {
|
||||
String state = new String(readAllBytes(storageState), UTF_8);
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("storageState", state);
|
||||
sendMessage("setStorageState", params, NO_TIMEOUT);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read storage state from file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String storageState(StorageStateOptions options) {
|
||||
if (options == null) {
|
||||
@@ -579,6 +642,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return storageState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DebuggerImpl debugger() {
|
||||
return debugger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TracingImpl tracing() {
|
||||
return tracing;
|
||||
@@ -775,7 +843,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
} else if ("response".equals(event)) {
|
||||
String guid = params.getAsJsonObject("response").get("guid").getAsString();
|
||||
Response response = connection.getExistingObject(guid);
|
||||
ResponseImpl response = connection.getExistingObject(guid);
|
||||
listeners.notify(EventType.RESPONSE, response);
|
||||
if (params.has("page")) {
|
||||
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
@@ -789,7 +857,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
} catch (PlaywrightException e) {
|
||||
page = null;
|
||||
}
|
||||
listeners.notify(BrowserContextImpl.EventType.WEBERROR, new WebErrorImpl(page, errorStr));
|
||||
WebErrorLocation location = null;
|
||||
if (params.has("location")) {
|
||||
location = gson().fromJson(params.getAsJsonObject("location"), WebErrorLocation.class);
|
||||
}
|
||||
listeners.notify(BrowserContextImpl.EventType.WEBERROR, new WebErrorImpl(page, errorStr, location));
|
||||
if (page != null) {
|
||||
page.listeners.notify(PageImpl.EventType.PAGEERROR, errorStr);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.*;
|
||||
import com.microsoft.playwright.options.BindResult;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -42,6 +43,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
String closeReason;
|
||||
|
||||
enum EventType {
|
||||
CONTEXT,
|
||||
DISCONNECTED,
|
||||
}
|
||||
|
||||
@@ -49,6 +51,16 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContext(Consumer<BrowserContext> handler) {
|
||||
listeners.add(EventType.CONTEXT, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offContext(Consumer<BrowserContext> handler) {
|
||||
listeners.remove(EventType.CONTEXT, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(Consumer<Browser> handler) {
|
||||
listeners.add(EventType.DISCONNECTED, handler);
|
||||
@@ -195,6 +207,32 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
sendMessage("startTracing", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindResult bind(String title, BindOptions options) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("title", title);
|
||||
if (options != null) {
|
||||
if (options.host != null) {
|
||||
params.addProperty("host", options.host);
|
||||
}
|
||||
if (options.port != null) {
|
||||
params.addProperty("port", options.port);
|
||||
}
|
||||
if (options.workspaceDir != null) {
|
||||
params.addProperty("workspaceDir", options.workspaceDir);
|
||||
}
|
||||
}
|
||||
JsonObject result = sendMessage("startServer", params, NO_TIMEOUT).getAsJsonObject();
|
||||
BindResult bindResult = new BindResult();
|
||||
bindResult.endpoint = result.get("endpoint").getAsString();
|
||||
return bindResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
sendMessage("stopServer", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] stopTracing() {
|
||||
JsonObject json = sendMessage("stopTracing").getAsJsonObject();
|
||||
@@ -275,6 +313,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
context.tracing().setTracesDir(tracePath);
|
||||
browserType.playwright.selectors.contextsForSelectors.add(context);
|
||||
}
|
||||
listeners.notify(EventType.CONTEXT, context);
|
||||
}
|
||||
|
||||
private void didClose() {
|
||||
|
||||
@@ -59,7 +59,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
}
|
||||
// We don't use gson() here as the headers map should be serialized to a json object.
|
||||
JsonObject params = new Gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("wsEndpoint", wsEndpoint);
|
||||
params.addProperty("endpoint", wsEndpoint);
|
||||
|
||||
if (!params.has("headers")) {
|
||||
params.add("headers", new JsonObject());
|
||||
|
||||
@@ -25,6 +25,11 @@ import java.util.function.Consumer;
|
||||
|
||||
public class CDPSessionImpl extends ChannelOwner implements CDPSession {
|
||||
private final ListenerCollection<String> listeners = new ListenerCollection<>(new HashMap<>(), this);
|
||||
private final ListenerCollection<EventType> typedListeners = new ListenerCollection<>(new HashMap<>(), this);
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
}
|
||||
|
||||
protected CDPSessionImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
@@ -40,9 +45,22 @@ public class CDPSessionImpl extends ChannelOwner implements CDPSession {
|
||||
params = parameters.get("params").getAsJsonObject();
|
||||
}
|
||||
listeners.notify(method, params);
|
||||
listeners.notify("event", parameters);
|
||||
} else if ("close".equals(event)) {
|
||||
typedListeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<CDPSession> handler) {
|
||||
typedListeners.add(EventType.CLOSE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offClose(Consumer<CDPSession> handler) {
|
||||
typedListeners.remove(EventType.CLOSE, handler);
|
||||
}
|
||||
|
||||
public JsonObject send(String method) {
|
||||
return send(method, null);
|
||||
}
|
||||
|
||||
@@ -333,6 +333,9 @@ public class Connection {
|
||||
case "Dialog":
|
||||
result = new DialogImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "Disposable":
|
||||
result = new DisposableObject(parent, type, guid, initializer);
|
||||
break;
|
||||
case "Electron":
|
||||
// result = new Playwright(parent, type, guid, initializer);
|
||||
break;
|
||||
@@ -378,6 +381,9 @@ public class Connection {
|
||||
break;
|
||||
case "SocksSupport":
|
||||
break;
|
||||
case "Debugger":
|
||||
result = new DebuggerImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "Tracing":
|
||||
result = new TracingImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
|
||||
@@ -38,6 +38,11 @@ public class ConsoleMessageImpl implements ConsoleMessage {
|
||||
this.initializer = initializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double timestamp() {
|
||||
return initializer.get("timestamp").getAsDouble();
|
||||
}
|
||||
|
||||
public String type() {
|
||||
return initializer.get("type").getAsString();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Debugger;
|
||||
import com.microsoft.playwright.options.Location;
|
||||
import com.microsoft.playwright.options.DebuggerPausedDetails;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class DebuggerImpl extends ChannelOwner implements Debugger {
|
||||
private final List<Runnable> pausedStateChangedHandlers = new ArrayList<>();
|
||||
private DebuggerPausedDetails pausedDetails;
|
||||
|
||||
DebuggerImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleEvent(String event, JsonObject params) {
|
||||
if ("pausedStateChanged".equals(event)) {
|
||||
if (params.has("pausedDetails") && !params.get("pausedDetails").isJsonNull()) {
|
||||
pausedDetails = gson().fromJson(params.get("pausedDetails"), DebuggerPausedDetails.class);
|
||||
} else {
|
||||
pausedDetails = null;
|
||||
}
|
||||
for (Runnable handler : new ArrayList<>(pausedStateChangedHandlers)) {
|
||||
handler.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPausedStateChanged(Runnable handler) {
|
||||
pausedStateChangedHandlers.add(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offPausedStateChanged(Runnable handler) {
|
||||
pausedStateChangedHandlers.remove(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DebuggerPausedDetails pausedDetails() {
|
||||
return pausedDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestPause() {
|
||||
sendMessage("requestPause", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
sendMessage("resume", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
sendMessage("next", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTo(Location location) {
|
||||
JsonObject params = gson().toJsonTree(location).getAsJsonObject();
|
||||
sendMessage("runTo", params, NO_TIMEOUT);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,11 @@ class DialogImpl extends ChannelOwner implements Dialog {
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
sendMessage("dismiss");
|
||||
try {
|
||||
sendMessage("dismiss");
|
||||
} catch (TargetClosedError e) {
|
||||
// Swallow TargetClosedErrors for beforeunload dialogs.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
class DisposableObject extends ChannelOwner implements AutoCloseable {
|
||||
DisposableObject(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
sendMessage("dispose", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
class DisposableStub implements AutoCloseable {
|
||||
private Runnable dispose;
|
||||
|
||||
DisposableStub(Runnable dispose) {
|
||||
this.dispose = dispose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (dispose == null)
|
||||
return;
|
||||
Runnable d = dispose;
|
||||
dispose = null;
|
||||
d.run();
|
||||
}
|
||||
}
|
||||
@@ -1051,12 +1051,58 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
return result.get("value").getAsInt();
|
||||
}
|
||||
|
||||
void highlightImpl(String selector) {
|
||||
void dropImpl(String selector, DropPayload payload, com.microsoft.playwright.Locator.DropOptions options) {
|
||||
if (options == null) {
|
||||
options = new com.microsoft.playwright.Locator.DropOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
params.addProperty("strict", true);
|
||||
if (payload != null) {
|
||||
if (payload.files != null) {
|
||||
if (payload.files instanceof Path) {
|
||||
addFilePathUploadParams(new Path[] { (Path) payload.files }, params, page.context());
|
||||
} else if (payload.files instanceof Path[]) {
|
||||
addFilePathUploadParams((Path[]) payload.files, params, page.context());
|
||||
} else if (payload.files instanceof com.microsoft.playwright.options.FilePayload) {
|
||||
checkFilePayloadSize(new com.microsoft.playwright.options.FilePayload[] { (com.microsoft.playwright.options.FilePayload) payload.files });
|
||||
params.add("payloads", toJsonArray(new com.microsoft.playwright.options.FilePayload[] { (com.microsoft.playwright.options.FilePayload) payload.files }));
|
||||
} else if (payload.files instanceof com.microsoft.playwright.options.FilePayload[]) {
|
||||
checkFilePayloadSize((com.microsoft.playwright.options.FilePayload[]) payload.files);
|
||||
params.add("payloads", toJsonArray((com.microsoft.playwright.options.FilePayload[]) payload.files));
|
||||
} else {
|
||||
throw new com.microsoft.playwright.PlaywrightException("Unsupported files type: " + payload.files.getClass());
|
||||
}
|
||||
}
|
||||
if (payload.data != null) {
|
||||
com.google.gson.JsonArray dataArray = new com.google.gson.JsonArray();
|
||||
for (java.util.Map.Entry<String, String> entry : payload.data.entrySet()) {
|
||||
JsonObject e = new JsonObject();
|
||||
e.addProperty("mimeType", entry.getKey());
|
||||
e.addProperty("value", entry.getValue());
|
||||
dataArray.add(e);
|
||||
}
|
||||
params.add("data", dataArray);
|
||||
}
|
||||
}
|
||||
sendMessage("drop", params, timeout(options.timeout));
|
||||
}
|
||||
|
||||
void highlightImpl(String selector, String style) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
if (style != null) {
|
||||
params.addProperty("style", style);
|
||||
}
|
||||
sendMessage("highlight", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
void hideHighlightImpl(String selector) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("hideHighlight", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
protected void handleEvent(String event, JsonObject params) {
|
||||
if ("loadstate".equals(event)) {
|
||||
JsonElement add = params.get("add");
|
||||
@@ -1066,6 +1112,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
if (parentFrame == null && page != null) {
|
||||
if (state == LOAD) {
|
||||
page.listeners.notify(PageImpl.EventType.LOAD, page);
|
||||
page.browserContext.notifyPageLoad(page);
|
||||
} else if (state == DOMCONTENTLOADED) {
|
||||
page.listeners.notify(PageImpl.EventType.DOMCONTENTLOADED, page);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
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.Request;
|
||||
@@ -82,7 +84,7 @@ public class HARRouter {
|
||||
if (status == -1) {
|
||||
return;
|
||||
}
|
||||
Map<String, String> headers = fromNameValues(response.getAsJsonArray("headers"));
|
||||
Map<String, String> headers = mergeSetCookieHeaders(response.getAsJsonArray("headers"));
|
||||
byte[] buffer = Base64.getDecoder().decode(response.get("body").getAsString());
|
||||
route.fulfill(new Route.FulfillOptions()
|
||||
.setStatus(status)
|
||||
@@ -105,6 +107,25 @@ public class HARRouter {
|
||||
route.abort();
|
||||
}
|
||||
|
||||
private static Map<String, String> mergeSetCookieHeaders(JsonArray headersArray) {
|
||||
Map<String, String> result = new java.util.LinkedHashMap<>();
|
||||
for (JsonElement element : headersArray) {
|
||||
JsonObject pair = element.getAsJsonObject();
|
||||
String name = pair.get("name").getAsString();
|
||||
String value = pair.get("value").getAsString();
|
||||
if ("set-cookie".equalsIgnoreCase(name)) {
|
||||
if (!result.containsKey("set-cookie")) {
|
||||
result.put("set-cookie", value);
|
||||
} else {
|
||||
result.put("set-cookie", result.get("set-cookie") + "\n" + value);
|
||||
}
|
||||
} else {
|
||||
result.put(name, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("harId", harId);
|
||||
|
||||
@@ -34,13 +34,20 @@ public class LocalUtils extends ChannelOwner {
|
||||
return initializer.getAsJsonArray("deviceDescriptors");
|
||||
}
|
||||
|
||||
void zip(Path zipFile, JsonArray entries, String stacksId, boolean appendMode, boolean includeSources) {
|
||||
void zip(Path zipFile, JsonArray entries, String stacksId, boolean appendMode, boolean includeSources, List<String> additionalSources) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("zipFile", zipFile.toString());
|
||||
params.add("entries", entries);
|
||||
params.addProperty("mode", appendMode ? "append" : "write");
|
||||
params.addProperty("stacksId", stacksId);
|
||||
params.addProperty("includeSources", includeSources);
|
||||
if (!additionalSources.isEmpty()) {
|
||||
JsonArray sourcesArray = new JsonArray();
|
||||
for (String source : additionalSources) {
|
||||
sourcesArray.add(source);
|
||||
}
|
||||
params.add("additionalSources", sourcesArray);
|
||||
}
|
||||
sendMessage("zip", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,14 @@ class LocatorImpl implements Locator {
|
||||
return (List<String>) frame.evalOnSelectorAll(selector, "ee => ee.map(e => e.textContent || '')");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator normalize() {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
JsonObject result = frame.sendMessage("resolveSelector", params, ChannelOwner.NO_TIMEOUT).getAsJsonObject();
|
||||
return new LocatorImpl(frame, result.get("resolvedSelector").getAsString(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator and(Locator locator) {
|
||||
LocatorImpl other = (LocatorImpl) locator;
|
||||
@@ -363,8 +371,20 @@ class LocatorImpl implements Locator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void highlight() {
|
||||
frame.highlightImpl(selector);
|
||||
public void drop(DropPayload payload, DropOptions options) {
|
||||
frame.dropImpl(selector, payload, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoCloseable highlight(HighlightOptions options) {
|
||||
String style = options == null ? null : options.style;
|
||||
frame.highlightImpl(selector, style);
|
||||
return new DisposableStub(this::hideHighlight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideHighlight() {
|
||||
frame.hideHighlightImpl(selector);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,6 +86,10 @@ public class LocatorUtils {
|
||||
String name = escapeForAttributeSelector(options.name, options.exact != null && options.exact);
|
||||
addAttr(result, "name", name);
|
||||
}
|
||||
if (options.description != null) {
|
||||
String description = escapeForAttributeSelector(options.description, options.exact != null && options.exact);
|
||||
addAttr(result, "description", description);
|
||||
}
|
||||
if (options.pressed != null)
|
||||
addAttr(result, "pressed", options.pressed.toString());
|
||||
}
|
||||
|
||||
@@ -73,6 +73,16 @@ public class PageAssertionsImpl extends AssertionsBase implements PageAssertions
|
||||
expectImpl("to.have.url", expected, pattern, "Page URL expected to match regex", convertType(options, FrameExpectOptions.class), "Assert \"hasURL\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void matchesAriaSnapshot(String expected, MatchesAriaSnapshotOptions snapshotOptions) {
|
||||
if (snapshotOptions == null) {
|
||||
snapshotOptions = new MatchesAriaSnapshotOptions();
|
||||
}
|
||||
FrameExpectOptions options = convertType(snapshotOptions, FrameExpectOptions.class);
|
||||
options.expectedValue = Serialization.serializeArgument(expected);
|
||||
expectImpl("to.match.aria", options, expected, "Page expected to match Aria snapshot", "Assert \"matchesAriaSnapshot\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageAssertions not() {
|
||||
return new PageAssertionsImpl(actualPage, !isNot);
|
||||
|
||||
@@ -41,11 +41,12 @@ import static java.util.Arrays.asList;
|
||||
|
||||
|
||||
public class PageImpl extends ChannelOwner implements Page {
|
||||
private final BrowserContextImpl browserContext;
|
||||
final BrowserContextImpl browserContext;
|
||||
private final FrameImpl mainFrame;
|
||||
private final KeyboardImpl keyboard;
|
||||
private final MouseImpl mouse;
|
||||
private final TouchscreenImpl touchscreen;
|
||||
private final ScreencastImpl screencast;
|
||||
final Waitable<?> waitableClosedOrCrashed;
|
||||
private ViewportSize viewport;
|
||||
private final Router routes = new Router();
|
||||
@@ -135,6 +136,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
keyboard = new KeyboardImpl(this);
|
||||
mouse = new MouseImpl(this);
|
||||
touchscreen = new TouchscreenImpl(this);
|
||||
screencast = new ScreencastImpl(this);
|
||||
frames.add(mainFrame);
|
||||
timeoutSettings = new TimeoutSettings(browserContext.timeoutSettings);
|
||||
waitableClosedOrCrashed = createWaitForCloseHelper();
|
||||
@@ -143,6 +145,13 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
} else {
|
||||
opener = null;
|
||||
}
|
||||
if (initializer.has("video")) {
|
||||
String artifactGuid = initializer.getAsJsonObject("video").get("guid").getAsString();
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
video = new VideoImpl(this, artifact);
|
||||
} else {
|
||||
video = new VideoImpl(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,6 +171,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
DownloadImpl download = new DownloadImpl(this, artifact, params);
|
||||
listeners.notify(EventType.DOWNLOAD, download);
|
||||
browserContext.notifyDownload(download);
|
||||
} else if ("fileChooser".equals(event)) {
|
||||
String guid = params.getAsJsonObject("element").get("guid").getAsString();
|
||||
ElementHandleImpl elementHandle = connection.getExistingObject(guid);
|
||||
@@ -192,6 +202,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
frame.parentFrame.childFrames.add(frame);
|
||||
}
|
||||
listeners.notify(EventType.FRAMEATTACHED, frame);
|
||||
browserContext.notifyFrameAttached(frame);
|
||||
} else if ("frameDetached".equals(event)) {
|
||||
String guid = params.getAsJsonObject("frame").get("guid").getAsString();
|
||||
FrameImpl frame = connection.getExistingObject(guid);
|
||||
@@ -201,6 +212,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
frame.parentFrame.childFrames.remove(frame);
|
||||
}
|
||||
listeners.notify(EventType.FRAMEDETACHED, frame);
|
||||
browserContext.notifyFrameDetached(frame);
|
||||
} else if ("locatorHandlerTriggered".equals(event)) {
|
||||
int uid = params.get("uid").getAsInt();
|
||||
onLocatorHandlerTriggered(uid);
|
||||
@@ -219,14 +231,12 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
if (!webSocketRoutes.handle(route)) {
|
||||
browserContext.handleWebSocketRoute(route);
|
||||
}
|
||||
} else if ("video".equals(event)) {
|
||||
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
forceVideo().setArtifact(artifact);
|
||||
} else if ("crash".equals(event)) {
|
||||
listeners.notify(EventType.CRASH, this);
|
||||
} else if ("close".equals(event)) {
|
||||
didClose();
|
||||
} else if ("screencastFrame".equals(event)) {
|
||||
screencast.handleScreencastFrame(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,6 +248,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
isClosed = true;
|
||||
browserContext.pages.remove(this);
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
browserContext.notifyPageClose(this);
|
||||
}
|
||||
|
||||
private String effectiveCloseReason() {
|
||||
@@ -633,6 +644,16 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ariaSnapshot(AriaSnapshotOptions options) {
|
||||
if (options == null) {
|
||||
options = new AriaSnapshotOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
JsonObject result = mainFrame.sendMessage("ariaSnapshot", params, mainFrame.timeout(options.timeout)).getAsJsonObject();
|
||||
return result.get("snapshot").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object evalOnSelector(String selector, String pageFunction, Object arg, EvalOnSelectorOptions options) {
|
||||
return mainFrame.evalOnSelectorImpl(
|
||||
@@ -645,25 +666,26 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInitScript(String script) {
|
||||
addInitScriptImpl(script);
|
||||
public AutoCloseable addInitScript(String script) {
|
||||
return addInitScriptImpl(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInitScript(Path path) {
|
||||
public AutoCloseable addInitScript(Path path) {
|
||||
try {
|
||||
byte[] bytes = readAllBytes(path);
|
||||
String script = addSourceUrlToScript(new String(bytes, UTF_8), path);
|
||||
addInitScriptImpl(script);
|
||||
return addInitScriptImpl(script);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read script from file", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addInitScriptImpl(String script) {
|
||||
private AutoCloseable addInitScriptImpl(String script) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("source", script);
|
||||
sendMessage("addInitScript", params, NO_TIMEOUT);
|
||||
JsonObject result = sendMessage("addInitScript", params, NO_TIMEOUT).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("disposable").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -735,11 +757,11 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exposeBinding(String name, BindingCallback playwrightBinding, ExposeBindingOptions options) {
|
||||
exposeBindingImpl(name, playwrightBinding, options);
|
||||
public AutoCloseable exposeBinding(String name, BindingCallback playwrightBinding) {
|
||||
return exposeBindingImpl(name, playwrightBinding);
|
||||
}
|
||||
|
||||
private void exposeBindingImpl(String name, BindingCallback playwrightBinding, ExposeBindingOptions options) {
|
||||
private AutoCloseable exposeBindingImpl(String name, BindingCallback playwrightBinding) {
|
||||
if (bindings.containsKey(name)) {
|
||||
throw new PlaywrightException("Function \"" + name + "\" has been already registered");
|
||||
}
|
||||
@@ -750,15 +772,13 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("name", name);
|
||||
if (options != null && options.handle != null && options.handle) {
|
||||
params.addProperty("needsHandle", true);
|
||||
}
|
||||
sendMessage("exposeBinding", params, NO_TIMEOUT);
|
||||
JsonObject result = sendMessage("exposeBinding", params, NO_TIMEOUT).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("disposable").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exposeFunction(String name, FunctionCallback playwrightFunction) {
|
||||
exposeBindingImpl(name, (BindingCallback.Source source, Object... args) -> playwrightFunction.call(args), null);
|
||||
public AutoCloseable exposeFunction(String name, FunctionCallback playwrightFunction) {
|
||||
return exposeBindingImpl(name, (BindingCallback.Source source, Object... args) -> playwrightFunction.call(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -998,8 +1018,9 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConsoleMessage> consoleMessages() {
|
||||
JsonObject json = sendMessage("consoleMessages", new JsonObject(), NO_TIMEOUT).getAsJsonObject();
|
||||
public List<ConsoleMessage> consoleMessages(ConsoleMessagesOptions options) {
|
||||
JsonObject params = options != null ? gson().toJsonTree(options).getAsJsonObject() : new JsonObject();
|
||||
JsonObject json = sendMessage("consoleMessages", params, NO_TIMEOUT).getAsJsonObject();
|
||||
JsonArray messages = json.getAsJsonArray("messages");
|
||||
List<ConsoleMessage> result = new ArrayList<>();
|
||||
for (JsonElement item : messages) {
|
||||
@@ -1008,6 +1029,16 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsoleMessages() {
|
||||
sendMessage("clearConsoleMessages", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPageErrors() {
|
||||
sendMessage("clearPageErrors", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> pageErrors() {
|
||||
JsonObject json = sendMessage("pageErrors", new JsonObject(), NO_TIMEOUT).getAsJsonObject();
|
||||
@@ -1030,6 +1061,11 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return mainFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideHighlight() {
|
||||
sendMessage("hideHighlight", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mouse mouse() {
|
||||
return mouse;
|
||||
@@ -1043,6 +1079,17 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return opener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelPickLocator() {
|
||||
sendMessage("cancelPickLocator", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator pickLocator() {
|
||||
JsonObject result = sendMessage("pickLocator", new JsonObject(), NO_TIMEOUT).getAsJsonObject();
|
||||
return new LocatorImpl(mainFrame, result.get("selector").getAsString(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
TimeoutSettings settings = browserContext.timeoutSettings;
|
||||
@@ -1105,18 +1152,21 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void route(String url, Consumer<Route> handler, RouteOptions options) {
|
||||
public AutoCloseable route(String url, Consumer<Route> handler, RouteOptions options) {
|
||||
route(UrlMatcher.forGlob(browserContext.baseUrl(), url, this.connection.localUtils, false), handler, options);
|
||||
return new DisposableStub(() -> unroute(url, handler));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void route(Pattern url, Consumer<Route> handler, RouteOptions options) {
|
||||
public AutoCloseable route(Pattern url, Consumer<Route> handler, RouteOptions options) {
|
||||
route(new UrlMatcher(url), handler, options);
|
||||
return new DisposableStub(() -> unroute(url, handler));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options) {
|
||||
public AutoCloseable route(Predicate<String> url, Consumer<Route> handler, RouteOptions options) {
|
||||
route(new UrlMatcher(url), handler, options);
|
||||
return new DisposableStub(() -> unroute(url, handler));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1307,6 +1357,11 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return touchscreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Screencast screencast() {
|
||||
return screencast;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void type(String selector, String text, TypeOptions options) {
|
||||
mainFrame.type(selector, text, convertType(options, Frame.TypeOptions.class));
|
||||
@@ -1357,22 +1412,9 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
|
||||
private VideoImpl forceVideo() {
|
||||
if (video == null) {
|
||||
video = new VideoImpl(this);
|
||||
}
|
||||
return video;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoImpl video() {
|
||||
// Note: we are creating Video object lazily, because we do not know
|
||||
// BrowserContextOptions when constructing the page - it is assigned
|
||||
// too late during launchPersistentContext.
|
||||
if (browserContext.videosDir() == null) {
|
||||
return null;
|
||||
}
|
||||
return forceVideo();
|
||||
return video;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1421,6 +1463,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
void frameNavigated(FrameImpl frame) {
|
||||
listeners.notify(EventType.FRAMENAVIGATED, frame);
|
||||
browserContext.notifyFrameNavigated(frame);
|
||||
}
|
||||
|
||||
private class WaitableFrameDetach extends WaitableEvent<EventType, Frame> {
|
||||
|
||||
@@ -112,8 +112,12 @@ class FrameExpectOptions {
|
||||
}
|
||||
|
||||
class FrameExpectResult {
|
||||
static class Received {
|
||||
SerializedValue value;
|
||||
String ariaSnapshot;
|
||||
}
|
||||
boolean matches;
|
||||
SerializedValue received;
|
||||
Received received;
|
||||
String errorMessage;
|
||||
List<String> log;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class RequestImpl extends ChannelOwner implements Request {
|
||||
String failure;
|
||||
Timing timing;
|
||||
boolean didFailOrFinish;
|
||||
ResponseImpl existingResponse;
|
||||
private FallbackOverrides fallbackOverrides;
|
||||
|
||||
static class FallbackOverrides {
|
||||
@@ -66,6 +67,11 @@ public class RequestImpl extends ChannelOwner implements Request {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseImpl existingResponse() {
|
||||
return existingResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> allHeaders() {
|
||||
return getRawHeaders().headers();
|
||||
|
||||
@@ -36,12 +36,13 @@ import static java.util.Arrays.asList;
|
||||
public class ResponseImpl extends ChannelOwner implements Response {
|
||||
private final RawHeaders headers;
|
||||
private RawHeaders rawHeaders;
|
||||
private final RequestImpl request;
|
||||
final RequestImpl request;
|
||||
|
||||
ResponseImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
headers = new RawHeaders(asList(gson().fromJson(initializer.getAsJsonArray("headers"), HttpHeader[].class)));
|
||||
request = connection.getExistingObject(initializer.getAsJsonObject("request").get("guid").getAsString());
|
||||
request.existingResponse = this;
|
||||
request.timing = gson().fromJson(initializer.get("timing"), Timing.class);
|
||||
}
|
||||
|
||||
@@ -86,6 +87,12 @@ public class ResponseImpl extends ChannelOwner implements Response {
|
||||
return initializer.get("fromServiceWorker").getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String httpVersion() {
|
||||
JsonObject result = sendMessage("httpVersion").getAsJsonObject();
|
||||
return result.get("value").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> headers() {
|
||||
return headers.headers();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.microsoft.playwright.ScreencastFrame;
|
||||
|
||||
class ScreencastFrameImpl implements ScreencastFrame {
|
||||
private final byte[] data;
|
||||
private final int viewportWidth;
|
||||
private final int viewportHeight;
|
||||
|
||||
ScreencastFrameImpl(byte[] data, int viewportWidth, int viewportHeight) {
|
||||
this.data = data;
|
||||
this.viewportWidth = viewportWidth;
|
||||
this.viewportHeight = viewportHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int viewportWidth() {
|
||||
return viewportWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int viewportHeight() {
|
||||
return viewportHeight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.Screencast;
|
||||
import com.microsoft.playwright.ScreencastFrame;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class ScreencastImpl implements Screencast {
|
||||
private final PageImpl page;
|
||||
private boolean started;
|
||||
private Path savePath;
|
||||
private Consumer<ScreencastFrame> onFrame;
|
||||
private ArtifactImpl artifact;
|
||||
|
||||
ScreencastImpl(PageImpl page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
void handleScreencastFrame(JsonObject params) {
|
||||
if (onFrame == null) {
|
||||
return;
|
||||
}
|
||||
String dataBase64 = params.get("data").getAsString();
|
||||
byte[] data = java.util.Base64.getDecoder().decode(dataBase64);
|
||||
int viewportWidth = params.get("viewportWidth").getAsInt();
|
||||
int viewportHeight = params.get("viewportHeight").getAsInt();
|
||||
onFrame.accept(new ScreencastFrameImpl(data, viewportWidth, viewportHeight));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoCloseable start(StartOptions options) {
|
||||
if (started) {
|
||||
throw new PlaywrightException("Screencast is already started");
|
||||
}
|
||||
started = true;
|
||||
JsonObject params = new JsonObject();
|
||||
if (options != null) {
|
||||
if (options.onFrame != null) {
|
||||
onFrame = options.onFrame;
|
||||
}
|
||||
if (options.quality != null) {
|
||||
params.addProperty("quality", options.quality);
|
||||
}
|
||||
params.addProperty("sendFrames", options.onFrame != null);
|
||||
params.addProperty("record", options.path != null);
|
||||
savePath = options.path;
|
||||
} else {
|
||||
params.addProperty("sendFrames", false);
|
||||
params.addProperty("record", false);
|
||||
}
|
||||
JsonObject result = page.sendMessage("screencastStart", params, NO_TIMEOUT).getAsJsonObject();
|
||||
if (result.has("artifact")) {
|
||||
String artifactGuid = result.getAsJsonObject("artifact").get("guid").getAsString();
|
||||
artifact = page.connection.getExistingObject(artifactGuid);
|
||||
}
|
||||
return new DisposableStub(this::stop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
started = false;
|
||||
onFrame = null;
|
||||
page.sendMessage("screencastStop", new JsonObject(), NO_TIMEOUT);
|
||||
if (savePath != null && artifact != null) {
|
||||
artifact.saveAs(savePath);
|
||||
}
|
||||
artifact = null;
|
||||
savePath = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoCloseable showOverlay(String html, ShowOverlayOptions options) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("html", html);
|
||||
if (options != null && options.duration != null) {
|
||||
params.addProperty("duration", options.duration);
|
||||
}
|
||||
JsonObject result = (JsonObject) page.sendMessage("screencastShowOverlay", params, NO_TIMEOUT);
|
||||
String id = result.get("id").getAsString();
|
||||
return () -> {
|
||||
JsonObject removeParams = new JsonObject();
|
||||
removeParams.addProperty("id", id);
|
||||
page.sendMessage("screencastRemoveOverlay", removeParams, NO_TIMEOUT);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showChapter(String title, ShowChapterOptions options) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("title", title);
|
||||
if (options != null) {
|
||||
if (options.description != null) {
|
||||
params.addProperty("description", options.description);
|
||||
}
|
||||
if (options.duration != null) {
|
||||
params.addProperty("duration", options.duration);
|
||||
}
|
||||
}
|
||||
page.sendMessage("screencastChapter", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoCloseable showActions(ShowActionsOptions options) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (options != null) {
|
||||
if (options.duration != null) {
|
||||
params.addProperty("duration", options.duration);
|
||||
}
|
||||
if (options.fontSize != null) {
|
||||
params.addProperty("fontSize", options.fontSize);
|
||||
}
|
||||
if (options.position != null) {
|
||||
params.add("position", gson().toJsonTree(options.position));
|
||||
}
|
||||
}
|
||||
page.sendMessage("screencastShowActions", params, NO_TIMEOUT);
|
||||
return new DisposableStub(this::hideActions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showOverlays() {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("visible", true);
|
||||
page.sendMessage("screencastSetOverlayVisible", params, NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideActions() {
|
||||
page.sendMessage("screencastHideActions", new JsonObject(), NO_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideOverlays() {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("visible", false);
|
||||
page.sendMessage("screencastSetOverlayVisible", params, NO_TIMEOUT);
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@ class Serialization {
|
||||
.registerTypeAdapter(ScreenshotCaret.class, new ToLowerCaseSerializer<ScreenshotCaret>())
|
||||
.registerTypeAdapter(ServiceWorkerPolicy.class, new ToLowerCaseAndDashSerializer<ServiceWorkerPolicy>())
|
||||
.registerTypeAdapter(MouseButton.class, new ToLowerCaseSerializer<MouseButton>())
|
||||
.registerTypeAdapter(ConsoleMessagesFilter.class, new ConsoleMessagesFilterSerializer())
|
||||
.registerTypeAdapter(AriaSnapshotMode.class, new ToLowerCaseSerializer<AriaSnapshotMode>())
|
||||
.registerTypeAdapter(LoadState.class, new ToLowerCaseSerializer<LoadState>())
|
||||
.registerTypeAdapter(WaitUntilState.class, new ToLowerCaseSerializer<WaitUntilState>())
|
||||
.registerTypeAdapter(WaitForSelectorState.class, new ToLowerCaseSerializer<WaitForSelectorState>())
|
||||
@@ -482,6 +484,17 @@ class Serialization {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConsoleMessagesFilterSerializer implements JsonSerializer<ConsoleMessagesFilter> {
|
||||
@Override
|
||||
public JsonElement serialize(ConsoleMessagesFilter src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
switch (src) {
|
||||
case ALL: return new JsonPrimitive("all");
|
||||
case SINCE_NAVIGATION: return new JsonPrimitive("since-navigation");
|
||||
default: throw new PlaywrightException("Unknown ConsoleMessagesFilter: " + src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ToLowerCaseAndDashSerializer<E extends Enum<E>> implements JsonSerializer<E> {
|
||||
@Override
|
||||
public JsonElement serialize(E src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
|
||||
@@ -18,10 +18,21 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.Tracing;
|
||||
import com.microsoft.playwright.options.HarContentPolicy;
|
||||
import com.microsoft.playwright.options.HarMode;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.addHarUrlFilter;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class TracingImpl extends ChannelOwner implements Tracing {
|
||||
@@ -29,6 +40,18 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
private Path tracesDir;
|
||||
private boolean isTracing;
|
||||
private String stacksId;
|
||||
private final Set<String> additionalSources = new HashSet<>();
|
||||
final Map<String, HarRecorder> harRecorders = new HashMap<>();
|
||||
|
||||
static class HarRecorder {
|
||||
final Path path;
|
||||
final HarContentPolicy contentPolicy;
|
||||
|
||||
HarRecorder(Path har, HarContentPolicy policy) {
|
||||
this.path = har;
|
||||
this.contentPolicy = policy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TracingImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
@@ -42,6 +65,9 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
}
|
||||
JsonObject params = new JsonObject();
|
||||
|
||||
List<String> capturedAdditionalSources = new ArrayList<>(additionalSources);
|
||||
additionalSources.clear();
|
||||
|
||||
// Not interested in artifacts.
|
||||
if (path == null) {
|
||||
params.addProperty("mode", "discard");
|
||||
@@ -57,7 +83,7 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
params.addProperty("mode", "entries");
|
||||
JsonObject json = sendMessage("tracingStopChunk", params, NO_TIMEOUT).getAsJsonObject();
|
||||
JsonArray entries = json.getAsJsonArray("entries");
|
||||
connection.localUtils.zip(path, entries, stacksId, false, includeSources);
|
||||
connection.localUtils.zip(path, entries, stacksId, false, includeSources, capturedAdditionalSources);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,7 +100,7 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
artifact.saveAs(path);
|
||||
artifact.delete();
|
||||
|
||||
connection.localUtils.zip(path, new JsonArray(), stacksId, true, includeSources);
|
||||
connection.localUtils.zip(path, new JsonArray(), stacksId, true, includeSources, capturedAdditionalSources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,14 +112,18 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void group(String name, GroupOptions options) {
|
||||
public AutoCloseable group(String name, GroupOptions options) {
|
||||
groupImpl(name, options);
|
||||
return new DisposableStub(this::groupEnd);
|
||||
}
|
||||
|
||||
private void groupImpl(String name, GroupOptions options) {
|
||||
if (options == null) {
|
||||
options = new GroupOptions();
|
||||
}
|
||||
if (options.location != null) {
|
||||
additionalSources.add(options.location.file);
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("name", name);
|
||||
sendMessage("tracingGroup", params, NO_TIMEOUT);
|
||||
@@ -149,6 +179,110 @@ class TracingImpl extends ChannelOwner implements Tracing {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
}
|
||||
|
||||
private String currentHarId;
|
||||
|
||||
@Override
|
||||
public AutoCloseable startHar(Path path, StartHarOptions options) {
|
||||
if (currentHarId != null) {
|
||||
throw new PlaywrightException("HAR recording has already been started");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new StartHarOptions();
|
||||
}
|
||||
boolean isZip = path.toString().endsWith(".zip");
|
||||
HarContentPolicy contentPolicy = options.content != null
|
||||
? options.content
|
||||
: (isZip ? HarContentPolicy.ATTACH : HarContentPolicy.EMBED);
|
||||
HarMode mode = options.mode != null ? options.mode : HarMode.FULL;
|
||||
currentHarId = recordIntoHar(null, path, options.urlFilter, contentPolicy, mode, null);
|
||||
return new DisposableStub(this::stopHar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopHar() {
|
||||
if (currentHarId == null) {
|
||||
throw new PlaywrightException("HAR recording has not been started");
|
||||
}
|
||||
String harId = currentHarId;
|
||||
currentHarId = null;
|
||||
exportHar(harId);
|
||||
}
|
||||
|
||||
String recordIntoHar(PageImpl page, Path har, Object urlFilter, HarContentPolicy contentPolicy, HarMode mode, Path resourcesDir) {
|
||||
if (contentPolicy == null) {
|
||||
contentPolicy = HarContentPolicy.ATTACH;
|
||||
}
|
||||
if (mode == null) {
|
||||
mode = HarMode.MINIMAL;
|
||||
}
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
if (page != null) {
|
||||
params.add("page", page.toProtocolRef());
|
||||
}
|
||||
JsonObject recordHarArgs = new JsonObject();
|
||||
recordHarArgs.addProperty("zip", har.toString().endsWith(".zip"));
|
||||
recordHarArgs.addProperty("content", contentPolicy.name().toLowerCase());
|
||||
recordHarArgs.addProperty("mode", mode.name().toLowerCase());
|
||||
addHarUrlFilter(recordHarArgs, urlFilter);
|
||||
if (resourcesDir != null) {
|
||||
recordHarArgs.addProperty("resourcesDir", resourcesDir.toString());
|
||||
}
|
||||
if (!har.toString().endsWith(".zip")) {
|
||||
recordHarArgs.addProperty("harPath", har.toString());
|
||||
}
|
||||
|
||||
params.add("options", recordHarArgs);
|
||||
JsonObject json = sendMessage("harStart", params, NO_TIMEOUT).getAsJsonObject();
|
||||
String harId = json.get("harId").getAsString();
|
||||
harRecorders.put(harId, new HarRecorder(har, contentPolicy));
|
||||
return harId;
|
||||
}
|
||||
|
||||
void exportHar(String harId) {
|
||||
HarRecorder harParams = harRecorders.remove(harId);
|
||||
if (harParams == null) {
|
||||
return;
|
||||
}
|
||||
boolean isLocal = !connection.isRemote;
|
||||
boolean isZip = harParams.path.toString().endsWith(".zip");
|
||||
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("harId", harId);
|
||||
if (isLocal) {
|
||||
params.addProperty("mode", "entries");
|
||||
JsonObject json = sendMessage("harExport", params, NO_TIMEOUT).getAsJsonObject();
|
||||
if (!isZip) {
|
||||
return;
|
||||
}
|
||||
JsonArray entries = json.getAsJsonArray("entries");
|
||||
connection.localUtils.zip(harParams.path, entries, null, false, false, java.util.Collections.emptyList());
|
||||
return;
|
||||
}
|
||||
|
||||
params.addProperty("mode", "archive");
|
||||
JsonObject json = sendMessage("harExport", params, NO_TIMEOUT).getAsJsonObject();
|
||||
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject("artifact").get("guid").getAsString());
|
||||
if (isZip) {
|
||||
artifact.saveAs(harParams.path);
|
||||
artifact.delete();
|
||||
return;
|
||||
}
|
||||
String tmpPath = harParams.path + ".tmp";
|
||||
artifact.saveAs(Paths.get(tmpPath));
|
||||
JsonObject unzipParams = new JsonObject();
|
||||
unzipParams.addProperty("zipFile", tmpPath);
|
||||
unzipParams.addProperty("harFile", harParams.path.toString());
|
||||
connection.localUtils.sendMessage("harUnzip", unzipParams, NO_TIMEOUT);
|
||||
artifact.delete();
|
||||
}
|
||||
|
||||
void exportAllHars() {
|
||||
for (String harId : new ArrayList<>(harRecorders.keySet())) {
|
||||
exportHar(harId);
|
||||
}
|
||||
}
|
||||
|
||||
void setTracesDir(Path tracesDir) {
|
||||
this.tracesDir = tracesDir;
|
||||
}
|
||||
|
||||
@@ -22,31 +22,23 @@ import com.microsoft.playwright.Video;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
class VideoImpl implements Video {
|
||||
private final PageImpl page;
|
||||
private final WaitableResult<ArtifactImpl> waitableArtifact = new WaitableResult<>();
|
||||
ArtifactImpl artifact;
|
||||
|
||||
VideoImpl(PageImpl page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
void setArtifact(ArtifactImpl artifact) {
|
||||
waitableArtifact.complete(artifact);
|
||||
}
|
||||
|
||||
private ArtifactImpl waitForArtifact() {
|
||||
Waitable<ArtifactImpl> waitable = new WaitableRace<>(asList(waitableArtifact, (Waitable<ArtifactImpl>) page.waitableClosedOrCrashed));
|
||||
return page.runUntil(() -> {}, waitable);
|
||||
VideoImpl(PageImpl page, ArtifactImpl artifact) {
|
||||
this.page = page;
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
try {
|
||||
waitForArtifact().delete();
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
if (artifact != null)
|
||||
artifact.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,22 +46,15 @@ class VideoImpl implements Video {
|
||||
if (page.connection.isRemote) {
|
||||
throw new PlaywrightException("Path is not available when using browserType.connect(). Use saveAs() to save a local copy.");
|
||||
}
|
||||
try {
|
||||
return Paths.get(waitForArtifact().initializer.get("absolutePath").getAsString());
|
||||
} catch (PlaywrightException e) {
|
||||
throw new PlaywrightException("Page did not produce any video frames", e);
|
||||
}
|
||||
if (artifact == null)
|
||||
throw new PlaywrightException("Video recording has not been started.");
|
||||
return Paths.get(artifact.initializer.get("absolutePath").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAs(Path path) {
|
||||
if (!page.isClosed()) {
|
||||
throw new PlaywrightException("Page is not yet closed. Close the page prior to calling saveAs");
|
||||
}
|
||||
try {
|
||||
waitForArtifact().saveAs(path);
|
||||
} catch (PlaywrightException e) {
|
||||
throw new PlaywrightException("Page did not produce any video frames", e);
|
||||
}
|
||||
if (artifact == null)
|
||||
throw new PlaywrightException("Video recording has not been started.");
|
||||
artifact.saveAs(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,17 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.WebError;
|
||||
import com.microsoft.playwright.options.WebErrorLocation;
|
||||
|
||||
public class WebErrorImpl implements WebError {
|
||||
private final PageImpl page;
|
||||
private final String error;
|
||||
private final WebErrorLocation location;
|
||||
|
||||
WebErrorImpl(PageImpl page, String error) {
|
||||
WebErrorImpl(PageImpl page, String error, WebErrorLocation location) {
|
||||
this.page = page;
|
||||
this.error = error;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,4 +39,9 @@ public class WebErrorImpl implements WebError {
|
||||
public String error() {
|
||||
return error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebErrorLocation location() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.WebSocketFrame;
|
||||
import com.microsoft.playwright.WebSocketRoute;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -65,6 +68,11 @@ class WebSocketRouteImpl extends ChannelOwner implements WebSocketRoute {
|
||||
public String url() {
|
||||
return initializer.get("url").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> protocols() {
|
||||
return readProtocols();
|
||||
}
|
||||
};
|
||||
|
||||
WebSocketRouteImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
@@ -123,6 +131,22 @@ class WebSocketRouteImpl extends ChannelOwner implements WebSocketRoute {
|
||||
return initializer.get("url").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> protocols() {
|
||||
return readProtocols();
|
||||
}
|
||||
|
||||
private List<String> readProtocols() {
|
||||
List<String> result = new ArrayList<>();
|
||||
if (!initializer.has("protocols")) {
|
||||
return result;
|
||||
}
|
||||
for (JsonElement element : initializer.getAsJsonArray("protocols")) {
|
||||
result.add(element.getAsString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void afterHandle() {
|
||||
if (this.connected) {
|
||||
return;
|
||||
@@ -160,9 +184,9 @@ class WebSocketRouteImpl extends ChannelOwner implements WebSocketRoute {
|
||||
sendMessageAsync("sendToPage", messageParams);
|
||||
}
|
||||
} else if ("closePage".equals(event)) {
|
||||
int code = params.get("code").getAsInt();
|
||||
String reason = params.get("reason").getAsString();
|
||||
boolean wasClean = params.get("wasClean").getAsBoolean();
|
||||
Integer code = params.has("code") ? params.get("code").getAsInt() : null;
|
||||
String reason = params.has("reason") ? params.get("reason").getAsString() : null;
|
||||
boolean wasClean = params.has("wasClean") && params.get("wasClean").getAsBoolean();
|
||||
if (onPageClose != null) {
|
||||
onPageClose.accept(code, reason);
|
||||
} else {
|
||||
@@ -173,9 +197,9 @@ class WebSocketRouteImpl extends ChannelOwner implements WebSocketRoute {
|
||||
sendMessageAsync("closeServer", closeParams);
|
||||
}
|
||||
} else if ("closeServer".equals(event)) {
|
||||
int code = params.get("code").getAsInt();
|
||||
String reason = params.get("reason").getAsString();
|
||||
boolean wasClean = params.get("wasClean").getAsBoolean();
|
||||
Integer code = params.has("code") ? params.get("code").getAsInt() : null;
|
||||
String reason = params.has("reason") ? params.get("reason").getAsString() : null;
|
||||
boolean wasClean = params.has("wasClean") && params.get("wasClean").getAsBoolean();
|
||||
if (onServerClose != null) {
|
||||
onServerClose.accept(code, reason);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 class Annotate {
|
||||
/**
|
||||
* How long each annotation is displayed in milliseconds. Defaults to {@code 500}.
|
||||
*/
|
||||
public Double duration;
|
||||
/**
|
||||
* Position of the action title overlay. Defaults to {@code "top-right"}.
|
||||
*/
|
||||
public AnnotatePosition position;
|
||||
/**
|
||||
* Font size of the action title in pixels. Defaults to {@code 24}.
|
||||
*/
|
||||
public Integer fontSize;
|
||||
|
||||
/**
|
||||
* How long each annotation is displayed in milliseconds. Defaults to {@code 500}.
|
||||
*/
|
||||
public Annotate setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Position of the action title overlay. Defaults to {@code "top-right"}.
|
||||
*/
|
||||
public Annotate setPosition(AnnotatePosition position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Font size of the action title in pixels. Defaults to {@code 24}.
|
||||
*/
|
||||
public Annotate setFontSize(int fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 AnnotatePosition {
|
||||
TOP_LEFT,
|
||||
TOP,
|
||||
TOP_RIGHT,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM,
|
||||
BOTTOM_RIGHT
|
||||
}
|
||||
@@ -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 AriaSnapshotMode {
|
||||
AI,
|
||||
DEFAULT
|
||||
}
|
||||
@@ -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 class BindResult {
|
||||
public String endpoint;
|
||||
|
||||
}
|
||||
@@ -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 ConsoleMessagesFilter {
|
||||
ALL,
|
||||
SINCE_NAVIGATION
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 class DebuggerPausedDetails {
|
||||
public Location location;
|
||||
public String title;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.util.Map;
|
||||
|
||||
public class DropPayload {
|
||||
public Object files;
|
||||
public Map<String, String> data;
|
||||
|
||||
public DropPayload setFiles(Object files) {
|
||||
this.files = files;
|
||||
return this;
|
||||
}
|
||||
public DropPayload setData(Map<String, String> data) {
|
||||
this.data = data;
|
||||
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 PseudoElement {
|
||||
BEFORE,
|
||||
AFTER
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 class Size {
|
||||
/**
|
||||
* Video frame width.
|
||||
*/
|
||||
public int width;
|
||||
/**
|
||||
* Video frame height.
|
||||
*/
|
||||
public int height;
|
||||
|
||||
public Size(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 class WebErrorLocation {
|
||||
/**
|
||||
* URL of the resource.
|
||||
*/
|
||||
public String url;
|
||||
/**
|
||||
* 0-based line number in the resource.
|
||||
*/
|
||||
public int line;
|
||||
/**
|
||||
* 0-based column number in the resource.
|
||||
*/
|
||||
public int column;
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
|
||||
@@ -30,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
@Tag("smoke")
|
||||
public class TestBrowser1 {
|
||||
|
||||
@Test
|
||||
@@ -113,4 +115,13 @@ public class TestBrowser1 {
|
||||
assertTrue(e.getMessage().contains("The reason."), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFireContextEvent(Browser browser) {
|
||||
BrowserContext[] contextEvent = { null };
|
||||
browser.onContext(c -> contextEvent[0] = c);
|
||||
BrowserContext context = browser.newContext();
|
||||
assertEquals(context, contextEvent[0]);
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.BindResult;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBrowserBind extends TestBase {
|
||||
@Test
|
||||
void shouldBindAndUnbindBrowser() {
|
||||
BindResult serverInfo = browser.bind("default");
|
||||
try {
|
||||
assertNotNull(serverInfo);
|
||||
assertNotNull(serverInfo.endpoint);
|
||||
assertFalse(serverInfo.endpoint.isEmpty());
|
||||
} finally {
|
||||
browser.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBindWithCustomTitleAndOptions() {
|
||||
BindResult serverInfo = browser.bind("my-title",
|
||||
new Browser.BindOptions().setHost("127.0.0.1").setPort(0));
|
||||
try {
|
||||
assertNotNull(serverInfo);
|
||||
assertNotNull(serverInfo.endpoint);
|
||||
assertFalse(serverInfo.endpoint.isEmpty());
|
||||
} finally {
|
||||
browser.unbind();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
@@ -32,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
@Tag("smoke")
|
||||
public class TestBrowserContextBasic {
|
||||
@Test
|
||||
void shouldCreateNewContext(Browser browser) {
|
||||
|
||||
@@ -155,6 +155,26 @@ public class TestBrowserContextCDPSession extends TestBase {
|
||||
assertEquals(2, events.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldEmitEventForEachCDPEvent() {
|
||||
CDPSession client = page.context().newCDPSession(page);
|
||||
client.send("Network.enable");
|
||||
List<JsonObject> events = new ArrayList<>();
|
||||
client.on("event", events::add);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertTrue(events.size() > 0);
|
||||
JsonObject requestEvent = null;
|
||||
for (JsonObject e : events) {
|
||||
if ("Network.requestWillBeSent".equals(e.get("method").getAsString())) {
|
||||
requestEvent = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(requestEvent);
|
||||
assertEquals(server.EMPTY_PAGE,
|
||||
requestEvent.getAsJsonObject("params").getAsJsonObject("request").get("url").getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRemoveEventListeners() {
|
||||
CDPSession cdpSession = page.context().newCDPSession(page);
|
||||
|
||||
@@ -186,4 +186,90 @@ public class TestBrowserContextEvents extends TestBase {
|
||||
assertTrue(webError[0].error().contains("boom"), webError[0].error());
|
||||
}
|
||||
|
||||
@Test
|
||||
void weberrorEventShouldIncludeLocation() {
|
||||
server.setRoute("/error.js", exchange -> {
|
||||
exchange.getResponseHeaders().add("content-type", "application/javascript");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("\nfunction foo() {\n throw new Error('boom');\n}\nfoo();\n");
|
||||
}
|
||||
});
|
||||
server.setRoute("/error.html", exchange -> {
|
||||
exchange.getResponseHeaders().add("content-type", "text/html");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("<script src=\"/error.js\"></script>");
|
||||
}
|
||||
});
|
||||
WebError[] webError = { null };
|
||||
context.onWebError(e -> webError[0] = e);
|
||||
page.navigate(server.PREFIX + "/error.html");
|
||||
waitForCondition(() -> webError[0] != null);
|
||||
com.microsoft.playwright.options.WebErrorLocation location = webError[0].location();
|
||||
assertEquals(server.PREFIX + "/error.js", location.url);
|
||||
assertEquals(2, location.line);
|
||||
assertTrue(location.column > 0, "expected column > 0, got " + location.column);
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageLoadEventShouldWork() {
|
||||
Page[] loaded = { null };
|
||||
context.onPageLoad(p -> loaded[0] = p);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
waitForCondition(() -> loaded[0] != null);
|
||||
assertEquals(page, loaded[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void frameNavigatedEventShouldWork() {
|
||||
Frame[] navigated = { null };
|
||||
context.onFrameNavigated(f -> navigated[0] = f);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
waitForCondition(() -> navigated[0] != null);
|
||||
assertEquals(page.mainFrame(), navigated[0]);
|
||||
assertEquals(server.EMPTY_PAGE, navigated[0].url());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageCloseEventShouldWork() {
|
||||
Page newPage = context.newPage();
|
||||
Page[] closed = { null };
|
||||
context.onPageClose(p -> closed[0] = p);
|
||||
newPage.close();
|
||||
waitForCondition(() -> closed[0] != null);
|
||||
assertEquals(newPage, closed[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void frameAttachedEventShouldWork() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
Frame[] attached = { null };
|
||||
context.onFrameAttached(f -> attached[0] = f);
|
||||
page.evaluate("() => {\n" +
|
||||
" const iframe = document.createElement('iframe');\n" +
|
||||
" iframe.src = 'about:blank';\n" +
|
||||
" document.body.appendChild(iframe);\n" +
|
||||
"}");
|
||||
waitForCondition(() -> attached[0] != null);
|
||||
assertEquals(page.mainFrame(), attached[0].parentFrame());
|
||||
}
|
||||
|
||||
@Test
|
||||
void frameDetachedEventShouldWork() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("() => {\n" +
|
||||
" const iframe = document.createElement('iframe');\n" +
|
||||
" iframe.id = 'x';\n" +
|
||||
" iframe.src = 'about:blank';\n" +
|
||||
" document.body.appendChild(iframe);\n" +
|
||||
"}");
|
||||
page.waitForSelector("iframe");
|
||||
Frame[] detached = { null };
|
||||
context.onFrameDetached(f -> detached[0] = f);
|
||||
page.evaluate("() => document.getElementById('x').remove()");
|
||||
waitForCondition(() -> detached[0] != null);
|
||||
assertEquals(page.mainFrame(), detached[0].parentFrame());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-15
@@ -84,19 +84,4 @@ public class TestBrowserContextExposeFunction extends TestBase {
|
||||
assertEquals(asList("context", "page"), actualArgs);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposeBindingHandleShouldWork() {
|
||||
JSHandle[] target = { null };
|
||||
context.exposeBinding("logme", (source, args) -> {
|
||||
target[0] = (JSHandle) args[0];
|
||||
return 17;
|
||||
}, new BrowserContext.ExposeBindingOptions().setHandle(true));
|
||||
Page page = context.newPage();
|
||||
Object result = page.evaluate("async function() {\n" +
|
||||
" return window['logme']({ foo: 42 });\n" +
|
||||
"}");
|
||||
assertNotNull(target[0]);
|
||||
assertEquals(42, target[0].evaluate("x => x.foo"));
|
||||
assertEquals(17, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import static com.microsoft.playwright.Utils.assertJsonEquals;
|
||||
import static com.microsoft.playwright.Utils.mapOf;
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestBrowserContextStorageState extends TestBase {
|
||||
|
||||
@@ -276,4 +277,12 @@ public class TestBrowserContextStorageState extends TestBase {
|
||||
assertEquals("{\"cookies\":[],\"origins\":[]}", context.storageState(
|
||||
new BrowserContext.StorageStateOptions().setIndexedDB(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void setStorageStateShouldHandleMissingFile(@TempDir Path tempDir) {
|
||||
Path file = tempDir.resolve("does-not-exist.json");
|
||||
PlaywrightException e = org.junit.jupiter.api.Assertions.assertThrows(
|
||||
PlaywrightException.class, () -> context.setStorageState(file));
|
||||
assertTrue(e.getMessage().contains("Failed to read storage state from file"), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,9 +355,8 @@ public class TestClick extends TestBase {
|
||||
page.evalOnSelector("button", "button => button.style.borderWidth = '8px'");
|
||||
page.click("button", new Page.ClickOptions().setPosition(20, 10));
|
||||
assertEquals(page.evaluate("result"), "Clicked");
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit() ? 20 + 8 : 20, page.evaluate("offsetX"));
|
||||
assertEquals(isWebKit() ? 10 + 8 : 10, page.evaluate("offsetY"));
|
||||
assertEquals(20, page.evaluate("offsetX"));
|
||||
assertEquals(10, page.evaluate("offsetY"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,9 +366,8 @@ public class TestClick extends TestBase {
|
||||
page.evalOnSelector("button", "button => button.style.fontSize = '12px'");
|
||||
page.click("button", new Page.ClickOptions().setPosition(20, 10));
|
||||
assertEquals("Clicked", page.evaluate("result"));
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit() ? 12 * 2 + 20 : 20, page.evaluate("offsetX"));
|
||||
assertEquals(isWebKit() ? 12 * 2 + 10 : 10, page.evaluate("offsetY"));
|
||||
assertEquals(20, page.evaluate("offsetX"));
|
||||
assertEquals(10, page.evaluate("offsetY"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -379,9 +377,8 @@ public class TestClick extends TestBase {
|
||||
page.evalOnSelector("button", "button => button.style.height = button.style.width = '2000px'");
|
||||
page.click("button", new Page.ClickOptions().setPosition(1900, 1910));
|
||||
assertEquals("Clicked", page.evaluate("() => window['result']"));
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit() ? 1900 + 8 : 1900, page.evaluate("offsetX"));
|
||||
assertEquals(isWebKit() ? 1910 + 8 : 1910, page.evaluate("offsetY"));
|
||||
assertEquals(1900, page.evaluate("offsetX"));
|
||||
assertEquals(1910, page.evaluate("offsetY"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -400,9 +397,8 @@ public class TestClick extends TestBase {
|
||||
"}");
|
||||
page.click("button", new Page.ClickOptions().setPosition(1900, 1910));
|
||||
assertEquals("Clicked", page.evaluate("() => window['result']"));
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit() ? 1900 + 8 : 1900, page.evaluate("offsetX"));
|
||||
assertEquals(isWebKit() ? 1910 + 8 : 1910, page.evaluate("offsetY"));
|
||||
assertEquals(1900, page.evaluate("offsetX"));
|
||||
assertEquals(1910, page.evaluate("offsetY"));
|
||||
}
|
||||
|
||||
private static void expectCloseTo(double expected, double actual) {
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.DebuggerPausedDetails;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestDebugger extends TestBase {
|
||||
@Test
|
||||
void shouldReturnNullPausedDetailsInitially() {
|
||||
Debugger dbg = context.debugger();
|
||||
assertNull(dbg.pausedDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPauseAtNextAndResume() {
|
||||
page.setContent("<div>click me</div>");
|
||||
Debugger dbg = context.debugger();
|
||||
assertNull(dbg.pausedDetails());
|
||||
|
||||
dbg.requestPause();
|
||||
|
||||
boolean[] paused = {false};
|
||||
dbg.onPausedStateChanged(() -> {
|
||||
if (!paused[0]) {
|
||||
paused[0] = true;
|
||||
DebuggerPausedDetails details = dbg.pausedDetails();
|
||||
assertNotNull(details);
|
||||
assertTrue(details.title.contains("Click"), "title: " + details.title);
|
||||
dbg.resume();
|
||||
}
|
||||
});
|
||||
|
||||
page.click("div"); // blocks until dbg.resume() is called
|
||||
assertNull(dbg.pausedDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldStepWithNext() {
|
||||
page.setContent("<div>click me</div>");
|
||||
Debugger dbg = context.debugger();
|
||||
assertNull(dbg.pausedDetails());
|
||||
|
||||
dbg.requestPause();
|
||||
|
||||
boolean[] paused = {false};
|
||||
dbg.onPausedStateChanged(() -> {
|
||||
if (!paused[0]) {
|
||||
paused[0] = true;
|
||||
DebuggerPausedDetails details = dbg.pausedDetails();
|
||||
assertNotNull(details);
|
||||
assertTrue(details.title.contains("Click"), "title: " + details.title);
|
||||
dbg.next();
|
||||
} else if (dbg.pausedDetails() != null) {
|
||||
dbg.resume();
|
||||
}
|
||||
});
|
||||
|
||||
page.click("div");
|
||||
assertNull(dbg.pausedDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPauseAtPauseCall() {
|
||||
page.setContent("<div>click me</div>");
|
||||
Debugger dbg = context.debugger();
|
||||
assertNull(dbg.pausedDetails());
|
||||
|
||||
dbg.requestPause();
|
||||
|
||||
boolean[] paused = {false};
|
||||
dbg.onPausedStateChanged(() -> {
|
||||
if (!paused[0]) {
|
||||
paused[0] = true;
|
||||
DebuggerPausedDetails details = dbg.pausedDetails();
|
||||
assertNotNull(details);
|
||||
assertTrue(details.title.contains("Pause"), "title: " + details.title);
|
||||
dbg.resume();
|
||||
}
|
||||
});
|
||||
|
||||
page.pause(); // blocks until dbg.resume() is called from event handler
|
||||
assertNull(dbg.pausedDetails());
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class TestDefaultBrowserContext2 extends TestBase {
|
||||
@TempDir Path tempDir;
|
||||
|
||||
@AfterEach
|
||||
private void closePersistentContext() {
|
||||
void closePersistentContext() {
|
||||
if (persistentContext != null) {
|
||||
persistentContext.close();
|
||||
persistentContext = null;
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.KeyboardModifier;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@Tag("smoke")
|
||||
public class TestLocatorClick extends TestBase {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,4 +36,18 @@ public class TestLocatorHighlight extends TestBase {
|
||||
BoundingBox box2 = page.locator("x-pw-highlight").boundingBox();
|
||||
assertEquals(new Gson().toJson(box2), new Gson().toJson(box1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void highlightAndHideHighlightShouldNotThrow() {
|
||||
page.setContent("<input type='text' />");
|
||||
AutoCloseable disposable = page.locator("input").highlight(new Locator.HighlightOptions().setStyle("outline: 2px dashed red"));
|
||||
try {
|
||||
disposable.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
page.locator("input").highlight();
|
||||
page.locator("input").hideHighlight();
|
||||
page.hideHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,4 +136,219 @@ public class TestPageAriaSnapshot {
|
||||
" - /url: /auth?r=/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSnapshotIntegration(Page page) {
|
||||
page.setContent(
|
||||
"<h1>Microsoft</h1>" +
|
||||
"<div>Open source projects and samples from Microsoft</div>" +
|
||||
"<ul>" +
|
||||
"<li><details><summary>Verified</summary><div><div>" +
|
||||
"<p>We've verified that the organization <strong>microsoft</strong> controls the domain:</p>" +
|
||||
"<ul><li class=\"mb-1\"><strong>opensource.microsoft.com</strong></li></ul>" +
|
||||
"<div><a href=\"about: blank\">Learn more about verified organizations</a></div>" +
|
||||
"</div></div></details></li>" +
|
||||
"<li><a href=\"about:blank\"><summary title=\"Label: GitHub Sponsor\">Sponsor</summary></a></li>" +
|
||||
"</ul>");
|
||||
checkAndMatchSnapshot(page.locator("body"),
|
||||
"- heading \"Microsoft\" [level=1]\n" +
|
||||
"- text: Open source projects and samples from Microsoft\n" +
|
||||
"- list:\n" +
|
||||
" - listitem:\n" +
|
||||
" - group: Verified\n" +
|
||||
" - listitem:\n" +
|
||||
" - link \"Sponsor\":\n" +
|
||||
" - /url: about:blank");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupportMultilineText(Page page) {
|
||||
page.setContent("<p>\n Line 1\n Line 2\n Line 3\n </p>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- paragraph: Line 1 Line 2 Line 3");
|
||||
assertThat(page.locator("body")).matchesAriaSnapshot(
|
||||
" - paragraph: |\n" +
|
||||
" Line 1\n" +
|
||||
" Line 2\n" +
|
||||
" Line 3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConcatenateSpanText(Page page) {
|
||||
page.setContent("<span>One</span> <span>Two</span> <span>Three</span>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- text: One Two Three");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConcatenateSpanText2(Page page) {
|
||||
page.setContent("<span>One </span><span>Two </span><span>Three</span>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- text: One Two Three");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConcatenateDivTextWithSpaces(Page page) {
|
||||
page.setContent("<div>One</div><div>Two</div><div>Three</div>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- text: One Two Three");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIncludePseudoInText(Page page) {
|
||||
page.setContent(
|
||||
"<style>span:before { content: 'world'; } div:after { content: 'bye'; }</style>" +
|
||||
"<a href=\"about:blank\"><span>hello</span><div>hello</div></a>");
|
||||
checkAndMatchSnapshot(page.locator("body"),
|
||||
"- link \"worldhello hellobye\":\n" +
|
||||
" - /url: about:blank");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotIncludeHiddenPseudoInText(Page page) {
|
||||
page.setContent(
|
||||
"<style>span:before { content: 'world'; display: none; } div:after { content: 'bye'; visibility: hidden; }</style>" +
|
||||
"<a href=\"about:blank\"><span>hello</span><div>hello</div></a>");
|
||||
checkAndMatchSnapshot(page.locator("body"),
|
||||
"- link \"hello hello\":\n" +
|
||||
" - /url: about:blank");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIncludeNewLineForBlockPseudo(Page page) {
|
||||
page.setContent(
|
||||
"<style>span:before { content: 'world'; display: block; } div:after { content: 'bye'; display: block; }</style>" +
|
||||
"<a href=\"about:blank\"><span>hello</span><div>hello</div></a>");
|
||||
checkAndMatchSnapshot(page.locator("body"),
|
||||
"- link \"world hello hello bye\":\n" +
|
||||
" - /url: about:blank");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithSlots(Page page) {
|
||||
// Text "foo" is assigned to the slot, should not be used twice.
|
||||
page.setContent(
|
||||
"<button><div>foo</div></button>" +
|
||||
"<script>(() => {" +
|
||||
" const container = document.querySelector('div');" +
|
||||
" const shadow = container.attachShadow({ mode: 'open' });" +
|
||||
" const slot = document.createElement('slot');" +
|
||||
" shadow.appendChild(slot);" +
|
||||
"})()</script>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- button \"foo\"");
|
||||
|
||||
// Text "foo" is assigned to the slot, should be used instead of slot content.
|
||||
page.setContent(
|
||||
"<div>foo</div>" +
|
||||
"<script>(() => {" +
|
||||
" const container = document.querySelector('div');" +
|
||||
" const shadow = container.attachShadow({ mode: 'open' });" +
|
||||
" const button = document.createElement('button');" +
|
||||
" shadow.appendChild(button);" +
|
||||
" const slot = document.createElement('slot');" +
|
||||
" button.appendChild(slot);" +
|
||||
" const span = document.createElement('span');" +
|
||||
" span.textContent = 'pre';" +
|
||||
" slot.appendChild(span);" +
|
||||
"})()</script>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- button \"foo\"");
|
||||
|
||||
// Nothing is assigned to the slot, should use slot content.
|
||||
page.setContent(
|
||||
"<div></div>" +
|
||||
"<script>(() => {" +
|
||||
" const container = document.querySelector('div');" +
|
||||
" const shadow = container.attachShadow({ mode: 'open' });" +
|
||||
" const button = document.createElement('button');" +
|
||||
" shadow.appendChild(button);" +
|
||||
" const slot = document.createElement('slot');" +
|
||||
" button.appendChild(slot);" +
|
||||
" const span = document.createElement('span');" +
|
||||
" span.textContent = 'pre';" +
|
||||
" slot.appendChild(span);" +
|
||||
"})()</script>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- button \"pre\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSnapshotInnerText(Page page) {
|
||||
page.setContent(
|
||||
"<div role=\"listitem\"><div><div><span title=\"a.test.ts\">a.test.ts</span></div>" +
|
||||
"<div><button title=\"Run\"></button><button title=\"Show source\"></button><button title=\"Watch\"></button></div></div></div>" +
|
||||
"<div role=\"listitem\"><div><div><span title=\"snapshot\">snapshot</span></div>" +
|
||||
"<div class=\"ui-mode-list-item-time\">30ms</div>" +
|
||||
"<div><button title=\"Run\"></button><button title=\"Show source\"></button><button title=\"Watch\"></button></div></div></div>");
|
||||
checkAndMatchSnapshot(page.locator("body"),
|
||||
" - listitem:\n" +
|
||||
" - text: a.test.ts\n" +
|
||||
" - button \"Run\"\n" +
|
||||
" - button \"Show source\"\n" +
|
||||
" - button \"Watch\"\n" +
|
||||
" - listitem:\n" +
|
||||
" - text: snapshot 30ms\n" +
|
||||
" - button \"Run\"\n" +
|
||||
" - button \"Show source\"\n" +
|
||||
" - button \"Watch\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkAriaHiddenText(Page page) {
|
||||
page.setContent("<p><span>hello</span><span aria-hidden=\"true\">world</span></p>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- paragraph: hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIgnorePresentationAndNoneRoles(Page page) {
|
||||
page.setContent("<ul><li role=\"presentation\">hello</li><li role=\"none\">world</li></ul>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- list: hello world");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotUseOnAsCheckboxValue(Page page) {
|
||||
page.setContent("<input type=\"checkbox\"><input type=\"radio\">");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- checkbox\n- radio");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotReportTextareaTextContent(Page page) {
|
||||
page.setContent("<textarea>Before</textarea>");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- textbox: Before");
|
||||
page.evaluate("document.querySelector('textarea').value = 'After'");
|
||||
checkAndMatchSnapshot(page.locator("body"), "- textbox: After");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotShowVisibleChildrenOfHiddenElements(Page page) {
|
||||
page.setContent(
|
||||
"<div style=\"visibility: hidden;\">" +
|
||||
"<div style=\"visibility: visible;\"><button>Button</button></div>" +
|
||||
"</div>");
|
||||
assertEquals("", page.locator("body").ariaSnapshot());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotShowUnhiddenChildrenOfAriaHiddenElements(Page page) {
|
||||
page.setContent(
|
||||
"<div aria-hidden=\"true\">" +
|
||||
"<div aria-hidden=\"false\"><button>Button</button></div>" +
|
||||
"</div>");
|
||||
assertEquals("", page.locator("body").ariaSnapshot());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSnapshotPlaceholderWhenDifferentFromName(Page page) {
|
||||
page.setContent("<input placeholder=\"Placeholder\">");
|
||||
assertThat(page.locator("body")).matchesAriaSnapshot("- textbox \"Placeholder\"");
|
||||
|
||||
page.setContent("<input placeholder=\"Placeholder\" aria-label=\"Label\">");
|
||||
assertThat(page.locator("body")).matchesAriaSnapshot(
|
||||
"- textbox \"Label\":\n" +
|
||||
" - /placeholder: Placeholder");
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageMatchesAriaSnapshot(Page page) {
|
||||
page.setContent("<h1>hello</h1>");
|
||||
assertThat(page).matchesAriaSnapshot("- heading \"hello\" [level=1]");
|
||||
AssertionFailedError e = assertThrows(AssertionFailedError.class,
|
||||
() -> assertThat(page).matchesAriaSnapshot("- heading \"world\"",
|
||||
new com.microsoft.playwright.assertions.PageAssertions.MatchesAriaSnapshotOptions().setTimeout(1000)));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(e.getMessage().contains("Page expected to match Aria snapshot"), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import com.microsoft.playwright.options.AriaSnapshotMode;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@FixtureTest
|
||||
@UsePlaywright
|
||||
public class TestPageAriaSnapshotAI {
|
||||
private static String aiSnapshot(Page page) {
|
||||
return page.ariaSnapshot(new Page.AriaSnapshotOptions().setMode(AriaSnapshotMode.AI));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldGenerateRefs(Page page) {
|
||||
page.setContent("<button>One</button><button>Two</button><button>Three</button>");
|
||||
|
||||
String snapshot1 = aiSnapshot(page);
|
||||
assertTrue(snapshot1.contains("button \"One\" [ref=e2]"), snapshot1);
|
||||
assertTrue(snapshot1.contains("button \"Two\" [ref=e3]"), snapshot1);
|
||||
assertTrue(snapshot1.contains("button \"Three\" [ref=e4]"), snapshot1);
|
||||
assertThat(page.locator("aria-ref=e2")).hasText("One");
|
||||
assertThat(page.locator("aria-ref=e3")).hasText("Two");
|
||||
assertThat(page.locator("aria-ref=e4")).hasText("Three");
|
||||
|
||||
page.locator("aria-ref=e3").evaluate("e => e.textContent = 'Not Two'");
|
||||
|
||||
String snapshot2 = aiSnapshot(page);
|
||||
assertTrue(snapshot2.contains("button \"One\" [ref=e2]"), snapshot2);
|
||||
assertTrue(snapshot2.contains("button \"Not Two\" [ref=e5]"), snapshot2);
|
||||
assertTrue(snapshot2.contains("button \"Three\" [ref=e4]"), snapshot2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldListIframes(Page page) {
|
||||
page.setContent(
|
||||
"<h1>Hello</h1>" +
|
||||
"<iframe name=\"foo\" src=\"data:text/html,<h1>World</h1>\">");
|
||||
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("- iframe"), snapshot);
|
||||
|
||||
String frameSnapshot = page.frameLocator("iframe").locator("body").ariaSnapshot();
|
||||
assertEquals("- heading \"World\" [level=1]", frameSnapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSnapshotLocatorInsideIframe(Page page) {
|
||||
page.setContent(
|
||||
"<h1>Main Page</h1>" +
|
||||
"<iframe srcdoc=\"<ul><li>Item 1</li><li>Item 2</li></ul>\"></iframe>");
|
||||
|
||||
Locator list = page.frames().get(1).locator("ul");
|
||||
String snapshot = list.ariaSnapshot(new Locator.AriaSnapshotOptions().setMode(AriaSnapshotMode.AI));
|
||||
assertTrue(snapshot.contains("list [ref=f1e1]"), snapshot);
|
||||
assertTrue(snapshot.contains("listitem [ref=f1e2]: Item 1"), snapshot);
|
||||
assertTrue(snapshot.contains("listitem [ref=f1e3]: Item 2"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCollapseGenericNodes(Page page) {
|
||||
page.setContent("<div><div><div><button>Button</button></div></div></div>");
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("button \"Button\" [ref=e5]"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIncludeCursorPointerHint(Page page) {
|
||||
page.setContent("<button style=\"cursor: pointer\">Button</button>");
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("button \"Button\" [ref=e2] [cursor=pointer]"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotNestCursorPointerHints(Page page) {
|
||||
page.setContent(
|
||||
"<a style=\"cursor: pointer\" href=\"about:blank\">" +
|
||||
"Link with a button <button style=\"cursor: pointer\">Button</button>" +
|
||||
"</a>");
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("link \"Link with a button Button\" [ref=e2] [cursor=pointer]"), snapshot);
|
||||
// The button inside a cursor-pointer link should not get a redundant [cursor=pointer]
|
||||
assertTrue(snapshot.contains("button \"Button\" [ref=e3]"), snapshot);
|
||||
assertFalse(snapshot.contains("button \"Button\" [ref=e3] [cursor=pointer]"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldShowVisibleChildrenOfHiddenElements(Page page) {
|
||||
page.setContent(
|
||||
"<div style=\"visibility: hidden\">" +
|
||||
" <div style=\"visibility: visible\"><button>Visible</button></div>" +
|
||||
" <div style=\"visibility: hidden\"><button style=\"visibility: visible\">Visible</button></div>" +
|
||||
" <div>" +
|
||||
" <div style=\"visibility: visible\"><button style=\"visibility: hidden\">Hidden</button></div>" +
|
||||
" <button>Hidden</button>" +
|
||||
" </div>" +
|
||||
"</div>");
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertEquals(
|
||||
"- generic [active] [ref=e1]:\n" +
|
||||
" - button \"Visible\" [ref=e3]\n" +
|
||||
" - button \"Visible\" [ref=e4]",
|
||||
snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIncludeActiveElementInformation(Page page) {
|
||||
page.setContent(
|
||||
"<button id=\"btn1\">Button 1</button>" +
|
||||
"<button id=\"btn2\" autofocus>Button 2</button>" +
|
||||
"<div>Not focusable</div>");
|
||||
page.waitForFunction("document.activeElement?.id === 'btn2'");
|
||||
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("button \"Button 2\" [active] [ref=e3]"), snapshot);
|
||||
assertFalse(snapshot.contains("button \"Button 1\" [active]"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateActiveElementOnFocus(Page page) {
|
||||
page.setContent(
|
||||
"<input id=\"input1\" placeholder=\"First input\">" +
|
||||
"<input id=\"input2\" placeholder=\"Second input\">");
|
||||
|
||||
String initialSnapshot = aiSnapshot(page);
|
||||
assertTrue(initialSnapshot.contains("textbox \"First input\" [ref=e2]"), initialSnapshot);
|
||||
assertTrue(initialSnapshot.contains("textbox \"Second input\" [ref=e3]"), initialSnapshot);
|
||||
assertFalse(initialSnapshot.contains("textbox \"First input\" [active]"), initialSnapshot);
|
||||
assertFalse(initialSnapshot.contains("textbox \"Second input\" [active]"), initialSnapshot);
|
||||
|
||||
page.locator("#input2").focus();
|
||||
|
||||
String afterFocusSnapshot = aiSnapshot(page);
|
||||
assertTrue(afterFocusSnapshot.contains("textbox \"Second input\" [active] [ref=e3]"), afterFocusSnapshot);
|
||||
assertFalse(afterFocusSnapshot.contains("textbox \"First input\" [active]"), afterFocusSnapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCollapseInlineGenericNodes(Page page) {
|
||||
page.setContent(
|
||||
"<ul>" +
|
||||
"<li><b>3</b> <abbr>bds</abbr></li>" +
|
||||
"<li><b>2</b> <abbr>ba</abbr></li>" +
|
||||
"<li><b>1,200</b> <abbr>sqft</abbr></li>" +
|
||||
"</ul>");
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("listitem [ref=e3]: 3 bds"), snapshot);
|
||||
assertTrue(snapshot.contains("listitem [ref=e4]: 2 ba"), snapshot);
|
||||
assertTrue(snapshot.contains("listitem [ref=e5]: 1,200 sqft"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotRemoveGenericNodesWithTitle(Page page) {
|
||||
page.setContent("<div title=\"Element title\">Element content</div>");
|
||||
String snapshot = aiSnapshot(page);
|
||||
assertTrue(snapshot.contains("generic \"Element title\" [ref=e2]"), snapshot);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLimitDepth(Page page) {
|
||||
page.setContent(
|
||||
"<ul>" +
|
||||
"<li>item1</li>" +
|
||||
"<a href=\"about:blank\" style=\"cursor:pointer\">link</a>" +
|
||||
"<li><ul id=\"target\"><li>item2</li><li><ul><li>item3</li></ul></li></ul></li>" +
|
||||
"</ul>");
|
||||
|
||||
String snapshot1 = page.ariaSnapshot(new Page.AriaSnapshotOptions().setMode(AriaSnapshotMode.AI).setDepth(1));
|
||||
assertTrue(snapshot1.contains("listitem [ref=e3]: item1"), snapshot1);
|
||||
assertFalse(snapshot1.contains("item2"), snapshot1);
|
||||
assertFalse(snapshot1.contains("item3"), snapshot1);
|
||||
|
||||
String snapshot2 = page.ariaSnapshot(new Page.AriaSnapshotOptions().setMode(AriaSnapshotMode.AI).setDepth(3));
|
||||
assertTrue(snapshot2.contains("item1"), snapshot2);
|
||||
assertTrue(snapshot2.contains("item2"), snapshot2);
|
||||
assertFalse(snapshot2.contains("item3"), snapshot2);
|
||||
|
||||
String snapshot3 = page.ariaSnapshot(new Page.AriaSnapshotOptions().setMode(AriaSnapshotMode.AI).setDepth(100));
|
||||
assertTrue(snapshot3.contains("item1"), snapshot3);
|
||||
assertTrue(snapshot3.contains("item2"), snapshot3);
|
||||
assertTrue(snapshot3.contains("item3"), snapshot3);
|
||||
|
||||
String snapshot4 = page.locator("#target").ariaSnapshot(new Locator.AriaSnapshotOptions().setMode(AriaSnapshotMode.AI).setDepth(1));
|
||||
assertTrue(snapshot4.contains("listitem [ref=e7]: item2"), snapshot4);
|
||||
assertFalse(snapshot4.contains("item3"), snapshot4);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
|
||||
@@ -30,6 +31,7 @@ import static com.microsoft.playwright.options.LoadState.LOAD;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Tag("smoke")
|
||||
public class TestPageBasic extends TestBase {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.DropPayload;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.microsoft.playwright.Utils.mapOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestPageDrop extends TestBase {
|
||||
private void setupDropzone() {
|
||||
page.setContent("<style>#dropzone { width: 300px; height: 200px; border: 2px dashed #888; }</style>\n" +
|
||||
"<div id=\"dropzone\"></div>\n" +
|
||||
"<script>\n" +
|
||||
" window.__dropInfo = null;\n" +
|
||||
" const zone = document.getElementById('dropzone');\n" +
|
||||
" zone.addEventListener('dragenter', e => e.preventDefault());\n" +
|
||||
" zone.addEventListener('dragover', e => e.preventDefault());\n" +
|
||||
" zone.addEventListener('drop', async e => {\n" +
|
||||
" e.preventDefault();\n" +
|
||||
" const files = [];\n" +
|
||||
" for (const file of e.dataTransfer.files)\n" +
|
||||
" files.push({ name: file.name, type: file.type, size: file.size, text: await file.text() });\n" +
|
||||
" const data = {};\n" +
|
||||
" for (const t of e.dataTransfer.types) {\n" +
|
||||
" if (t !== 'Files')\n" +
|
||||
" data[t] = e.dataTransfer.getData(t);\n" +
|
||||
" }\n" +
|
||||
" window.__dropInfo = { files, data };\n" +
|
||||
" });\n" +
|
||||
"</script>");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> waitForDropInfo() {
|
||||
page.waitForCondition(() -> page.evaluate("window.__dropInfo") != null);
|
||||
return (Map<String, Object>) page.evaluate("window.__dropInfo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDropFilePayload() {
|
||||
setupDropzone();
|
||||
page.locator("#dropzone").drop(new DropPayload().setFiles(new FilePayload("note.txt", "text/plain", "hello".getBytes(StandardCharsets.UTF_8))));
|
||||
Map<String, Object> info = waitForDropInfo();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> files = (List<Map<String, Object>>) info.get("files");
|
||||
assertEquals(1, files.size());
|
||||
assertEquals("note.txt", files.get(0).get("name"));
|
||||
assertEquals("text/plain", files.get(0).get("type"));
|
||||
assertEquals("hello", files.get(0).get("text"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDropMultipleFilePayloads() {
|
||||
setupDropzone();
|
||||
page.locator("#dropzone").drop(new DropPayload().setFiles(new FilePayload[] {
|
||||
new FilePayload("a.txt", "text/plain", "AAA".getBytes(StandardCharsets.UTF_8)),
|
||||
new FilePayload("b.txt", "text/plain", "BB".getBytes(StandardCharsets.UTF_8)),
|
||||
}));
|
||||
Map<String, Object> info = waitForDropInfo();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> files = (List<Map<String, Object>>) info.get("files");
|
||||
assertEquals(2, files.size());
|
||||
assertEquals("a.txt", files.get(0).get("name"));
|
||||
assertEquals("AAA", files.get(0).get("text"));
|
||||
assertEquals("b.txt", files.get(1).get("name"));
|
||||
assertEquals("BB", files.get(1).get("text"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDropClipboardLikeData() {
|
||||
setupDropzone();
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("text/plain", "hello world");
|
||||
data.put("text/uri-list", "https://example.com");
|
||||
page.locator("#dropzone").drop(new DropPayload().setData(data));
|
||||
Map<String, Object> info = waitForDropInfo();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<?> files = (List<?>) info.get("files");
|
||||
assertTrue(files.isEmpty(), "expected no files");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> droppedData = (Map<String, String>) info.get("data");
|
||||
assertEquals("hello world", droppedData.get("text/plain"));
|
||||
assertEquals("https://example.com", droppedData.get("text/uri-list"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDropFileByLocalPath(@org.junit.jupiter.api.io.TempDir Path dir) throws Exception {
|
||||
setupDropzone();
|
||||
Path filePath = dir.resolve("hello.txt");
|
||||
Files.write(filePath, "path-content".getBytes(StandardCharsets.UTF_8));
|
||||
page.locator("#dropzone").drop(new DropPayload().setFiles(filePath));
|
||||
Map<String, Object> info = waitForDropInfo();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> files = (List<Map<String, Object>>) info.get("files");
|
||||
assertEquals(1, files.size());
|
||||
assertEquals("hello.txt", files.get(0).get("name"));
|
||||
assertEquals("path-content", files.get(0).get("text"));
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.options.ConsoleMessagesFilter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
|
||||
@@ -26,8 +27,7 @@ import static com.microsoft.playwright.Utils.getOS;
|
||||
import static com.microsoft.playwright.Utils.mapOf;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestPageEventConsole extends TestBase {
|
||||
@Test
|
||||
@@ -149,4 +149,60 @@ public class TestPageEventConsole extends TestBase {
|
||||
assertEquals(page, message.page());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveTimestamp() {
|
||||
double before = (double) System.currentTimeMillis() - 1;
|
||||
ConsoleMessage message = page.waitForConsoleMessage(
|
||||
() -> page.evaluate("() => console.log('timestamp test')"));
|
||||
double after = (double) System.currentTimeMillis() + 1;
|
||||
assertTrue(message.timestamp() >= before,
|
||||
"timestamp " + message.timestamp() + " should be >= " + before);
|
||||
assertTrue(message.timestamp() <= after,
|
||||
"timestamp " + message.timestamp() + " should be <= " + after);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveIncreasingTimestamps() {
|
||||
List<ConsoleMessage> messages = new ArrayList<>();
|
||||
page.onConsoleMessage(messages::add);
|
||||
page.evaluate("() => { console.log('first'); console.log('second'); console.log('third'); }");
|
||||
assertEquals(3, messages.size());
|
||||
for (int i = 1; i < messages.size(); i++)
|
||||
assertTrue(messages.get(i).timestamp() >= messages.get(i - 1).timestamp());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearConsoleMessagesShouldWork() {
|
||||
page.evaluate("() => { console.log('message1'); console.log('message2'); }");
|
||||
List<ConsoleMessage> messages = page.consoleMessages();
|
||||
assertTrue(messages.stream().anyMatch(m -> "message1".equals(m.text())));
|
||||
assertTrue(messages.stream().anyMatch(m -> "message2".equals(m.text())));
|
||||
|
||||
page.clearConsoleMessages();
|
||||
messages = page.consoleMessages();
|
||||
assertEquals(0, messages.size());
|
||||
|
||||
page.waitForConsoleMessage(() -> page.evaluate("() => console.log('message3')"));
|
||||
messages = page.consoleMessages();
|
||||
assertEquals(1, messages.size());
|
||||
assertEquals("message3", messages.get(0).text());
|
||||
}
|
||||
|
||||
@Test
|
||||
void consoleMessagesSinceNavigationFilterShouldWork() {
|
||||
page.evaluate("() => console.log('before navigation')");
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("() => console.log('after navigation')");
|
||||
|
||||
List<ConsoleMessage> all = page.consoleMessages(
|
||||
new Page.ConsoleMessagesOptions().setFilter(ConsoleMessagesFilter.ALL));
|
||||
assertTrue(all.stream().anyMatch(m -> "before navigation".equals(m.text())));
|
||||
assertTrue(all.stream().anyMatch(m -> "after navigation".equals(m.text())));
|
||||
|
||||
// sinceNavigation is the default
|
||||
List<ConsoleMessage> sinceNav = page.consoleMessages();
|
||||
assertFalse(sinceNav.stream().anyMatch(m -> "before navigation".equals(m.text())));
|
||||
assertTrue(sinceNav.stream().anyMatch(m -> "after navigation".equals(m.text())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -44,4 +43,28 @@ public class TestPageEventPageError extends TestBase {
|
||||
assertTrue(error.startsWith("Error: error" + (201 + i)), error);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearPageErrorsShouldWork() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("async () => {\n" +
|
||||
" window.setTimeout(() => { throw new Error('error1'); }, 0);\n" +
|
||||
" await new Promise(f => window.setTimeout(f, 100));\n" +
|
||||
"}");
|
||||
|
||||
List<String> errors = page.pageErrors();
|
||||
assertTrue(errors.stream().anyMatch(e -> e.contains("error1")));
|
||||
|
||||
page.clearPageErrors();
|
||||
errors = page.pageErrors();
|
||||
assertEquals(0, errors.size());
|
||||
|
||||
page.evaluate("async () => {\n" +
|
||||
" window.setTimeout(() => { throw new Error('error2'); }, 0);\n" +
|
||||
" await new Promise(f => window.setTimeout(f, 100));\n" +
|
||||
"}");
|
||||
errors = page.pageErrors();
|
||||
assertEquals(1, errors.size());
|
||||
assertTrue(errors.get(0).contains("error2"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,35 +164,6 @@ public class TestPageExposeFunction extends TestBase {
|
||||
assertEquals( 7, ((Map) result).get("x"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposeBindingHandleShouldWork() {
|
||||
JSHandle[] target = { null };
|
||||
page.exposeBinding("logme", (source, args) -> {
|
||||
target[0] = (JSHandle) args[0];
|
||||
return 17;
|
||||
}, new Page.ExposeBindingOptions().setHandle(true));
|
||||
Object result = page.evaluate("async function() {\n" +
|
||||
" return window['logme']({ foo: 42 });\n" +
|
||||
"}");
|
||||
assertEquals(42, target[0].evaluate("x => x.foo"));
|
||||
assertEquals(17, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposeBindingHandleShouldNotThrowDuringNavigation() {
|
||||
page.exposeBinding("logme", (source, args) -> {
|
||||
return 17;
|
||||
}, new Page.ExposeBindingOptions().setHandle(true));
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
|
||||
page.waitForNavigation(new Page.WaitForNavigationOptions().setWaitUntil(LOAD), () -> {
|
||||
page.evaluate("async url => {\n" +
|
||||
" window['logme']({ foo: 42 });\n" +
|
||||
" window.location.href = url;\n" +
|
||||
"}", server.PREFIX + "/one-style.html");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowForDuplicateRegistrations() {
|
||||
page.exposeFunction("foo", args -> null);
|
||||
@@ -202,28 +173,6 @@ public class TestPageExposeFunction extends TestBase {
|
||||
assertTrue(e.getMessage().contains("Function \"foo\" has been already registered"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposeBindingHandleShouldThrowForMultipleArguments() {
|
||||
page.exposeBinding("logme", (source, args) -> {
|
||||
return 17;
|
||||
}, new Page.ExposeBindingOptions().setHandle(true));
|
||||
assertEquals(17, page.evaluate("async function() {\n" +
|
||||
" return window['logme']({ foo: 42 });\n" +
|
||||
"}"));
|
||||
assertEquals(17, page.evaluate("async function() {\n" +
|
||||
" return window['logme']({ foo: 42 }, undefined, undefined);\n" +
|
||||
"}"));
|
||||
assertEquals(17, page.evaluate("async function() {\n" +
|
||||
" return window['logme'](undefined, undefined, undefined);\n" +
|
||||
"}"));
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
page.evaluate("async function() {\n" +
|
||||
" return window['logme'](1, 2);\n" +
|
||||
"}");
|
||||
});
|
||||
assertTrue(e.getMessage().contains("exposeBindingHandle supports a single argument, 2 received"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSerializeCycles() {
|
||||
Object[] object = { null };
|
||||
|
||||
@@ -71,6 +71,35 @@ public class TestPageNetworkResponse extends TestBase {
|
||||
assertTrue(e.getMessage().contains("closed"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnNullExistingResponseBeforeResponseReceived() {
|
||||
Request[] capturedRequest = {null};
|
||||
page.route("**/*", route -> {
|
||||
capturedRequest[0] = route.request();
|
||||
assertNull(capturedRequest[0].existingResponse());
|
||||
route.resume();
|
||||
});
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertNotNull(capturedRequest[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnExistingResponseAfterReceived() {
|
||||
Response[] responses = {null};
|
||||
page.onResponse(r -> responses[0] = r);
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
assertNotNull(responses[0]);
|
||||
assertEquals(responses[0], responses[0].request().existingResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnHttpVersion() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
Response response = page.waitForResponse("**/*", () -> page.navigate(server.EMPTY_PAGE));
|
||||
String version = response.httpVersion();
|
||||
assertTrue(version.matches("HTTP/[12](\\.[01])?"), "unexpected version: " + version);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRejectResponseFinishedIfContextCloses() {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -107,6 +108,8 @@ public class TestPopup extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldInheritTouchSupportFromBrowserContext() {
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=2014330
|
||||
Assumptions.assumeFalse(isFirefox() && Integer.parseInt(browser.version().split("\\.")[0]) >= 148);
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setViewportSize(400, 500)
|
||||
.setHasTouch(true));
|
||||
|
||||
@@ -40,18 +40,18 @@ public class TestRouteWebSocket {
|
||||
webSocketServer.reset();
|
||||
}
|
||||
|
||||
private void setupWS(Page target, int port, String binaryType) {
|
||||
setupWS(target.mainFrame(), port, binaryType);
|
||||
private void setupWS(Page target, Server server, int port, String binaryType) {
|
||||
setupWS(target.mainFrame(), server, port, binaryType);
|
||||
}
|
||||
private void setupWS(Frame target, int port, String binaryType) {
|
||||
target.navigate("about:blank");
|
||||
private void setupWS(Frame target, Server server, int port, String binaryType) {
|
||||
target.navigate(server.EMPTY_PAGE);
|
||||
// No 'error' listener: WebKit fires a spurious 'error' before 'close' on non-normal closures (e.g. 1008).
|
||||
target.evaluate("({ port, binaryType }) => {\n" +
|
||||
" window.log = [];\n" +
|
||||
" window.ws = new WebSocket('ws://localhost:' + port + '/ws');\n" +
|
||||
" window.ws.binaryType = binaryType;\n" +
|
||||
" window.ws.addEventListener('open', () => window.log.push('open'));\n" +
|
||||
" window.ws.addEventListener('close', event => window.log.push(`close code=${event.code} reason=${event.reason}`));\n" +
|
||||
" window.ws.addEventListener('error', event => window.log.push(`error`));\n" +
|
||||
" window.ws.addEventListener('message', async event => {\n" +
|
||||
" let data;\n" +
|
||||
" if (typeof event.data === 'string')\n" +
|
||||
@@ -92,10 +92,10 @@ public class TestRouteWebSocket {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"no-mock", "no-match", "pass-through"})
|
||||
public void shouldWorkWithTextMessage(String mock, Page page) throws Exception {
|
||||
public void shouldWorkWithTextMessage(String mock, Page page, Server server) throws Exception {
|
||||
setupRoute(page, mock);
|
||||
Future<WebSocket> wsPromise = webSocketServer.waitForWebSocket();
|
||||
setupWS(page, webSocketServer.getPort(), "blob");
|
||||
setupWS(page, server, webSocketServer.getPort(), "blob");
|
||||
|
||||
page.waitForCondition(() -> {
|
||||
Boolean result = (Boolean) page.evaluate("() => window.log.length >= 1");
|
||||
@@ -134,10 +134,10 @@ public class TestRouteWebSocket {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"no-mock", "no-match", "pass-through"})
|
||||
public void shouldWorkWithBinaryTypeBlob(String mock, Page page) throws Exception {
|
||||
public void shouldWorkWithBinaryTypeBlob(String mock, Page page, Server server) throws Exception {
|
||||
setupRoute(page, mock);
|
||||
Future<WebSocket> wsPromise = webSocketServer.waitForWebSocket();
|
||||
setupWS(page, webSocketServer.getPort(), "blob");
|
||||
setupWS(page, server, webSocketServer.getPort(), "blob");
|
||||
org.java_websocket.WebSocket ws = wsPromise.get();
|
||||
ws.send("hi".getBytes(StandardCharsets.UTF_8));
|
||||
page.waitForCondition(() -> {
|
||||
@@ -157,10 +157,10 @@ public class TestRouteWebSocket {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"no-mock", "no-match", "pass-through"})
|
||||
public void shouldWorkWithBinaryTypeArrayBuffer(String mock, Page page) throws Exception {
|
||||
public void shouldWorkWithBinaryTypeArrayBuffer(String mock, Page page, Server server) throws Exception {
|
||||
setupRoute(page, mock);
|
||||
Future<WebSocket> wsPromise = webSocketServer.waitForWebSocket();
|
||||
setupWS(page, webSocketServer.getPort(), "arraybuffer");
|
||||
setupWS(page, server, webSocketServer.getPort(), "arraybuffer");
|
||||
org.java_websocket.WebSocket ws = wsPromise.get();
|
||||
ws.send("hi".getBytes(StandardCharsets.UTF_8));
|
||||
page.waitForCondition(() -> {
|
||||
@@ -179,10 +179,10 @@ public class TestRouteWebSocket {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithServer(Page page) throws ExecutionException, InterruptedException {
|
||||
public void shouldWorkWithServer(Page page, Server server) throws ExecutionException, InterruptedException {
|
||||
WebSocketRoute[] wsRoute = new WebSocketRoute[]{null};
|
||||
page.routeWebSocket(Pattern.compile("/.*/"), ws -> {
|
||||
WebSocketRoute server = ws.connectToServer();
|
||||
WebSocketRoute serverRoute = ws.connectToServer();
|
||||
ws.onMessage(frame -> {
|
||||
String message = frame.text();
|
||||
switch (message) {
|
||||
@@ -192,13 +192,13 @@ public class TestRouteWebSocket {
|
||||
case "to-block":
|
||||
break;
|
||||
case "to-modify":
|
||||
server.send("modified");
|
||||
serverRoute.send("modified");
|
||||
break;
|
||||
default:
|
||||
server.send(message);
|
||||
serverRoute.send(message);
|
||||
}
|
||||
});
|
||||
server.onMessage(frame -> {
|
||||
serverRoute.onMessage(frame -> {
|
||||
String message = frame.text();
|
||||
switch (message) {
|
||||
case "to-block":
|
||||
@@ -210,12 +210,12 @@ public class TestRouteWebSocket {
|
||||
ws.send(message);
|
||||
}
|
||||
});
|
||||
server.send("fake");
|
||||
serverRoute.send("fake");
|
||||
wsRoute[0] = ws;
|
||||
});
|
||||
|
||||
Future<WebSocket> ws = webSocketServer.waitForWebSocket();
|
||||
setupWS(page, webSocketServer.getPort(), "blob");
|
||||
setupWS(page, server, webSocketServer.getPort(), "blob");
|
||||
page.waitForCondition(() -> webSocketServer.logCopy().size() >= 1);
|
||||
assertEquals(
|
||||
asList("message: fake"),
|
||||
@@ -277,7 +277,7 @@ public class TestRouteWebSocket {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithoutServer(Page page) {
|
||||
public void shouldWorkWithoutServer(Page page, Server server) {
|
||||
WebSocketRoute[] wsRoute = new WebSocketRoute[]{ null };
|
||||
page.routeWebSocket(Pattern.compile("/.*/"), ws -> {
|
||||
ws.onMessage(frame -> {
|
||||
@@ -288,7 +288,7 @@ public class TestRouteWebSocket {
|
||||
});
|
||||
wsRoute[0] = ws;
|
||||
});
|
||||
setupWS(page, webSocketServer.getPort(), "blob");
|
||||
setupWS(page, server, webSocketServer.getPort(), "blob");
|
||||
|
||||
page.evaluate("async () => {\n" +
|
||||
" await window.wsOpened;\n" +
|
||||
@@ -321,7 +321,7 @@ public class TestRouteWebSocket {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithBaseURL(Browser browser) throws Exception {
|
||||
public void shouldWorkWithBaseURL(Browser browser, Server server) throws Exception {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setBaseURL("http://localhost:" + webSocketServer.getPort()));
|
||||
Page newPage = context.newPage();
|
||||
|
||||
@@ -335,7 +335,7 @@ public class TestRouteWebSocket {
|
||||
});
|
||||
});
|
||||
|
||||
setupWS(newPage, webSocketServer.getPort(), "blob");
|
||||
setupWS(newPage, server, webSocketServer.getPort(), "blob");
|
||||
|
||||
newPage.evaluate("async () => {\n" +
|
||||
" await window.wsOpened;\n" +
|
||||
@@ -353,7 +353,7 @@ public class TestRouteWebSocket {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithNoTrailingSlash(Page page) throws Exception {
|
||||
public void shouldWorkWithNoTrailingSlash(Page page) throws Exception {
|
||||
List<String> log = new ArrayList<>();
|
||||
|
||||
// No trailing slash in the route pattern
|
||||
@@ -384,11 +384,36 @@ public class TestRouteWebSocket {
|
||||
page.waitForCondition(() -> log.size() >= 1);
|
||||
assertEquals(asList("query"), log);
|
||||
|
||||
// Wait and verify client received response
|
||||
// Wait and verify client received response
|
||||
page.waitForCondition(() -> {
|
||||
Boolean result = (Boolean) page.evaluate("() => window.log.length >= 1");
|
||||
return result;
|
||||
});
|
||||
assertEquals(asList("response"), page.evaluate("window.log"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExposeProtocolsToTheRouteHandler(Page page, Server server) {
|
||||
List<com.microsoft.playwright.WebSocketRoute> routes = new ArrayList<>();
|
||||
page.routeWebSocket(Pattern.compile(".*"), ws -> routes.add(ws));
|
||||
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
int port = webSocketServer.getPort();
|
||||
page.evaluate("({ port }) => {\n" +
|
||||
" window.wsNone = new WebSocket('ws://localhost:' + port + '/ws-none');\n" +
|
||||
" window.wsString = new WebSocket('ws://localhost:' + port + '/ws-string', 'chat.v1');\n" +
|
||||
" window.wsArray = new WebSocket('ws://localhost:' + port + '/ws-array', ['chat.v2', 'chat.v1']);\n" +
|
||||
"}", mapOf("port", port));
|
||||
|
||||
page.waitForCondition(() -> routes.size() == 3);
|
||||
|
||||
java.util.Map<String, com.microsoft.playwright.WebSocketRoute> byUrl = new java.util.HashMap<>();
|
||||
for (com.microsoft.playwright.WebSocketRoute r : routes) {
|
||||
String path = java.net.URI.create(r.url()).getPath();
|
||||
byUrl.put(path, r);
|
||||
}
|
||||
assertEquals(asList(), byUrl.get("/ws-none").protocols());
|
||||
assertEquals(asList("chat.v1"), byUrl.get("/ws-string").protocols());
|
||||
assertEquals(asList("chat.v2", "chat.v1"), byUrl.get("/ws-array").protocols());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -58,38 +59,6 @@ public class TestScreencast extends TestBase {
|
||||
assertTrue(Files.exists(saveAsPath));
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveAsShouldThrowWhenNoVideoFrames(@TempDir Path videosDir) {
|
||||
try (BrowserContext context = browser.newContext(
|
||||
new Browser.NewContextOptions()
|
||||
.setRecordVideoDir(videosDir)
|
||||
.setRecordVideoSize(320, 240)
|
||||
.setViewportSize(320, 240))) {
|
||||
|
||||
Page page = context.newPage();
|
||||
Page popup = context.waitForPage(() -> {
|
||||
page.evaluate("() => {\n" +
|
||||
" const win = window.open('about:blank');\n" +
|
||||
" win.close();\n" +
|
||||
"}");
|
||||
});
|
||||
page.close();
|
||||
|
||||
Path saveAsPath = videosDir.resolve("my-video.webm");
|
||||
if (!popup.isClosed()) {
|
||||
popup.waitForClose(() -> {});
|
||||
}
|
||||
// WebKit pauses renderer before win.close() and actually writes something.
|
||||
if (isWebKit()) {
|
||||
popup.video().saveAs(saveAsPath);
|
||||
assertTrue(Files.exists(saveAsPath));
|
||||
} else {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> popup.video().saveAs(saveAsPath));
|
||||
assertTrue(e.getMessage().contains("Page did not produce any video frames"), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDeleteVideo(@TempDir Path videosDir) {
|
||||
try (BrowserContext context = browser.newContext(
|
||||
@@ -130,15 +99,151 @@ public class TestScreencast extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldErrorIfPageNotClosedBeforeSaveAs(@TempDir Path tmpDir) {
|
||||
try (Page page = browser.newPage(new Browser.NewPageOptions().setRecordVideoDir(tmpDir))) {
|
||||
page.navigate(server.PREFIX + "/grid.html");
|
||||
Path outPath = tmpDir.resolve("some-video.webm");
|
||||
Video video = page.video();
|
||||
PlaywrightException exception = assertThrows(PlaywrightException.class, () -> video.saveAs(outPath));
|
||||
assertTrue(
|
||||
exception.getMessage().contains("Page is not yet closed. Close the page prior to calling saveAs"),
|
||||
exception.getMessage());
|
||||
void screencastStartShouldDeliverFramesViaOnFrame() throws Exception {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(500, 400));
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
List<ScreencastFrame> frames = new ArrayList<>();
|
||||
page.screencast().start(new Screencast.StartOptions().setOnFrame(frames::add));
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("() => document.body.style.backgroundColor = 'red'");
|
||||
page.waitForTimeout(500);
|
||||
page.screencast().stop();
|
||||
assertFalse(frames.isEmpty(), "expected at least one frame");
|
||||
// JPEG-encoded frames start with FF D8.
|
||||
for (ScreencastFrame frame : frames) {
|
||||
assertNotNull(frame.data());
|
||||
assertEquals((byte) 0xFF, frame.data()[0]);
|
||||
assertEquals((byte) 0xD8, frame.data()[1]);
|
||||
}
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void onFrameShouldReceiveViewportSize() {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(1000, 400));
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
List<ScreencastFrame> frames = new ArrayList<>();
|
||||
page.screencast().start(new Screencast.StartOptions().setOnFrame(frames::add));
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("() => document.body.style.backgroundColor = 'red'");
|
||||
page.waitForTimeout(500);
|
||||
page.screencast().stop();
|
||||
assertFalse(frames.isEmpty(), "expected at least one frame");
|
||||
for (ScreencastFrame frame : frames) {
|
||||
assertEquals(1000, frame.viewportWidth());
|
||||
assertEquals(400, frame.viewportHeight());
|
||||
}
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastStartShouldThrowIfAlreadyStarted() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
page.screencast().start(new Screencast.StartOptions().setOnFrame(data -> {}));
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class,
|
||||
() -> page.screencast().start(new Screencast.StartOptions().setOnFrame(data -> {})));
|
||||
assertTrue(e.getMessage().contains("Screencast is already started"), e.getMessage());
|
||||
page.screencast().stop();
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastStartShouldRecordVideoToPath(@TempDir Path tmpDir) throws Exception {
|
||||
Path videoPath = tmpDir.resolve("video.webm");
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(800, 600));
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
page.screencast().start(new Screencast.StartOptions().setPath(videoPath));
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("() => document.body.style.backgroundColor = 'red'");
|
||||
page.waitForTimeout(500);
|
||||
page.screencast().stop();
|
||||
assertTrue(Files.exists(videoPath), "video file should exist: " + videoPath);
|
||||
assertTrue(Files.size(videoPath) > 0);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastStartReturnsDisposable() throws Exception {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
AutoCloseable disposable = page.screencast().start(new Screencast.StartOptions().setOnFrame(data -> {}));
|
||||
disposable.close();
|
||||
// After dispose, starting again should succeed.
|
||||
page.screencast().start(new Screencast.StartOptions().setOnFrame(data -> {}));
|
||||
page.screencast().stop();
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastShowOverlay() throws Exception {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
AutoCloseable disposable = page.screencast().showOverlay("<div>Hello Overlay</div>");
|
||||
assertNotNull(disposable);
|
||||
disposable.close();
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastShowChapter() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.screencast().showChapter("Chapter Title");
|
||||
page.screencast().showChapter("With Description",
|
||||
new Screencast.ShowChapterOptions().setDescription("Some details").setDuration(100));
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastHideShowOverlays() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.screencast().showOverlay("<div>visible</div>");
|
||||
page.screencast().hideOverlays();
|
||||
page.screencast().showOverlays();
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void screencastShowAndHideActions() throws Exception {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
try {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
AutoCloseable disposable = page.screencast().showActions();
|
||||
assertNotNull(disposable);
|
||||
disposable.close();
|
||||
page.screencast().hideActions();
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Tag("smoke")
|
||||
public class TestSelectorsCss extends TestBase {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -448,7 +448,7 @@ public class TestSelectorsRole extends TestBase {
|
||||
assertTrue(e0.getMessage().contains("Role must not be empty"), e0.getMessage());
|
||||
|
||||
PlaywrightException e1 = assertThrows(PlaywrightException.class, () -> page.querySelector("role=foo[sElected]"));
|
||||
assertTrue(e1.getMessage().contains("Unknown attribute \"sElected\", must be one of \"checked\", \"disabled\", \"expanded\", \"include-hidden\", \"level\", \"name\", \"pressed\", \"selected\""), e1.getMessage());
|
||||
assertTrue(e1.getMessage().contains("Unknown attribute \"sElected\", must be one of \"checked\", \"description\", \"disabled\", \"expanded\", \"include-hidden\", \"level\", \"name\", \"pressed\", \"selected\""), e1.getMessage());
|
||||
|
||||
PlaywrightException e2 = assertThrows(PlaywrightException.class, () -> page.querySelector("role=foo[bar . qux=true]"));
|
||||
assertTrue(e2.getMessage().contains("Unknown attribute \"bar.qux\""), e2.getMessage());
|
||||
|
||||
@@ -158,6 +158,7 @@ public class TestTracing extends TestBase {
|
||||
Pattern.compile("Set content"),
|
||||
Pattern.compile("Click")
|
||||
});
|
||||
traceViewer.selectAction("Click");
|
||||
traceViewer.showSourceTab();
|
||||
assertThat(traceViewer.stackFrames()).containsText(new Pattern[] {
|
||||
Pattern.compile("myMethodInner"),
|
||||
@@ -379,4 +380,15 @@ public class TestTracing extends TestBase {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRecordHarWithStartHarStopHar(@TempDir Path tempDir) throws Exception {
|
||||
Path harPath = tempDir.resolve("tracing.har");
|
||||
context.tracing().startHar(harPath, new Tracing.StartHarOptions().setMode(com.microsoft.playwright.options.HarMode.MINIMAL));
|
||||
page.navigate(server.PREFIX + "/one-style.html");
|
||||
context.tracing().stopHar();
|
||||
String content = new String(Files.readAllBytes(harPath));
|
||||
assertTrue(content.contains("\"log\""), content);
|
||||
assertTrue(content.contains("/one-style.html"), content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static com.microsoft.playwright.Utils.relativePathOrSkipTest;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestVideo extends TestBase {
|
||||
@Test
|
||||
|
||||
@@ -193,7 +193,9 @@ public class TestWorkers extends TestBase {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
Worker worker = page.waitForWorker(() -> page.evaluate(
|
||||
"() => new Worker(URL.createObjectURL(new Blob(['console.log(1)'], {type: 'application/javascript'})))"));
|
||||
assertEquals("10\u00A0000,2", worker.evaluate("() => (10000.20).toLocaleString()"));
|
||||
// https://github.com/microsoft/playwright/issues/38919
|
||||
String expected = isFirefox() ? "10,000.2" : "10\u00A0000,2";
|
||||
assertEquals(expected, worker.evaluate("() => (10000.20).toLocaleString()"));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class TraceViewerPage {
|
||||
}
|
||||
|
||||
Locator stackFrames() {
|
||||
return this.page.getByRole(AriaRole.LIST, new Page.GetByRoleOptions().setName("stack trace")).getByRole(AriaRole.LISTITEM);
|
||||
return this.page.getByRole(AriaRole.LISTBOX, new Page.GetByRoleOptions().setName("stack trace")).getByRole(AriaRole.OPTION);
|
||||
}
|
||||
|
||||
void selectAction(String title, int ordinal) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user