Compare commits
116 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b56a714f6 | |||
| ccffa01154 | |||
| 91c3264c75 | |||
| 419c378e0f | |||
| 270bc99420 | |||
| 942a281f15 | |||
| 3417717c62 | |||
| f98ad20dcc | |||
| 8fb21af3ff | |||
| 049493c242 | |||
| be06d1e7db | |||
| b9b3552cc4 | |||
| 1b2ac3f2c3 | |||
| e8e076310a | |||
| 4a07105d8b | |||
| 7f2a5fe9af | |||
| 99ab89917f | |||
| bd97c96707 | |||
| d38bae17d3 | |||
| 23aa10690e | |||
| 72b36b46e2 | |||
| 70a8577f6f | |||
| de1d6a6b36 | |||
| 36705817bf | |||
| 8286f8a9d8 | |||
| 906d947c26 | |||
| e26a2710bd | |||
| dbe1d30feb | |||
| 4121a28299 | |||
| 0ad604f058 | |||
| d72000c793 | |||
| 9ef73b389b | |||
| da2501af49 | |||
| 7ce6c7f0a0 | |||
| 197ee801ad | |||
| 77e59999ab | |||
| c4e1f898e6 | |||
| ffe2bd4a96 | |||
| bc2857053c | |||
| 7e6f98c903 | |||
| e889b20fda | |||
| f28ca44fa0 | |||
| d73f953e68 | |||
| cc28516281 | |||
| d91c93bed1 | |||
| 2b45615e14 | |||
| d6f6448b1d | |||
| 5d9f76f4c5 | |||
| 38f3dd3f5a | |||
| 4efb792c36 | |||
| aa4f9754de | |||
| 7d9d9a2d9d | |||
| db1c899cf6 | |||
| 91e70280a3 | |||
| 5fe5a3e925 | |||
| fb2188cd2a | |||
| fc4a536308 | |||
| 4312a98ae0 | |||
| f629f915de | |||
| 85c5f90029 | |||
| 30778a3b04 | |||
| 25ba8474f4 | |||
| 5394b5d9b3 | |||
| 883487772a | |||
| 4d912193e7 | |||
| 05eb1f1161 | |||
| 2dbfa9d38e | |||
| 86f929aaf0 | |||
| fa75e29fcf | |||
| 7d5953c96e | |||
| 632fba54a5 | |||
| f76af33f52 | |||
| 4204096c24 | |||
| d3495ca511 | |||
| 4b873ec3ad | |||
| 463146ab11 | |||
| f6bc9a8b3d | |||
| 35e3c3653e | |||
| ed63ba4dcf | |||
| 48a92d1a62 | |||
| d219fddc8b | |||
| 7a1bbe23b1 | |||
| 2a047bff9a | |||
| 4e5285950d | |||
| b8a9d888be | |||
| 5a4640fe2a | |||
| 2ba018dd7e | |||
| 7f3db2ff46 | |||
| 8547c706ea | |||
| 30a696172a | |||
| 23de4518f4 | |||
| 343502d559 | |||
| 83837af5e5 | |||
| 7163012709 | |||
| be59662a62 | |||
| 45591df430 | |||
| 804c577070 | |||
| c237fae71e | |||
| 1783b117e6 | |||
| 5f3b5dbe27 | |||
| bc50392220 | |||
| 96d74ef678 | |||
| ab89f6a953 | |||
| 05f641c5af | |||
| d0bbf54b3b | |||
| 7db3e3f401 | |||
| 470df42b36 | |||
| b260125389 | |||
| f8fc1068bc | |||
| 2db2762a0d | |||
| cd56352278 | |||
| 6c729a8c9d | |||
| fe3e3e55dc | |||
| 1dc938cc67 | |||
| 05239433d2 | |||
| 9fdcbb63f9 |
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"hydrated": false,
|
||||
"properties": {
|
||||
"helpUri": "https://eng.ms/docs/microsoft-security/security/azure-security/cloudai-security-fundamentals-engineering/security-integration/guardian-wiki/microsoft-guardian/general/suppressions",
|
||||
"hydrationStatus": "This file does not contain identifying data. It is safe to check into your repo. To hydrate this file with identifying data, run `guardian hydrate --help` and follow the guidance."
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"suppressionSets": {
|
||||
"default": {
|
||||
"name": "default",
|
||||
"createdDate": "2024-02-06 20:37:57Z",
|
||||
"lastUpdatedDate": "2024-02-06 20:37:57Z"
|
||||
}
|
||||
},
|
||||
"results": {
|
||||
"de854c6ab9b27b1ec642cec1a51059b92f88815a231c1c8f4b8e71d9e378f174": {
|
||||
"signature": "de854c6ab9b27b1ec642cec1a51059b92f88815a231c1c8f4b8e71d9e378f174",
|
||||
"alternativeSignatures": [
|
||||
"79827cf2e75a7f99eec716562fb9fa0d49014ac96b7afc76d29d79a33e8edd94"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"ebe0026db71ae4bb2d8e76b706198003079a5c095658de8dd49e67f7e572ea46": {
|
||||
"signature": "ebe0026db71ae4bb2d8e76b706198003079a5c095658de8dd49e67f7e572ea46",
|
||||
"alternativeSignatures": [],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"bb02ef965dce40b6c950b6d0cf8a9f41c08c5e33f17268fb208f3687b11ffa26": {
|
||||
"signature": "bb02ef965dce40b6c950b6d0cf8a9f41c08c5e33f17268fb208f3687b11ffa26",
|
||||
"alternativeSignatures": [
|
||||
"3a8630eaccc2c5c39ae78836bb115bf55557058bad206fdad7dbe4f0ae466ed1"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"dffa3e24f6dc7542d741b2fab22eec657aca441a51cee515ca9bb4932995a416": {
|
||||
"signature": "dffa3e24f6dc7542d741b2fab22eec657aca441a51cee515ca9bb4932995a416",
|
||||
"alternativeSignatures": [
|
||||
"56a4b454840e2c21d44a76d9ab09fde76fba682ce7508a3f6abf7b411d389e56"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"5dbcaaac8cdccc6df557cbde94e5d7e0f1c8a67546ba82a1b85b629030f3d311": {
|
||||
"signature": "5dbcaaac8cdccc6df557cbde94e5d7e0f1c8a67546ba82a1b85b629030f3d311",
|
||||
"alternativeSignatures": [
|
||||
"fdb8e8af8d5697f767d0e55194f91d4a089d981555e00d058ba866acb8602014"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"b7db026b2a60bdb63af1c0938ac16d9414bb4d38e9efdc51626e12aa55f6b72f": {
|
||||
"signature": "b7db026b2a60bdb63af1c0938ac16d9414bb4d38e9efdc51626e12aa55f6b72f",
|
||||
"alternativeSignatures": [
|
||||
"bf7bb897e644659827d8dc8d55f719296d3ab94dc750b666ce90d8057361d9d5"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"aa702d85554c352e3016e3ec3d790df489833dc97e3733c58b57915ec125f47b": {
|
||||
"signature": "aa702d85554c352e3016e3ec3d790df489833dc97e3733c58b57915ec125f47b",
|
||||
"alternativeSignatures": [
|
||||
"948787329d52a66b4691383c81af407b03e68344a6685bbab3cfa8eb8db34f81"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"38174b5c9b474c3c0278d4c4173c14022e03dec3dc4db5ced51d2ca8459e7f2a": {
|
||||
"signature": "38174b5c9b474c3c0278d4c4173c14022e03dec3dc4db5ced51d2ca8459e7f2a",
|
||||
"alternativeSignatures": [
|
||||
"a9efa99679f3966da96a8b89f1250576cfceda774556d43ea89ea84289967276"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"08a4e1be4662d897e5b2b7a7dc6d6901405462cd2d5f8ad433c13e12a8503fb6": {
|
||||
"signature": "08a4e1be4662d897e5b2b7a7dc6d6901405462cd2d5f8ad433c13e12a8503fb6",
|
||||
"alternativeSignatures": [
|
||||
"009132f89939956a3f4471bb13353394015c9a7e675d118aa427e75f05658e05"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
},
|
||||
"551d69737553150380e58bc9a8ae1e8f17da931561ea4e195781fb8cad225188": {
|
||||
"signature": "551d69737553150380e58bc9a8ae1e8f17da931561ea4e195781fb8cad225188",
|
||||
"alternativeSignatures": [
|
||||
"617ad56322c5fb82a162b0b583e676d66a8e76b0d444aaab487865e4bf89e83b"
|
||||
],
|
||||
"memberOf": [
|
||||
"default"
|
||||
],
|
||||
"createdDate": "2024-02-06 20:37:57Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +1,81 @@
|
||||
trigger:
|
||||
none
|
||||
trigger: none
|
||||
pr: none
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-22.04
|
||||
resources:
|
||||
repositories:
|
||||
- repository: 1esPipelines
|
||||
type: git
|
||||
name: 1ESPipelineTemplates/1ESPipelineTemplates
|
||||
ref: refs/tags/release
|
||||
|
||||
steps:
|
||||
- bash: |
|
||||
if [[ ! "$CURRENT_BRANCH" =~ ^release-.* ]]; then
|
||||
echo "Can only publish from a release branch."
|
||||
echo "Unexpected branch name: $CURRENT_BRANCH"
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CURRENT_BRANCH: ${{ variables['Build.SourceBranchName'] }}
|
||||
displayName: "Check the branch is a release branch"
|
||||
|
||||
- bash: |
|
||||
echo "importing GPG key:"
|
||||
# Pipeline variables do not preserve line ends so we use base64 instead of --armored as a workaround.
|
||||
echo $GPG_PRIVATE_KEY_BASE64 | base64 -d | gpg --batch --import
|
||||
echo "list keys after import:"
|
||||
gpg --list-keys
|
||||
env:
|
||||
GPG_PRIVATE_KEY_BASE64: $(GPG_PRIVATE_KEY_BASE64) # secret variable has to be mapped to an env variable
|
||||
displayName: "Import gpg key"
|
||||
|
||||
- bash: ./scripts/download_driver_for_all_platforms.sh
|
||||
displayName: 'Download driver'
|
||||
|
||||
- bash: mvn -B deploy -D skipTests --no-transfer-progress --activate-profiles release -D gpg.passphrase=$GPG_PASSPHRASE -DaltDeploymentRepository=snapshot-repo::default::file:$(pwd)/local-build
|
||||
displayName: 'Build and deploy to a local directory'
|
||||
env:
|
||||
GPG_PASSPHRASE: $(GPG_PASSPHRASE) # secret variable has to be mapped to an env variable
|
||||
|
||||
- bash: |
|
||||
for file in $(find snapshots -type f); do
|
||||
echo "processing: $file"
|
||||
if [[ $file =~ \.(md5|sha1|sha256)$ ]]; then
|
||||
continue
|
||||
fi
|
||||
sha256sum "$file" | cut -f1 -d \ > "$file.sha256"
|
||||
done
|
||||
displayName: 'Create .sha256 files'
|
||||
|
||||
- task: EsrpRelease@2
|
||||
inputs:
|
||||
ConnectedServiceName: 'Playwright-Java-ESRP'
|
||||
Intent: 'PackageDistribution'
|
||||
ContentType: 'Maven'
|
||||
PackageLocation: './local-build'
|
||||
Owners: 'yurys@microsoft.com'
|
||||
Approvers: 'maxschmitt@microsoft.com'
|
||||
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
|
||||
MainPublisher: 'PlaywrightJava'
|
||||
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
|
||||
displayName: 'ESRP Release to Maven'
|
||||
extends:
|
||||
template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines
|
||||
parameters:
|
||||
pool:
|
||||
name: DevDivPlaywrightAzurePipelinesUbuntu2204
|
||||
os: linux
|
||||
sdl:
|
||||
sourceAnalysisPool:
|
||||
name: DevDivPlaywrightAzurePipelinesWindows2022
|
||||
# The image must be windows-based due to restrictions of the SDL tools. See: https://aka.ms/AAo6v8e
|
||||
# In the case of a windows build, this can be the same as the above pool image.
|
||||
os: windows
|
||||
suppression:
|
||||
suppressionFile: $(Build.SourcesDirectory)\.azure-pipelines\guardian\SDL\.gdnsuppress
|
||||
stages:
|
||||
- stage: Stage
|
||||
jobs:
|
||||
- job: HostJob
|
||||
steps:
|
||||
- bash: |
|
||||
if [[ ! "$CURRENT_BRANCH" =~ ^release-.* ]]; then
|
||||
echo "Can only publish from a release branch."
|
||||
echo "Unexpected branch name: $CURRENT_BRANCH"
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CURRENT_BRANCH: ${{ variables['Build.SourceBranchName'] }}
|
||||
displayName: "Check the branch is a release branch"
|
||||
|
||||
- bash: |
|
||||
echo "importing GPG key:"
|
||||
# Pipeline variables do not preserve line ends so we use base64 instead of --armored as a workaround.
|
||||
echo $GPG_PRIVATE_KEY_BASE64 | base64 -d | gpg --batch --import
|
||||
echo "list keys after import:"
|
||||
gpg --list-keys
|
||||
env:
|
||||
GPG_PRIVATE_KEY_BASE64: $(GPG_PRIVATE_KEY_BASE64) # secret variable has to be mapped to an env variable
|
||||
displayName: "Import gpg key"
|
||||
|
||||
- bash: ./scripts/download_driver_for_all_platforms.sh
|
||||
displayName: 'Download driver'
|
||||
|
||||
- bash: mvn -B deploy -D skipTests --no-transfer-progress --activate-profiles release -D gpg.passphrase=$GPG_PASSPHRASE -DaltDeploymentRepository=snapshot-repo::default::file:$(pwd)/local-build
|
||||
displayName: 'Build and deploy to a local directory'
|
||||
env:
|
||||
GPG_PASSPHRASE: $(GPG_PASSPHRASE) # secret variable has to be mapped to an env variable
|
||||
|
||||
- bash: |
|
||||
for file in $(find snapshots -type f); do
|
||||
echo "processing: $file"
|
||||
if [[ $file =~ \.(md5|sha1|sha256)$ ]]; then
|
||||
continue
|
||||
fi
|
||||
sha256sum "$file" | cut -f1 -d \ > "$file.sha256"
|
||||
done
|
||||
displayName: 'Create .sha256 files'
|
||||
|
||||
- task: EsrpRelease@4
|
||||
inputs:
|
||||
ConnectedServiceName: 'Playwright-ESRP'
|
||||
Intent: 'PackageDistribution'
|
||||
ContentType: 'Maven'
|
||||
ContentSource: 'Folder'
|
||||
FolderLocation: './local-build'
|
||||
WaitForReleaseCompletion: true
|
||||
Owners: 'yurys@microsoft.com'
|
||||
Approvers: 'maxschmitt@microsoft.com'
|
||||
ServiceEndpointUrl: 'https://api.esrp.microsoft.com'
|
||||
MainPublisher: 'Playwright'
|
||||
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47'
|
||||
displayName: 'ESRP Release to Maven'
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Something doesn't work like it should? Tell us!
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Context:**
|
||||
- Playwright Version: [what Playwright version do you use?]
|
||||
- Operating System: [e.g. Windows, Linux or Mac]
|
||||
- Browser: [e.g. All, Chromium, Firefox, WebKit]
|
||||
- Extra: [any specific details about your environment]
|
||||
|
||||
<!-- CLI to auto-capture this info -->
|
||||
<!-- npx envinfo --preset playwright --markdown -->
|
||||
|
||||
**Code Snippet**
|
||||
|
||||
Help us help you! Put down a short code snippet that illustrates your bug and
|
||||
that we can run and debug locally. For example:
|
||||
|
||||
```java
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
public class ExampleReproducible {
|
||||
public static void main(String[] args) {
|
||||
try (Playwright playwright = Playwright.create()) {
|
||||
Browser browser = playwright.chromium().launch();
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Describe the bug**
|
||||
|
||||
Add any other details about the problem here.
|
||||
@@ -0,0 +1,95 @@
|
||||
name: Bug Report 🪲
|
||||
description: Create a bug report to help us improve
|
||||
title: '[Bug]: '
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
# Please follow these steps first:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Troubleshoot
|
||||
If Playwright is not behaving the way you expect, we'd ask you to look at the [documentation](https://playwright.dev/java/docs/intro) and search the issue tracker for evidence supporting your expectation.
|
||||
Please make reasonable efforts to troubleshoot and rule out issues with your code, the configuration, or any 3rd party libraries you might be using.
|
||||
Playwright offers [several debugging tools](https://playwright.dev/java/docs/debug) that you can use to troubleshoot your issues.
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Ask for help through appropriate channels
|
||||
If you feel unsure about the cause of the problem, consider asking for help on for example [StackOverflow](https://stackoverflow.com/questions/ask) or our [Discord channel](https://aka.ms/playwright/discord) before posting a bug report. The issue tracker is not a help forum.
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Make a minimal reproduction
|
||||
To file the report, you will need a GitHub repository with a minimal (but complete) example and simple/clear steps on how to reproduce the bug.
|
||||
The simpler you can make it, the more likely we are to successfully verify and fix the bug.
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
> [!IMPORTANT]
|
||||
> Bug reports without a minimal reproduction will be rejected.
|
||||
|
||||
---
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: |
|
||||
The version of Playwright you are using.
|
||||
Is it the [latest](https://github.com/microsoft/playwright-java/releases)? Test and see if the bug has already been fixed.
|
||||
placeholder: ex. 1.41.1
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: Please link to a repository with a minimal reproduction and describe accurately how we can reproduce/verify the bug.
|
||||
placeholder: |
|
||||
Example steps (replace with your own):
|
||||
1. Clone my repo at https://github.com/<myuser>/example
|
||||
2. mvn test
|
||||
3. You should see the error come up
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: A description of what you expect to happen.
|
||||
placeholder: I expect to see X or Y
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Actual behavior
|
||||
description: |
|
||||
A clear and concise description of the unexpected behavior.
|
||||
Please include any relevant output here, especially any error messages.
|
||||
placeholder: A bug happened!
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Anything else that might be relevant
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: envinfo
|
||||
attributes:
|
||||
label: Environment
|
||||
description: |
|
||||
Please provide information about the environment you are running in.
|
||||
placeholder: |
|
||||
- Operating System: [Ubuntu 22.04]
|
||||
- CPU: [arm64]
|
||||
- Browser: [All, Chromium, Firefox, WebKit]
|
||||
- Java Version: [20]
|
||||
- Maven Version: [3.8.6]
|
||||
- Other info:
|
||||
validations:
|
||||
required: true
|
||||
@@ -1,4 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Join our Slack community
|
||||
url: https://aka.ms/playwright-slack
|
||||
about: Ask questions and discuss with other community members
|
||||
- name: Join our Discord Server
|
||||
url: https://aka.ms/playwright/discord
|
||||
about: Ask questions and discuss with other community members
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
name: Documentation 📖
|
||||
description: Submit a request to add or update documentation
|
||||
title: '[Docs]: '
|
||||
labels: ['Documentation :book:']
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
### Thank you for helping us improve our documentation!
|
||||
Please be sure you are looking at [the Next version of the documentation](https://playwright.dev/java/docs/next/intro) before opening an issue here.
|
||||
- type: textarea
|
||||
id: links
|
||||
attributes:
|
||||
label: Page(s)
|
||||
description: |
|
||||
Links to one or more documentation pages that should be modified.
|
||||
If you are reporting an issue with a specific section of a page, try to link directly to the nearest anchor.
|
||||
If you are suggesting that a new page be created, link to the parent of the proposed page.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Description
|
||||
description: |
|
||||
Describe the change you are requesting.
|
||||
If the issue pertains to a single function or matcher, be sure to specify the entire call signature.
|
||||
validations:
|
||||
required: true
|
||||
@@ -0,0 +1,30 @@
|
||||
name: Feature Request 🚀
|
||||
description: Submit a proposal for a new feature
|
||||
title: '[Feature]: '
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
### Thank you for taking the time to suggest a new feature!
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: '🚀 Feature Request'
|
||||
description: A clear and concise description of what the feature is.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: example
|
||||
attributes:
|
||||
label: Example
|
||||
description: Describe how this feature would be used.
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: motivation
|
||||
attributes:
|
||||
label: Motivation
|
||||
description: |
|
||||
Outline your motivation for the proposal. How will it make Playwright better?
|
||||
validations:
|
||||
required: true
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Request new features to be added
|
||||
title: "[Feature]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Let us know what functionality you'd like to see in Playwright and what your use case is.
|
||||
Do you think others might benefit from this as well?
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
name: I have a question
|
||||
about: Feel free to ask us your questions!
|
||||
title: "[Question]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
name: 'Questions / Help 💬'
|
||||
description: If you have questions, please check StackOverflow or Discord
|
||||
title: '[Please read the message below]'
|
||||
labels: [':speech_balloon: Question']
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Questions and Help 💬
|
||||
|
||||
This issue tracker is reserved for bug reports and feature requests.
|
||||
|
||||
For anything else, such as questions or getting help, please see:
|
||||
|
||||
- [The Playwright documentation](https://playwright.dev/java)
|
||||
- [Our Discord server](https://aka.ms/playwright/discord)
|
||||
- type: checkboxes
|
||||
id: no-post
|
||||
attributes:
|
||||
label: |
|
||||
Please do not submit this issue.
|
||||
description: |
|
||||
> [!IMPORTANT]
|
||||
> This issue will be closed.
|
||||
options:
|
||||
- label: I understand
|
||||
required: true
|
||||
@@ -1,38 +0,0 @@
|
||||
---
|
||||
name: Report regression
|
||||
about: Functionality that used to work and does not any more
|
||||
title: "[REGRESSION]: "
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Context:**
|
||||
- GOOD Playwright Version: [what Playwright version worked nicely?]
|
||||
- BAD Playwright Version: [what Playwright version doesn't work any more?]
|
||||
- Operating System: [e.g. Windows, Linux or Mac]
|
||||
- Extra: [any specific details about your environment]
|
||||
|
||||
**Code Snippet**
|
||||
|
||||
Help us help you! Put down a short code snippet that illustrates your bug and
|
||||
that we can run and debug locally. For example:
|
||||
|
||||
```java
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
public class ExampleReproducible {
|
||||
public static void main(String[] args) {
|
||||
try (Playwright playwright = Playwright.create()) {
|
||||
Browser browser = playwright.chromium().launch();
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Describe the bug**
|
||||
|
||||
Add any other details about the problem here.
|
||||
@@ -0,0 +1,90 @@
|
||||
name: Report regression
|
||||
description: Functionality that used to work and does not any more
|
||||
title: "[Regression]: "
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
# Please follow these steps first:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Make a minimal reproduction
|
||||
To file the report, you will need a GitHub repository with a minimal (but complete) example and simple/clear steps on how to reproduce the regression.
|
||||
The simpler you can make it, the more likely we are to successfully verify and fix the regression.
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
> [!IMPORTANT]
|
||||
> Regression reports without a minimal reproduction will be rejected.
|
||||
|
||||
---
|
||||
- type: input
|
||||
id: goodVersion
|
||||
attributes:
|
||||
label: Last Good Version
|
||||
description: |
|
||||
Last version of Playwright where the feature was working.
|
||||
placeholder: ex. 1.40.1
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: badVersion
|
||||
attributes:
|
||||
label: First Bad Version
|
||||
description: |
|
||||
First version of Playwright where the feature was broken.
|
||||
Is it the [latest](https://github.com/microsoft/playwright-java/releases)? Test and see if the regression has already been fixed.
|
||||
placeholder: ex. 1.41.1
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: Please link to a repository with a minimal reproduction and describe accurately how we can reproduce/verify the bug.
|
||||
placeholder: |
|
||||
Example steps (replace with your own):
|
||||
1. Clone my repo at https://github.com/<myuser>/example
|
||||
2. mvn test
|
||||
3. You should see the error come up
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: A description of what you expect to happen.
|
||||
placeholder: I expect to see X or Y
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Actual behavior
|
||||
description: A clear and concise description of the unexpected behavior.
|
||||
placeholder: A bug happened!
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Anything else that might be relevant
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: envinfo
|
||||
attributes:
|
||||
label: Environment
|
||||
description: |
|
||||
Please provide information about the environment you are running in.
|
||||
placeholder: |
|
||||
- Operating System: [Ubuntu 22.04]
|
||||
- CPU: [arm64]
|
||||
- Browser: [All, Chromium, Firefox, WebKit]
|
||||
- Java Version: [20]
|
||||
- Maven Version: [3.8.6]
|
||||
- Other info:
|
||||
validations:
|
||||
required: true
|
||||
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/" # Location of the pom.xml file
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
open-pull-requests-limit: 10
|
||||
allow:
|
||||
- dependency-type: "direct" # Optional: Only update direct dependencies
|
||||
- dependency-type: "indirect" # Optional: Only update indirect (transitive) dependencies
|
||||
@@ -1,25 +0,0 @@
|
||||
name: "devrelease:docker"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
publish-canary-docker:
|
||||
name: "publish to DockerHub"
|
||||
runs-on: ubuntu-20.04
|
||||
if: github.repository == 'microsoft/playwright-java'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: azure/docker-login@v1
|
||||
with:
|
||||
login-server: playwright.azurecr.io
|
||||
username: playwright
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Docker QEMU for arm64 docker builds
|
||||
uses: docker/setup-qemu-action@v1
|
||||
with:
|
||||
platforms: arm64
|
||||
- name: publish docker canary
|
||||
run: ./utils/docker/publish_docker.sh canary
|
||||
@@ -8,25 +8,23 @@ on:
|
||||
required: true
|
||||
type: boolean
|
||||
description: "Is this a release image?"
|
||||
branches:
|
||||
- release-*
|
||||
jobs:
|
||||
publish-canary-docker:
|
||||
name: publish to DockerHub
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
if: github.repository == 'microsoft/playwright-java'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- uses: azure/docker-login@v1
|
||||
with:
|
||||
login-server: playwright.azurecr.io
|
||||
username: playwright
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
- name: Set up Docker QEMU for arm64 docker builds
|
||||
uses: docker/setup-qemu-action@v1
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: arm64
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- run: ./utils/docker/publish_docker.sh stable
|
||||
if: (github.event_name != 'workflow_dispatch' && !github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true')
|
||||
- run: ./utils/docker/publish_docker.sh canary
|
||||
@@ -31,11 +31,11 @@ jobs:
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Run tests
|
||||
run: mvn test --no-transfer-progress --fail-at-end
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
|
||||
env:
|
||||
BROWSER: ${{ matrix.browser }}
|
||||
- name: Run tracing tests w/ sources
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D test=*TestTracing*
|
||||
run: mvn test --no-transfer-progress --fail-at-end --projects=playwright -D test=*TestTracing* -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
|
||||
env:
|
||||
BROWSER: ${{ matrix.browser }}
|
||||
PLAYWRIGHT_JAVA_SRC: src/test/java
|
||||
@@ -79,7 +79,7 @@ jobs:
|
||||
- name: Build & Install
|
||||
run: mvn -B install -D skipTests --no-transfer-progress
|
||||
- name: Run tests
|
||||
run: mvn test --no-transfer-progress --fail-at-end
|
||||
run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
|
||||
env:
|
||||
BROWSER: chromium
|
||||
BROWSER_CHANNEL: ${{ matrix.browser-channel }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Test Docker
|
||||
name: Docker
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
@@ -18,13 +18,18 @@ on:
|
||||
- release-*
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-20.04
|
||||
name: Test
|
||||
timeout-minutes: 120
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
flavor: [focal, jammy]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build Docker image
|
||||
run: bash utils/docker/build.sh --amd64 focal playwright-java:localbuild-focal
|
||||
run: bash utils/docker/build.sh --amd64 ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
|
||||
- name: Test
|
||||
run: |
|
||||
CONTAINER_ID="$(docker run --rm --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-focal /bin/bash)"
|
||||
CONTAINER_ID="$(docker run --rm --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash)"
|
||||
docker exec "${CONTAINER_ID}" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh
|
||||
|
||||
+2
-2
@@ -34,9 +34,9 @@ Names of published driver archives can be found at https://github.com/microsoft/
|
||||
mvn compile
|
||||
mvn test
|
||||
# Executing a single test
|
||||
BROWSER=chromium mvn test -Dtest=TestPageNetworkSizes#shouldHaveTheCorrectResponseBodySize
|
||||
BROWSER=chromium mvn test --projects=playwright -Dtest=TestPageNetworkSizes#shouldHaveTheCorrectResponseBodySize
|
||||
# Executing a single test class
|
||||
BROWSER=chromium mvn test -Dtest=TestPageNetworkSizes
|
||||
BROWSER=chromium mvn test --projects=playwright -Dtest=TestPageNetworkSizes
|
||||
```
|
||||
|
||||
### Generating API
|
||||
|
||||
@@ -11,11 +11,11 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->111.0.5563.19<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->109.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->123.0.6312.4<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->123.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/next/intro/#system-requirements) for details.
|
||||
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/intro#system-requirements) for details.
|
||||
|
||||
* [Usage](#usage)
|
||||
- [Add Maven dependency](#add-maven-dependency)
|
||||
@@ -43,7 +43,7 @@ To run Playwright simply add following dependency to your Maven project:
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>1.28.1</version>
|
||||
<version>1.41.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -51,7 +51,7 @@ To run Playwright using Gradle add following dependency to your build.gradle fil
|
||||
|
||||
```gradle
|
||||
dependencies {
|
||||
implementation group: 'com.microsoft.playwright', name: 'playwright', version: '1.28.1'
|
||||
implementation group: 'com.microsoft.playwright', name: 'playwright', version: '1.41.0'
|
||||
}
|
||||
```
|
||||
|
||||
@@ -65,7 +65,7 @@ You can find Maven project with the examples [here](./examples).
|
||||
|
||||
#### Page screenshot
|
||||
|
||||
This code snippet navigates to whatsmyuseragent.org in Chromium, Firefox and WebKit, and saves 3 screenshots.
|
||||
This code snippet navigates to Playwright homepage in Chromium, Firefox and WebKit, and saves 3 screenshots.
|
||||
|
||||
```java
|
||||
import com.microsoft.playwright.*;
|
||||
@@ -86,7 +86,7 @@ public class PageScreenshot {
|
||||
try (Browser browser = browserType.launch()) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.navigate("https://playwright.dev/");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,15 @@
|
||||
* regenerate API: `./scripts/download_driver_for_all_platforms.sh -f && ./scripts/generate_api.sh && ./scripts/update_readme.sh`
|
||||
* commit & send PR with the roll
|
||||
|
||||
### Finding driver version
|
||||
|
||||
For development versions of Playwright, you can find the latest version by looking at [publish_canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) workflow -> `publish canary NPM & Publish canary Docker` -> `build & publish driver` step -> `PACKAGE_VERSION`
|
||||
<img width="960" alt="image" src="https://github.com/microsoft/playwright-java/assets/9798949/4f33a7f1-b39a-4179-8ae7-fb1d84094c75">
|
||||
|
||||
|
||||
# Updating Version
|
||||
|
||||
```bash
|
||||
./scripts/set_maven_version.sh 1.15.0
|
||||
```
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.31.0-SNAPSHOT</version>
|
||||
<version>1.42.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
|
||||
@@ -194,7 +194,11 @@ public class DriverJar extends Driver {
|
||||
}
|
||||
}
|
||||
if (name.contains("mac os x")) {
|
||||
return "mac";
|
||||
if (arch.equals("aarch64")) {
|
||||
return "mac-arm64";
|
||||
} else {
|
||||
return "mac";
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Unexpected os.name value: " + name);
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.31.0-SNAPSHOT</version>
|
||||
<version>1.42.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver</artifactId>
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>1.31.0-SNAPSHOT</version>
|
||||
<version>1.42.0</version>
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -15,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>1.30.0</version>
|
||||
<version>1.41.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
@@ -23,7 +23,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<version>3.12.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PageScreenshot {
|
||||
try (Browser browser = browserType.launch()) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.navigate("https://playwright.dev/");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class WebKitScreenshot {
|
||||
try (Playwright playwright = Playwright.create()) {
|
||||
Browser browser = playwright.webkit().launch();
|
||||
Page page = browser.newPage();
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.navigate("https://playwright.dev/");
|
||||
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("example.png")));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.31.0-SNAPSHOT</version>
|
||||
<version>1.42.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>playwright</artifactId>
|
||||
@@ -26,7 +26,7 @@
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration combine.self="append">
|
||||
<subpackages>com.microsoft.playwright</subpackages>
|
||||
<excludePackageNames>com.microsoft.playwright.impl</excludePackageNames>
|
||||
<excludePackageNames>com.microsoft.playwright.impl,com.microsoft.playwright.junit.impl</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@@ -42,11 +42,12 @@ public interface APIRequest {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -99,20 +100,22 @@ public interface APIRequest {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
|
||||
@@ -80,8 +80,8 @@ public interface APIRequestContext {
|
||||
APIResponse delete(String url, RequestOptions params);
|
||||
/**
|
||||
* All responses returned by {@link APIRequestContext#get APIRequestContext.get()} and similar methods are stored in the
|
||||
* memory, so that you can later call {@link APIResponse#body APIResponse.body()}. This method discards all stored
|
||||
* responses, and makes {@link APIResponse#body APIResponse.body()} throw "Response disposed" error.
|
||||
* memory, so that you can later call {@link APIResponse#body APIResponse.body()}.This method discards all its resources,
|
||||
* calling any method on disposed {@code APIRequestContext} will throw an exception.
|
||||
*
|
||||
* @since v1.16
|
||||
*/
|
||||
|
||||
@@ -56,6 +56,20 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
void offDisconnected(Consumer<Browser> handler);
|
||||
|
||||
class CloseOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the browser closure.
|
||||
*/
|
||||
public String reason;
|
||||
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the browser closure.
|
||||
*/
|
||||
public CloseOptions setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class NewContextOptions {
|
||||
/**
|
||||
* Whether to automatically download all the attachments. Defaults to {@code true} where all the downloads are accepted.
|
||||
@@ -66,7 +80,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -78,7 +92,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -88,11 +102,12 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -103,11 +118,13 @@ public interface Browser extends AutoCloseable {
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -115,30 +132,35 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -213,13 +235,14 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -228,7 +251,8 @@ public interface Browser extends AutoCloseable {
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -247,7 +271,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -262,7 +286,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public NewContextOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -278,14 +302,15 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public NewContextOptions setDeviceScaleFactor(double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public NewContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -308,20 +333,23 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
*/
|
||||
public NewContextOptions setHasTouch(boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public NewContextOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
@@ -335,15 +363,17 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public NewContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
*/
|
||||
public NewContextOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
@@ -351,14 +381,17 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public NewContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
*/
|
||||
public NewContextOptions setOffline(boolean offline) {
|
||||
this.offline = offline;
|
||||
@@ -366,14 +399,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public NewContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -383,7 +416,7 @@ public interface Browser extends AutoCloseable {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -516,7 +549,8 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -525,7 +559,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public NewContextOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -540,7 +574,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -550,7 +585,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -570,7 +606,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -582,7 +618,7 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -592,11 +628,12 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
@@ -607,11 +644,13 @@ public interface Browser extends AutoCloseable {
|
||||
public Optional<ForcedColors> forcedColors;
|
||||
public Geolocation geolocation;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -619,30 +658,35 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -717,13 +761,14 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -732,7 +777,8 @@ public interface Browser extends AutoCloseable {
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -751,7 +797,7 @@ public interface Browser extends AutoCloseable {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -766,7 +812,7 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public NewPageOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -782,14 +828,15 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public NewPageOptions setDeviceScaleFactor(double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public NewPageOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
@@ -812,20 +859,23 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
*/
|
||||
public NewPageOptions setHasTouch(boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public NewPageOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public NewPageOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
@@ -839,15 +889,17 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public NewPageOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
*/
|
||||
public NewPageOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
@@ -855,14 +907,17 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public NewPageOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
*/
|
||||
public NewPageOptions setOffline(boolean offline) {
|
||||
this.offline = offline;
|
||||
@@ -870,14 +925,14 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public NewPageOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -887,7 +942,7 @@ public interface Browser extends AutoCloseable {
|
||||
return setProxy(new Proxy(server));
|
||||
}
|
||||
/**
|
||||
* Network proxy settings to use with this context.
|
||||
* Network proxy settings to use with this context. Defaults to none.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all contexts
|
||||
* override the proxy, global proxy will be never used and can be any string, for example {@code launch({ proxy: { server:
|
||||
@@ -1020,7 +1075,8 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1029,7 +1085,7 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public NewPageOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -1044,7 +1100,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -1054,7 +1111,8 @@ public interface Browser extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -1121,7 +1179,25 @@ public interface Browser extends AutoCloseable {
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void close();
|
||||
default void close() {
|
||||
close(null);
|
||||
}
|
||||
/**
|
||||
* In case this browser is obtained using {@link BrowserType#launch BrowserType.launch()}, closes the browser and all of
|
||||
* its pages (if any were opened).
|
||||
*
|
||||
* <p> In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
|
||||
* browser server.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> This is similar to force quitting the browser. Therefore, you should call {@link BrowserContext#close
|
||||
* BrowserContext.close()} on any {@code BrowserContext}'s you explicitly created earlier with {@link Browser#newContext
|
||||
* Browser.newContext()} **before** calling {@link Browser#close Browser.close()}.
|
||||
*
|
||||
* <p> The {@code Browser} object itself is considered to be disposed and cannot be used anymore.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void close(CloseOptions options);
|
||||
/**
|
||||
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
||||
*
|
||||
@@ -1142,6 +1218,14 @@ public interface Browser extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
boolean isConnected();
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP Sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> Returns the newly created browser session.
|
||||
*
|
||||
* @since v1.11
|
||||
*/
|
||||
CDPSession newBrowserCDPSession();
|
||||
/**
|
||||
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -57,6 +58,51 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offClose(Consumer<BrowserContext> handler);
|
||||
|
||||
/**
|
||||
* Emitted when JavaScript within the page calls one of console API methods, e.g. {@code console.log} or {@code
|
||||
* console.dir}.
|
||||
*
|
||||
* <p> The arguments passed into {@code console.log} and the page are available on the {@code ConsoleMessage} event handler
|
||||
* argument.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.onConsoleMessage(msg -> {
|
||||
* for (int i = 0; i < msg.args().size(); ++i)
|
||||
* System.out.println(i + ": " + msg.args().get(i).jsonValue());
|
||||
* });
|
||||
* page.evaluate("() => console.log('hello', 5, { foo: 'bar' })");
|
||||
* }</pre>
|
||||
*/
|
||||
void onConsoleMessage(Consumer<ConsoleMessage> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onConsoleMessage onConsoleMessage(handler)}.
|
||||
*/
|
||||
void offConsoleMessage(Consumer<ConsoleMessage> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a JavaScript dialog appears, such as {@code alert}, {@code prompt}, {@code confirm} or {@code
|
||||
* beforeunload}. Listener **must** either {@link Dialog#accept Dialog.accept()} or {@link Dialog#dismiss Dialog.dismiss()}
|
||||
* the dialog - otherwise the page will <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking">freeze</a> waiting for the
|
||||
* dialog, and actions like click will never finish.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.onDialog(dialog -> {
|
||||
* dialog.accept();
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> When no {@link Page#onDialog Page.onDialog()} or {@link BrowserContext#onDialog BrowserContext.onDialog()} listeners are
|
||||
* present, all dialogs are automatically dismissed.
|
||||
*/
|
||||
void onDialog(Consumer<Dialog> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onDialog onDialog(handler)}.
|
||||
*/
|
||||
void offDialog(Consumer<Dialog> handler);
|
||||
|
||||
/**
|
||||
* The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
|
||||
* also fire for popup pages. See also {@link Page#onPopup Page.onPopup()} to receive events about popups relevant to a
|
||||
@@ -81,6 +127,16 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offPage(Consumer<Page> handler);
|
||||
|
||||
/**
|
||||
* Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular page,
|
||||
* use {@link Page#onPageError Page.onPageError()} instead.
|
||||
*/
|
||||
void onWebError(Consumer<WebError> handler);
|
||||
/**
|
||||
* Removes handler that was previously added with {@link #onWebError onWebError(handler)}.
|
||||
*/
|
||||
void offWebError(Consumer<WebError> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only
|
||||
* listen for requests from a particular page, use {@link Page#onRequest Page.onRequest()}.
|
||||
@@ -130,6 +186,20 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void offResponse(Consumer<Response> handler);
|
||||
|
||||
class CloseOptions {
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context closure.
|
||||
*/
|
||||
public String reason;
|
||||
|
||||
/**
|
||||
* The reason to be reported to the operations interrupted by the context closure.
|
||||
*/
|
||||
public CloseOptions setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
@@ -189,6 +259,17 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* written to disk when {@link BrowserContext#close BrowserContext.close()} is called.
|
||||
*/
|
||||
public Boolean update;
|
||||
/**
|
||||
* Optional setting to control resource content management. If {@code attach} is specified, resources are persisted as
|
||||
* separate files or entries in the ZIP archive. If {@code embed} is specified, content is stored inline the HAR file.
|
||||
*/
|
||||
public RouteFromHarUpdateContentPolicy updateContent;
|
||||
/**
|
||||
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
|
||||
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
|
||||
* minimal}.
|
||||
*/
|
||||
public HarMode updateMode;
|
||||
/**
|
||||
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
|
||||
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
|
||||
@@ -215,6 +296,23 @@ public interface BrowserContext extends AutoCloseable {
|
||||
this.update = update;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Optional setting to control resource content management. If {@code attach} is specified, resources are persisted as
|
||||
* separate files or entries in the ZIP archive. If {@code embed} is specified, content is stored inline the HAR file.
|
||||
*/
|
||||
public RouteFromHAROptions setUpdateContent(RouteFromHarUpdateContentPolicy updateContent) {
|
||||
this.updateContent = updateContent;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
|
||||
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
|
||||
* minimal}.
|
||||
*/
|
||||
public RouteFromHAROptions setUpdateMode(HarMode updateMode) {
|
||||
this.updateMode = updateMode;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
|
||||
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
|
||||
@@ -248,6 +346,51 @@ public interface BrowserContext extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class WaitForConditionOptions {
|
||||
/**
|
||||
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
|
||||
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or
|
||||
* {@link Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
|
||||
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or
|
||||
* {@link Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public WaitForConditionOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class WaitForConsoleMessageOptions {
|
||||
/**
|
||||
* Receives the {@code ConsoleMessage} object and resolves to truthy value when the waiting should resolve.
|
||||
*/
|
||||
public Predicate<ConsoleMessage> predicate;
|
||||
/**
|
||||
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
|
||||
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Receives the {@code ConsoleMessage} object and resolves to truthy value when the waiting should resolve.
|
||||
*/
|
||||
public WaitForConsoleMessageOptions setPredicate(Predicate<ConsoleMessage> predicate) {
|
||||
this.predicate = predicate;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
|
||||
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
|
||||
*/
|
||||
public WaitForConsoleMessageOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class WaitForPageOptions {
|
||||
/**
|
||||
* Receives the {@code Page} object and resolves to truthy value when the waiting should resolve.
|
||||
@@ -284,6 +427,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
|
||||
* }</pre>
|
||||
*
|
||||
* @param cookies Adds cookies to the browser context.
|
||||
*
|
||||
* <p> For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com".
|
||||
* @since v1.8
|
||||
*/
|
||||
void addCookies(List<Cookie> cookies);
|
||||
@@ -372,7 +518,17 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void close();
|
||||
default void close() {
|
||||
close(null);
|
||||
}
|
||||
/**
|
||||
* Closes the browser context. All the pages that belong to the browser context will be closed.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The default browser context cannot be closed.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void close(CloseOptions options);
|
||||
/**
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
||||
* are returned.
|
||||
@@ -630,6 +786,26 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
void grantPermissions(List<String> permissions, GrantPermissionsOptions options);
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> Returns the newly created session.
|
||||
*
|
||||
* @param page Target to create new session for. For backwards-compatibility, this parameter is named {@code page}, but it can be a
|
||||
* {@code Page} or {@code Frame} type.
|
||||
* @since v1.11
|
||||
*/
|
||||
CDPSession newCDPSession(Page page);
|
||||
/**
|
||||
* <strong>NOTE:</strong> CDP sessions are only supported on Chromium-based browsers.
|
||||
*
|
||||
* <p> Returns the newly created session.
|
||||
*
|
||||
* @param page Target to create new session for. For backwards-compatibility, this parameter is named {@code page}, but it can be a
|
||||
* {@code Page} or {@code Frame} type.
|
||||
* @since v1.11
|
||||
*/
|
||||
CDPSession newCDPSession(Frame page);
|
||||
/**
|
||||
* Creates a new page in the browser context.
|
||||
*
|
||||
@@ -974,7 +1150,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void route(Predicate<String> url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
*
|
||||
* <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
@@ -989,7 +1165,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
/**
|
||||
* If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
|
||||
* href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
|
||||
* href="https://playwright.dev/java/docs/mock#replaying-from-har">Replaying from HAR</a>.
|
||||
*
|
||||
* <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
@@ -1084,6 +1260,13 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.12
|
||||
*/
|
||||
Tracing tracing();
|
||||
/**
|
||||
* Removes all routes created with {@link BrowserContext#route BrowserContext.route()} and {@link
|
||||
* BrowserContext#routeFromHAR BrowserContext.routeFromHAR()}.
|
||||
*
|
||||
* @since v1.41
|
||||
*/
|
||||
void unrouteAll();
|
||||
/**
|
||||
* Removes a route created with {@link BrowserContext#route BrowserContext.route()}. When {@code handler} is not specified,
|
||||
* removes all routes for the {@code url}.
|
||||
@@ -1147,6 +1330,76 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* @since v1.8
|
||||
*/
|
||||
void unroute(Predicate<String> url, Consumer<Route> handler);
|
||||
/**
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Use the method to wait for a condition that depends on page events:
|
||||
* <pre>{@code
|
||||
* List<String> failedUrls = new ArrayList<>();
|
||||
* context.onResponse(response -> {
|
||||
* if (!response.ok()) {
|
||||
* failedUrls.add(response.url());
|
||||
* }
|
||||
* });
|
||||
* page1.getByText("Create user").click();
|
||||
* page2.getByText("Submit button").click();
|
||||
* context.waitForCondition(() -> failedUrls.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Condition to wait for.
|
||||
* @since v1.32
|
||||
*/
|
||||
default void waitForCondition(BooleanSupplier condition) {
|
||||
waitForCondition(condition, null);
|
||||
}
|
||||
/**
|
||||
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
|
||||
* waiting for the condition.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Use the method to wait for a condition that depends on page events:
|
||||
* <pre>{@code
|
||||
* List<String> failedUrls = new ArrayList<>();
|
||||
* context.onResponse(response -> {
|
||||
* if (!response.ok()) {
|
||||
* failedUrls.add(response.url());
|
||||
* }
|
||||
* });
|
||||
* page1.getByText("Create user").click();
|
||||
* page2.getByText("Submit button").click();
|
||||
* context.waitForCondition(() -> failedUrls.size() > 3);
|
||||
* }</pre>
|
||||
*
|
||||
* @param condition Condition to wait for.
|
||||
* @since v1.32
|
||||
*/
|
||||
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
|
||||
/**
|
||||
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the pages in the context. If predicate is
|
||||
* provided, it passes {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code
|
||||
* predicate(message)} to return a truthy value. Will throw an error if the page is closed before the {@link
|
||||
* BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
|
||||
*
|
||||
* @param callback Callback that performs the action triggering the event.
|
||||
* @since v1.34
|
||||
*/
|
||||
default ConsoleMessage waitForConsoleMessage(Runnable callback) {
|
||||
return waitForConsoleMessage(null, callback);
|
||||
}
|
||||
/**
|
||||
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the pages in the context. If predicate is
|
||||
* provided, it passes {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code
|
||||
* predicate(message)} to return a truthy value. Will throw an error if the page is closed before the {@link
|
||||
* BrowserContext#onConsoleMessage BrowserContext.onConsoleMessage()} event is fired.
|
||||
*
|
||||
* @param callback Callback that performs the action triggering the event.
|
||||
* @since v1.34
|
||||
*/
|
||||
ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable callback);
|
||||
/**
|
||||
* Performs action and waits for a new {@code Page} to be created in the context. If predicate is provided, it passes
|
||||
* {@code Page} value into the {@code predicate} function and waits for {@code predicate(event)} to return a truthy value.
|
||||
|
||||
@@ -43,6 +43,26 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface BrowserType {
|
||||
class ConnectOptions {
|
||||
/**
|
||||
* This option exposes network available on the connecting client to the browser being connected to. Consists of a list of
|
||||
* rules separated by comma.
|
||||
*
|
||||
* <p> Available rules:
|
||||
* <ol>
|
||||
* <li> Hostname pattern, for example: {@code example.com}, {@code *.org:99}, {@code x.*.y.com}, {@code *foo.org}.</li>
|
||||
* <li> IP literal, for example: {@code 127.0.0.1}, {@code 0.0.0.0:99}, {@code [::1]}, {@code [0:0::1]:99}.</li>
|
||||
* <li> {@code <loopback>} that matches local loopback interfaces: {@code localhost}, {@code *.localhost}, {@code 127.0.0.1},
|
||||
* {@code [::1]}.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p> Some common examples:
|
||||
* <ol>
|
||||
* <li> {@code "*"} to expose all network.</li>
|
||||
* <li> {@code "<loopback>"} to expose localhost network.</li>
|
||||
* <li> {@code "*.test.internal-domain,*.staging.internal-domain,<loopback>"} to expose test/staging deployments and localhost.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public String exposeNetwork;
|
||||
/**
|
||||
* Additional HTTP headers to be sent with web socket connect request. Optional.
|
||||
*/
|
||||
@@ -57,6 +77,29 @@ public interface BrowserType {
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* This option exposes network available on the connecting client to the browser being connected to. Consists of a list of
|
||||
* rules separated by comma.
|
||||
*
|
||||
* <p> Available rules:
|
||||
* <ol>
|
||||
* <li> Hostname pattern, for example: {@code example.com}, {@code *.org:99}, {@code x.*.y.com}, {@code *foo.org}.</li>
|
||||
* <li> IP literal, for example: {@code 127.0.0.1}, {@code 0.0.0.0:99}, {@code [::1]}, {@code [0:0::1]:99}.</li>
|
||||
* <li> {@code <loopback>} that matches local loopback interfaces: {@code localhost}, {@code *.localhost}, {@code 127.0.0.1},
|
||||
* {@code [::1]}.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p> Some common examples:
|
||||
* <ol>
|
||||
* <li> {@code "*"} to expose all network.</li>
|
||||
* <li> {@code "<loopback>"} to expose localhost network.</li>
|
||||
* <li> {@code "*.test.internal-domain,*.staging.internal-domain,<loopback>"} to expose test/staging deployments and localhost.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public ConnectOptions setExposeNetwork(String exposeNetwork) {
|
||||
this.exposeNetwork = exposeNetwork;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Additional HTTP headers to be sent with web socket connect request. Optional.
|
||||
*/
|
||||
@@ -122,8 +165,10 @@ public interface BrowserType {
|
||||
}
|
||||
class LaunchOptions {
|
||||
/**
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
@@ -210,8 +255,10 @@ public interface BrowserType {
|
||||
public Path tracesDir;
|
||||
|
||||
/**
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public LaunchOptions setArgs(List<String> args) {
|
||||
this.args = args;
|
||||
@@ -373,8 +420,10 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean acceptDownloads;
|
||||
/**
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public List<String> args;
|
||||
/**
|
||||
@@ -382,7 +431,7 @@ public interface BrowserType {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -394,7 +443,7 @@ public interface BrowserType {
|
||||
*/
|
||||
public String baseURL;
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
@@ -414,7 +463,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public Double deviceScaleFactor;
|
||||
/**
|
||||
@@ -439,9 +489,14 @@ public interface BrowserType {
|
||||
*/
|
||||
public Path executablePath;
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public Map<String, String> extraHTTPHeaders;
|
||||
/**
|
||||
* Firefox user preferences. Learn more about the Firefox user preferences at <a
|
||||
* href="https://support.mozilla.org/en-US/kb/about-config-editor-firefox">{@code about:config}</a>.
|
||||
*/
|
||||
public Map<String, Object> firefoxUserPrefs;
|
||||
/**
|
||||
* Emulates {@code "forced-colors"} media feature, supported values are {@code "active"}, {@code "none"}. See {@link
|
||||
* Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
@@ -462,7 +517,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean handleSIGTERM;
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean hasTouch;
|
||||
/**
|
||||
@@ -473,7 +529,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public HttpCredentials httpCredentials;
|
||||
/**
|
||||
@@ -491,26 +548,31 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
*/
|
||||
public Boolean offline;
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public List<String> permissions;
|
||||
/**
|
||||
@@ -578,7 +640,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
@@ -589,7 +652,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public String timezoneId;
|
||||
/**
|
||||
@@ -602,7 +665,8 @@ public interface BrowserType {
|
||||
public String userAgent;
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -617,8 +681,10 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="http://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
* <strong>NOTE:</strong> Use custom browser args at your own risk, as some of them may break Playwright functionality.
|
||||
*
|
||||
* <p> Additional arguments to pass to the browser instance. The list of Chromium flags can be found <a
|
||||
* href="https://peter.sh/experiments/chromium-command-line-switches/">here</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setArgs(List<String> args) {
|
||||
this.args = args;
|
||||
@@ -629,7 +695,7 @@ public interface BrowserType {
|
||||
* Page.waitForURL()}, {@link Page#waitForRequest Page.waitForRequest()}, or {@link Page#waitForResponse
|
||||
* Page.waitForResponse()} it takes the base URL in consideration by using the <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">{@code URL()}</a> constructor for building the
|
||||
* corresponding URL. Examples:
|
||||
* corresponding URL. Unset by default. Examples:
|
||||
* <ul>
|
||||
* <li> baseURL: {@code http://localhost:3000} and navigating to {@code /bar.html} results in {@code
|
||||
* http://localhost:3000/bar.html}</li>
|
||||
@@ -644,7 +710,7 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Toggles bypassing page's Content-Security-Policy.
|
||||
* Toggles bypassing page's Content-Security-Policy. Defaults to {@code false}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setBypassCSP(boolean bypassCSP) {
|
||||
this.bypassCSP = bypassCSP;
|
||||
@@ -686,7 +752,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}.
|
||||
* Specify device scale factor (can be thought of as dpr). Defaults to {@code 1}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">emulating devices with device scale factor</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setDeviceScaleFactor(double deviceScaleFactor) {
|
||||
this.deviceScaleFactor = deviceScaleFactor;
|
||||
@@ -726,12 +793,20 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* An object containing additional HTTP headers to be sent with every request.
|
||||
* An object containing additional HTTP headers to be sent with every request. Defaults to none.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setExtraHTTPHeaders(Map<String, String> extraHTTPHeaders) {
|
||||
this.extraHTTPHeaders = extraHTTPHeaders;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Firefox user preferences. Learn more about the Firefox user preferences at <a
|
||||
* href="https://support.mozilla.org/en-US/kb/about-config-editor-firefox">{@code about:config}</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setFirefoxUserPrefs(Map<String, Object> firefoxUserPrefs) {
|
||||
this.firefoxUserPrefs = firefoxUserPrefs;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "forced-colors"} media feature, supported values are {@code "active"}, {@code "none"}. See {@link
|
||||
* Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
@@ -770,7 +845,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specifies if viewport supports touch events. Defaults to false.
|
||||
* Specifies if viewport supports touch events. Defaults to false. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#devices">mobile emulation</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHasTouch(boolean hasTouch) {
|
||||
this.hasTouch = hasTouch;
|
||||
@@ -787,13 +863,15 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHttpCredentials(String username, String password) {
|
||||
return setHttpCredentials(new HttpCredentials(username, password));
|
||||
}
|
||||
/**
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>.
|
||||
* Credentials for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a>. If
|
||||
* no origin is specified, the username and password are sent to any servers upon unauthorized responses.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHttpCredentials(HttpCredentials httpCredentials) {
|
||||
this.httpCredentials = httpCredentials;
|
||||
@@ -823,15 +901,17 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. isMobile is a part of device,
|
||||
* so you don't actually need to set it manually. Defaults to {@code false} and is not supported in Firefox. Learn more
|
||||
* about <a href="https://playwright.dev/java/docs/emulation#ismobile">mobile emulation</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}.
|
||||
* Whether or not to enable JavaScript in the context. Defaults to {@code true}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#javascript-enabled">disabling JavaScript</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setJavaScriptEnabled(boolean javaScriptEnabled) {
|
||||
this.javaScriptEnabled = javaScriptEnabled;
|
||||
@@ -839,14 +919,17 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules. Defaults to the system default
|
||||
* locale. Learn more about emulation in our <a
|
||||
* href="https://playwright.dev/java/docs/emulation#locale--timezone">emulation guide</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether to emulate network being offline. Defaults to {@code false}.
|
||||
* Whether to emulate network being offline. Defaults to {@code false}. Learn more about <a
|
||||
* href="https://playwright.dev/java/docs/emulation#offline">network emulation</a>.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setOffline(boolean offline) {
|
||||
this.offline = offline;
|
||||
@@ -854,7 +937,7 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* A list of permissions to grant to all pages in this context. See {@link BrowserContext#grantPermissions
|
||||
* BrowserContext.grantPermissions()} for more details.
|
||||
* BrowserContext.grantPermissions()} for more details. Defaults to none.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
@@ -986,7 +1069,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
* affect any Locator APIs (Locators are always strict). Defaults to {@code false}. See {@code Locator} to learn more about
|
||||
* the strict mode.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1003,7 +1087,7 @@ public interface BrowserType {
|
||||
/**
|
||||
* Changes the timezone of the context. See <a
|
||||
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
|
||||
* metaZones.txt</a> for a list of supported timezone IDs.
|
||||
* metaZones.txt</a> for a list of supported timezone IDs. Defaults to the system timezone.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setTimezoneId(String timezoneId) {
|
||||
this.timezoneId = timezoneId;
|
||||
@@ -1025,7 +1109,8 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
@@ -1035,7 +1120,8 @@ public interface BrowserType {
|
||||
}
|
||||
/**
|
||||
* Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Use {@code null} to disable the consistent
|
||||
* viewport emulation.
|
||||
* viewport emulation. Learn more about <a href="https://playwright.dev/java/docs/emulation#viewport">viewport
|
||||
* emulation</a>.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The {@code null} value opts out from the default presets, makes viewport depend on the host window size defined by the
|
||||
* operating system. It makes the execution of the tests non-deterministic.
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
* The {@code CDPSession} instances are used to talk raw Chrome Devtools Protocol:
|
||||
* <ul>
|
||||
* <li> protocol methods can be called with {@code session.send} method.</li>
|
||||
* <li> protocol events can be subscribed to with {@code session.on} method.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Useful links:
|
||||
* <ul>
|
||||
* <li> Documentation on DevTools Protocol can be found here: <a
|
||||
* href="https://chromedevtools.github.io/devtools-protocol/">DevTools Protocol Viewer</a>.</li>
|
||||
* <li> Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md</li>
|
||||
* <pre>{@code
|
||||
* CDPSession client = page.context().newCDPSession(page);
|
||||
* client.send("Runtime.enable");
|
||||
*
|
||||
* client.on("Animation.animationCreated", (event) -> System.out.println("Animation created!"));
|
||||
*
|
||||
* JsonObject response = client.send("Animation.getPlaybackRate");
|
||||
* double playbackRate = response.get("playbackRate").getAsDouble();
|
||||
* System.out.println("playback rate is " + playbackRate);
|
||||
*
|
||||
* JsonObject params = new JsonObject();
|
||||
* params.addProperty("playbackRate", playbackRate / 2);
|
||||
* client.send("Animation.setPlaybackRate", params);
|
||||
* }</pre>
|
||||
* </ul>
|
||||
*/
|
||||
public interface CDPSession {
|
||||
/**
|
||||
* Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
||||
* send messages.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
void detach();
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param method Protocol method name.
|
||||
* @since v1.8
|
||||
*/
|
||||
default JsonObject send(String method) {
|
||||
return send(method, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param method Protocol method name.
|
||||
* @param args Optional method parameters.
|
||||
* @since v1.8
|
||||
*/
|
||||
JsonObject send(String method, JsonObject args);
|
||||
/**
|
||||
* Register an event handler for events with the specified event name. The given handler will be called for every event
|
||||
* with the given name.
|
||||
*
|
||||
* @param eventName CDP event name.
|
||||
* @param handler Event handler.
|
||||
* @since v1.37
|
||||
*/
|
||||
void on(String eventName, Consumer<JsonObject> handler);
|
||||
/**
|
||||
* Unregister an event handler for events with the specified event name. The given handler will not be called anymore for
|
||||
* events with the given name.
|
||||
*
|
||||
* @param eventName CDP event name.
|
||||
* @param handler Event handler.
|
||||
* @since v1.37
|
||||
*/
|
||||
void off(String eventName, Consumer<JsonObject> handler);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,12 @@ public interface ConsoleMessage {
|
||||
* @since v1.8
|
||||
*/
|
||||
String location();
|
||||
/**
|
||||
* The page that produced this console message, if any.
|
||||
*
|
||||
* @since v1.34
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* The text of the console message.
|
||||
*
|
||||
|
||||
@@ -81,6 +81,12 @@ public interface Dialog {
|
||||
* @since v1.8
|
||||
*/
|
||||
String message();
|
||||
/**
|
||||
* The page that initiated this dialog, if available.
|
||||
*
|
||||
* @since v1.34
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Returns dialog's type, can be one of {@code alert}, {@code beforeunload}, {@code confirm} or {@code prompt}.
|
||||
*
|
||||
|
||||
@@ -24,14 +24,16 @@ import java.nio.file.Path;
|
||||
*
|
||||
* <p> All the downloaded files belonging to the browser context are deleted when the browser context is closed.
|
||||
*
|
||||
* <p> Download event is emitted once the download starts. Download path becomes available once download completes:
|
||||
* <p> Download event is emitted once the download starts. Download path becomes available once download completes.
|
||||
* <pre>{@code
|
||||
* // wait for download to start
|
||||
* // Wait for the download to start
|
||||
* Download download = page.waitForDownload(() -> {
|
||||
* page.getByText("Download file").click();
|
||||
* // Perform the action that initiates download
|
||||
* page.getByText("Download file").click();
|
||||
* });
|
||||
* // wait for download to complete
|
||||
* Path path = download.path();
|
||||
*
|
||||
* // Wait for the download process to complete and save the downloaded file somewhere
|
||||
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
|
||||
* }</pre>
|
||||
*/
|
||||
public interface Download {
|
||||
@@ -43,7 +45,7 @@ public interface Download {
|
||||
*/
|
||||
void cancel();
|
||||
/**
|
||||
* Returns readable stream for current download or {@code null} if download failed.
|
||||
* Returns a readable stream for a successful download, or throws for a failed/canceled download.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
@@ -67,8 +69,8 @@ public interface Download {
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if
|
||||
* necessary. The method throws when connected remotely.
|
||||
* Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will
|
||||
* wait for the download to finish if necessary. The method throws when connected remotely.
|
||||
*
|
||||
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()}
|
||||
* to get suggested file name.
|
||||
@@ -80,6 +82,11 @@ public interface Download {
|
||||
* Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will
|
||||
* wait for the download to finish if necessary.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
|
||||
* }</pre>
|
||||
*
|
||||
* @param path Path where the download should be copied.
|
||||
* @since v1.8
|
||||
*/
|
||||
|
||||
@@ -75,8 +75,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -120,8 +120,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public CheckOptions setTimeout(double timeout) {
|
||||
@@ -173,8 +173,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -247,8 +247,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public ClickOptions setTimeout(double timeout) {
|
||||
@@ -296,8 +296,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -363,8 +363,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public DblclickOptions setTimeout(double timeout) {
|
||||
@@ -394,8 +394,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -418,8 +418,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public FillOptions setTimeout(double timeout) {
|
||||
@@ -450,8 +450,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -503,8 +503,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public HoverOptions setTimeout(double timeout) {
|
||||
@@ -523,15 +523,15 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
class InputValueOptions {
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public InputValueOptions setTimeout(double timeout) {
|
||||
@@ -551,8 +551,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -574,8 +574,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public PressOptions setTimeout(double timeout) {
|
||||
@@ -602,9 +602,15 @@ public interface ElementHandle extends JSHandle {
|
||||
public ScreenshotCaret caret;
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public List<Locator> mask;
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public String maskColor;
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -629,8 +635,14 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public ScreenshotScale scale;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
|
||||
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
|
||||
* and applies to the inner frames.
|
||||
*/
|
||||
public String style;
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -663,12 +675,21 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
/**
|
||||
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
|
||||
* {@code #FF00FF} that completely covers its bounding box.
|
||||
* {@code #FF00FF} (customized by {@code maskColor}) that completely covers its bounding box.
|
||||
*/
|
||||
public ScreenshotOptions setMask(List<Locator> mask) {
|
||||
this.mask = mask;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify the color of the overlay box for masked elements, in <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value">CSS color format</a>. Default color is pink {@code
|
||||
* #FF00FF}.
|
||||
*/
|
||||
public ScreenshotOptions setMaskColor(String maskColor) {
|
||||
this.maskColor = maskColor;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Hides default white background and allows capturing screenshots with transparency. Not applicable to {@code jpeg}
|
||||
* images. Defaults to {@code false}.
|
||||
@@ -705,8 +726,17 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements
|
||||
* invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM
|
||||
* and applies to the inner frames.
|
||||
*/
|
||||
public ScreenshotOptions setStyle(String style) {
|
||||
this.style = style;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public ScreenshotOptions setTimeout(double timeout) {
|
||||
@@ -723,15 +753,15 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
class ScrollIntoViewIfNeededOptions {
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public ScrollIntoViewIfNeededOptions setTimeout(double timeout) {
|
||||
@@ -752,8 +782,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -776,8 +806,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public SelectOptionOptions setTimeout(double timeout) {
|
||||
@@ -792,8 +822,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean force;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -807,8 +837,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public SelectTextOptions setTimeout(double timeout) {
|
||||
@@ -834,8 +864,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -879,8 +909,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public SetCheckedOptions setTimeout(double timeout) {
|
||||
@@ -905,8 +935,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -921,8 +951,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public SetInputFilesOptions setTimeout(double timeout) {
|
||||
@@ -953,8 +983,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -1006,8 +1036,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public TapOptions setTimeout(double timeout) {
|
||||
@@ -1036,8 +1066,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -1059,8 +1089,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public TypeOptions setTimeout(double timeout) {
|
||||
@@ -1086,8 +1116,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Position position;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -1131,8 +1161,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public UncheckOptions setTimeout(double timeout) {
|
||||
@@ -1151,15 +1181,15 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
class WaitForElementStateOptions {
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public WaitForElementStateOptions setTimeout(double timeout) {
|
||||
@@ -1186,8 +1216,8 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
public Boolean strict;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -1216,8 +1246,8 @@ public interface ElementHandle extends JSHandle {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public WaitForSelectorOptions setTimeout(double timeout) {
|
||||
@@ -1396,13 +1426,17 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -1436,13 +1470,17 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> Since {@code eventInit} is event-specific, please refer to the events documentation for the lists of initial properties:
|
||||
* <ul>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent">DeviceMotionEvent</a></li>
|
||||
* <li> <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent">DeviceOrientationEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent">DragEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent">FocusEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent">KeyboardEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent">MouseEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent">PointerEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent">TouchEvent</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/Event">Event</a></li>
|
||||
* <li> <a href="https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent">WheelEvent</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> You can also specify {@code JSHandle} as the property value if you want live objects to be passed into the event:
|
||||
@@ -1567,7 +1605,7 @@ public interface ElementHandle extends JSHandle {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link ElementHandle#type ElementHandle.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.8
|
||||
@@ -1585,7 +1623,7 @@ public interface ElementHandle extends JSHandle {
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>, the control will be filled
|
||||
* instead.
|
||||
*
|
||||
* <p> To send fine-grained keyboard events, use {@link ElementHandle#type ElementHandle.type()}.
|
||||
* <p> To send fine-grained keyboard events, use {@link Locator#pressSequentially Locator.pressSequentially()}.
|
||||
*
|
||||
* @param value Value to set for the {@code <input>}, {@code <textarea>} or {@code [contenteditable]} element.
|
||||
* @since v1.8
|
||||
@@ -1741,8 +1779,8 @@ public interface ElementHandle extends JSHandle {
|
||||
* <p> If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate
|
||||
* different respective texts.
|
||||
*
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with
|
||||
* the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p> Shortcuts such as {@code key: "Control+o"}, {@code key: "Control++} or {@code key: "Control+Shift+T"} are supported as
|
||||
* well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* @param key Name of the key to press or a character to generate, such as {@code ArrowLeft} or {@code a}.
|
||||
* @since v1.8
|
||||
@@ -1771,8 +1809,8 @@ public interface ElementHandle extends JSHandle {
|
||||
* <p> If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate
|
||||
* different respective texts.
|
||||
*
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with
|
||||
* the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p> Shortcuts such as {@code key: "Control+o"}, {@code key: "Control++} or {@code key: "Control+Shift+T"} are supported as
|
||||
* well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* @param key Name of the key to press or a character to generate, such as {@code ArrowLeft} or {@code a}.
|
||||
* @since v1.8
|
||||
@@ -1863,7 +1901,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1894,7 +1932,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1923,7 +1961,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1954,7 +1992,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -1983,7 +2021,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2014,7 +2052,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2043,7 +2081,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2074,7 +2112,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2103,7 +2141,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2134,7 +2172,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2163,7 +2201,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2194,7 +2232,7 @@ public interface ElementHandle extends JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // single selection matching the value
|
||||
* // Single selection matching the value or label
|
||||
* handle.selectOption("blue");
|
||||
* // single selection matching the label
|
||||
* handle.selectOption(new SelectOption().setLabel("Blue"));
|
||||
@@ -2435,24 +2473,9 @@ public interface ElementHandle extends JSHandle {
|
||||
*/
|
||||
String textContent();
|
||||
/**
|
||||
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link ElementHandle#press
|
||||
* ElementHandle.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* elementHandle.type("Hello"); // Types instantly
|
||||
* elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* ElementHandle elementHandle = page.querySelector("input");
|
||||
* elementHandle.type("some text");
|
||||
* elementHandle.press("Enter");
|
||||
* }</pre>
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.8
|
||||
@@ -2461,24 +2484,9 @@ public interface ElementHandle extends JSHandle {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* Focuses the element, and then sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each
|
||||
* character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link ElementHandle#press
|
||||
* ElementHandle.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* elementHandle.type("Hello"); // Types instantly
|
||||
* elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
|
||||
* }</pre>
|
||||
*
|
||||
* <p> An example of typing into a text field and then submitting the form:
|
||||
* <pre>{@code
|
||||
* ElementHandle elementHandle = page.querySelector("input");
|
||||
* elementHandle.type("some text");
|
||||
* elementHandle.press("Enter");
|
||||
* }</pre>
|
||||
* @deprecated In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
*
|
||||
* @param text A text to type into a focused element.
|
||||
* @since v1.8
|
||||
@@ -2538,8 +2546,7 @@ public interface ElementHandle extends JSHandle {
|
||||
* <li> {@code "visible"} Wait until the element is <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.</li>
|
||||
* <li> {@code "hidden"} Wait until the element is <a href="https://playwright.dev/java/docs/actionability#visible">not
|
||||
* visible</a> or <a href="https://playwright.dev/java/docs/actionability#attached">not attached</a>. Note that waiting for
|
||||
* hidden does not throw when the element detaches.</li>
|
||||
* visible</a> or not attached. Note that waiting for hidden does not throw when the element detaches.</li>
|
||||
* <li> {@code "stable"} Wait until the element is both <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#stable">stable</a>.</li>
|
||||
@@ -2569,8 +2576,7 @@ public interface ElementHandle extends JSHandle {
|
||||
* <li> {@code "visible"} Wait until the element is <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a>.</li>
|
||||
* <li> {@code "hidden"} Wait until the element is <a href="https://playwright.dev/java/docs/actionability#visible">not
|
||||
* visible</a> or <a href="https://playwright.dev/java/docs/actionability#attached">not attached</a>. Note that waiting for
|
||||
* hidden does not throw when the element detaches.</li>
|
||||
* visible</a> or not attached. Note that waiting for hidden does not throw when the element detaches.</li>
|
||||
* <li> {@code "stable"} Wait until the element is both <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#stable">stable</a>.</li>
|
||||
|
||||
@@ -35,8 +35,8 @@ public interface FileChooser {
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
@@ -51,8 +51,8 @@ public interface FileChooser {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be
|
||||
* changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
|
||||
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public SetFilesOptions setTimeout(double timeout) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -285,12 +285,31 @@ public interface FrameLocator {
|
||||
}
|
||||
class LocatorOptions {
|
||||
/**
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
|
||||
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
|
||||
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
|
||||
* document root. For example, you can find {@code content} that has {@code div} in {@code
|
||||
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
|
||||
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
|
||||
* content}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator has;
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public Locator hasNot;
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public Object hasNotText;
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -299,8 +318,14 @@ public interface FrameLocator {
|
||||
public Object hasText;
|
||||
|
||||
/**
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
|
||||
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
* Narrows down the results of the method to those which contain elements matching this relative locator. For example,
|
||||
* {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the
|
||||
* document root. For example, you can find {@code content} that has {@code div} in {@code
|
||||
* <article><content><div>Playwright</div></content></article>}. However, looking for {@code content} that has {@code
|
||||
* article div} will fail, because the inner locator must be relative and should not use any elements outside the {@code
|
||||
* content}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
@@ -308,6 +333,33 @@ public interface FrameLocator {
|
||||
this.has = has;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the
|
||||
* outer one. For example, {@code article} that does not have {@code div} matches {@code
|
||||
* <article><span>Playwright</span></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
public LocatorOptions setHasNot(Locator hasNot) {
|
||||
this.hasNot = hasNot;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(String hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When
|
||||
* passed a [string], matching is case-insensitive and searches for a substring.
|
||||
*/
|
||||
public LocatorOptions setHasNotText(Pattern hasNotText) {
|
||||
this.hasNotText = hasNotText;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||
* [string], matching is case-insensitive and searches for a substring. For example, {@code "Playwright"} matches {@code
|
||||
@@ -402,12 +454,14 @@ public interface FrameLocator {
|
||||
*/
|
||||
Locator getByAltText(Pattern text, GetByAltTextOptions options);
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated label.
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the input by label text "Password" in the following DOM:
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
*
|
||||
@@ -418,12 +472,14 @@ public interface FrameLocator {
|
||||
return getByLabel(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated label.
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the input by label text "Password" in the following DOM:
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
*
|
||||
@@ -432,12 +488,14 @@ public interface FrameLocator {
|
||||
*/
|
||||
Locator getByLabel(String text, GetByLabelOptions options);
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated label.
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the input by label text "Password" in the following DOM:
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
*
|
||||
@@ -448,12 +506,14 @@ public interface FrameLocator {
|
||||
return getByLabel(text, null);
|
||||
}
|
||||
/**
|
||||
* Allows locating input elements by the text of the associated label.
|
||||
* Allows locating input elements by the text of the associated {@code <label>} or {@code aria-labelledby} element, or by
|
||||
* the {@code aria-label} attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, this method will find the input by label text "Password" in the following DOM:
|
||||
* <p> For example, this method will find inputs by label "Username" and "Password" in the following DOM:
|
||||
* <pre>{@code
|
||||
* page.getByLabel("Username").fill("john");
|
||||
* page.getByLabel("Password").fill("secret");
|
||||
* }</pre>
|
||||
*
|
||||
@@ -899,11 +959,11 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
default Locator locator(String selector) {
|
||||
return locator(selector, null);
|
||||
default Locator locator(String selectorOrLocator) {
|
||||
return locator(selectorOrLocator, null);
|
||||
}
|
||||
/**
|
||||
* The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
||||
@@ -911,10 +971,32 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
Locator locator(String selector, LocatorOptions options);
|
||||
Locator locator(String selectorOrLocator, LocatorOptions options);
|
||||
/**
|
||||
* The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
||||
* similar to {@link Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
default Locator locator(Locator selectorOrLocator) {
|
||||
return locator(selectorOrLocator, null);
|
||||
}
|
||||
/**
|
||||
* The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options,
|
||||
* similar to {@link Locator#filter Locator.filter()} method.
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selectorOrLocator A selector or locator to use when resolving DOM element.
|
||||
* @since v1.17
|
||||
*/
|
||||
Locator locator(Locator selectorOrLocator, LocatorOptions options);
|
||||
/**
|
||||
* Returns locator to the n-th matching frame. It's zero based, {@code nth(0)} selects the first frame.
|
||||
*
|
||||
|
||||
@@ -135,7 +135,7 @@ public interface JSHandle {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* JSHandle handle = page.evaluateHandle("() => ({window, document}"););
|
||||
* JSHandle handle = page.evaluateHandle("() => ({ window, document })");
|
||||
* Map<String, JSHandle> properties = handle.getProperties();
|
||||
* JSHandle windowHandle = properties.get("window");
|
||||
* JSHandle documentHandle = properties.get("document");
|
||||
|
||||
@@ -132,7 +132,9 @@ public interface Keyboard {
|
||||
*/
|
||||
void insertText(String text);
|
||||
/**
|
||||
* {@code key} can specify the intended <a
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@code key} can specify the intended <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
@@ -150,8 +152,8 @@ public interface Keyboard {
|
||||
* <p> If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate
|
||||
* different respective texts.
|
||||
*
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with
|
||||
* the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p> Shortcuts such as {@code key: "Control+o"}, {@code key: "Control++} or {@code key: "Control+Shift+T"} are supported as
|
||||
* well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -175,7 +177,9 @@ public interface Keyboard {
|
||||
press(key, null);
|
||||
}
|
||||
/**
|
||||
* {@code key} can specify the intended <a
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#press Locator.press()} instead.
|
||||
*
|
||||
* <p> {@code key} can specify the intended <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key">keyboardEvent.key</a> value or a single
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
@@ -193,8 +197,8 @@ public interface Keyboard {
|
||||
* <p> If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate
|
||||
* different respective texts.
|
||||
*
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with
|
||||
* the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p> Shortcuts such as {@code key: "Control+o"}, {@code key: "Control++} or {@code key: "Control+Shift+T"} are supported as
|
||||
* well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -216,7 +220,11 @@ public interface Keyboard {
|
||||
*/
|
||||
void press(String key, PressOptions options);
|
||||
/**
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
*
|
||||
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
@@ -239,7 +247,11 @@ public interface Keyboard {
|
||||
type(text, null);
|
||||
}
|
||||
/**
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
* <strong>NOTE:</strong> In most cases, you should use {@link Locator#fill Locator.fill()} instead. You only need to press keys one by one if
|
||||
* there is special keyboard handling on the page - in this case use {@link Locator#pressSequentially
|
||||
* Locator.pressSequentially()}.
|
||||
*
|
||||
* <p> Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -62,6 +62,22 @@ public interface Request {
|
||||
/**
|
||||
* Returns the {@code Frame} that initiated this request.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* String frameUrl = request.frame().url();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> Note that in some cases the frame is not available, and this method will throw.
|
||||
* <ul>
|
||||
* <li> When request originates in the Service Worker. You can use {@code request.serviceWorker()} to check that.</li>
|
||||
* <li> When navigation request is issued before the corresponding frame is created. You can use {@link
|
||||
* Request#isNavigationRequest Request.isNavigationRequest()} to check that.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> Here is an example that handles all the cases:
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
Frame frame();
|
||||
@@ -91,6 +107,9 @@ public interface Request {
|
||||
/**
|
||||
* Whether this request is driving frame's navigation.
|
||||
*
|
||||
* <p> Some navigation requests are issued before the corresponding frame is created, and therefore do not have {@link
|
||||
* Request#frame Request.frame()} available.
|
||||
*
|
||||
* @since v1.8
|
||||
*/
|
||||
boolean isNavigationRequest();
|
||||
|
||||
@@ -154,6 +154,10 @@ public interface Route {
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public Object postData;
|
||||
/**
|
||||
* Request timeout in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
@@ -195,6 +199,13 @@ public interface Route {
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Request timeout in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout.
|
||||
*/
|
||||
public FetchOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
|
||||
@@ -38,8 +38,9 @@ import java.nio.file.Path;
|
||||
public interface Tracing {
|
||||
class StartOptions {
|
||||
/**
|
||||
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
|
||||
* specified in {@link BrowserType#launch BrowserType.launch()}.
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stop Tracing.stop()} instead.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
@@ -66,8 +67,9 @@ public interface Tracing {
|
||||
public String title;
|
||||
|
||||
/**
|
||||
* If specified, the trace is going to be saved into the file with the given name inside the {@code tracesDir} folder
|
||||
* specified in {@link BrowserType#launch BrowserType.launch()}.
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stop Tracing.stop()} instead.
|
||||
*/
|
||||
public StartOptions setName(String name) {
|
||||
this.name = name;
|
||||
@@ -109,11 +111,26 @@ public interface Tracing {
|
||||
}
|
||||
}
|
||||
class StartChunkOptions {
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stopChunk Tracing.stopChunk()} instead.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Trace name to be shown in the Trace Viewer.
|
||||
*/
|
||||
public String title;
|
||||
|
||||
/**
|
||||
* If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the {@code
|
||||
* tracesDir} folder specified in {@link BrowserType#launch BrowserType.launch()}. To specify the final trace zip file
|
||||
* name, you need to pass {@code path} option to {@link Tracing#stopChunk Tracing.stopChunk()} instead.
|
||||
*/
|
||||
public StartChunkOptions setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Trace name to be shown in the Trace Viewer.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
|
||||
/**
|
||||
* {@code WebError} class represents an unhandled exception thrown in the page. It is dispatched via the {@link
|
||||
* BrowserContext#onWebError BrowserContext.onWebError()} event.
|
||||
* <pre>{@code
|
||||
* // Log all uncaught errors to the terminal
|
||||
* context.onWebError(webError -> {
|
||||
* System.out.println("Uncaught exception: " + webError.error());
|
||||
* });
|
||||
*
|
||||
* // Navigate to a page with an exception.
|
||||
* page.navigate("data:text/html,<script>throw new Error('Test')</script>");
|
||||
* }</pre>
|
||||
*/
|
||||
public interface WebError {
|
||||
/**
|
||||
* The page that produced this unhandled exception, if any.
|
||||
*
|
||||
* @since v1.38
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Unhandled error that was thrown.
|
||||
*
|
||||
* @since v1.38
|
||||
*/
|
||||
String error();
|
||||
}
|
||||
|
||||
+242
-78
@@ -37,10 +37,29 @@ import java.util.regex.Pattern;
|
||||
* }</pre>
|
||||
*/
|
||||
public interface LocatorAssertions {
|
||||
class IsAttachedOptions {
|
||||
public Boolean attached;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
public IsAttachedOptions setAttached(boolean attached) {
|
||||
this.attached = attached;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsAttachedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class IsCheckedOptions {
|
||||
public Boolean checked;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -49,7 +68,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsCheckedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -58,12 +77,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsDisabledOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsDisabledOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -73,7 +92,7 @@ public interface LocatorAssertions {
|
||||
class IsEditableOptions {
|
||||
public Boolean editable;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -82,7 +101,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsEditableOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -91,12 +110,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsEmptyOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsEmptyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -106,7 +125,7 @@ public interface LocatorAssertions {
|
||||
class IsEnabledOptions {
|
||||
public Boolean enabled;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -115,7 +134,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsEnabledOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -124,12 +143,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsFocusedOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsFocusedOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -138,12 +157,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsHiddenOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsHiddenOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -157,7 +176,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Double ratio;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
@@ -170,7 +189,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsInViewportOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -179,13 +198,13 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class IsVisibleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
public Boolean visible;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public IsVisibleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -203,7 +222,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -220,7 +239,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public ContainsTextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -236,12 +255,25 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasAttributeOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Whether to perform case-insensitive match. {@code ignoreCase} option takes precedence over the corresponding regular
|
||||
* expression flag if specified.
|
||||
*/
|
||||
public HasAttributeOptions setIgnoreCase(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasAttributeOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -250,12 +282,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasClassOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasClassOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -264,12 +296,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasCountOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasCountOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -278,12 +310,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasCSSOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasCSSOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -292,12 +324,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasIdOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasIdOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -306,12 +338,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasJSPropertyOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasJSPropertyOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -325,7 +357,7 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
public Boolean ignoreCase;
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -342,7 +374,7 @@ public interface LocatorAssertions {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasTextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -358,12 +390,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasValueOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasValueOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -372,12 +404,12 @@ public interface LocatorAssertions {
|
||||
}
|
||||
class HasValuesOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasValuesOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -394,6 +426,32 @@ public interface LocatorAssertions {
|
||||
* @since v1.20
|
||||
*/
|
||||
LocatorAssertions not();
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an element that is <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected">connected</a> to a Document or a ShadowRoot.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.33
|
||||
*/
|
||||
default void isAttached() {
|
||||
isAttached(null);
|
||||
}
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an element that is <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected">connected</a> to a Document or a ShadowRoot.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByText("Hidden text")).isAttached();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.33
|
||||
*/
|
||||
void isAttached(IsAttachedOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
@@ -580,7 +638,7 @@ public interface LocatorAssertions {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Locator locator = page.locator("button.submit");
|
||||
* Locator locator = page.getByRole(AriaRole.BUTTON);
|
||||
* // Make sure at least some part of element intersects viewport.
|
||||
* assertThat(locator).isInViewport();
|
||||
* // Make sure element is fully outside of viewport.
|
||||
@@ -600,7 +658,7 @@ public interface LocatorAssertions {
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Locator locator = page.locator("button.submit");
|
||||
* Locator locator = page.getByRole(AriaRole.BUTTON);
|
||||
* // Make sure at least some part of element intersects viewport.
|
||||
* assertThat(locator).isInViewport();
|
||||
* // Make sure element is fully outside of viewport.
|
||||
@@ -613,12 +671,25 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void isInViewport(IsInViewportOptions options);
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
|
||||
* and <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
* Ensures that {@code Locator} points to an attached and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* // A specific element is visible.
|
||||
* assertThat(page.getByText("Welcome")).isVisible();
|
||||
*
|
||||
* // At least one item in the list is visible.
|
||||
* asserThat(page.getByTestId("todo-item").first()).isVisible();
|
||||
*
|
||||
* // At least one of the two elements is visible, possibly both.
|
||||
* asserThat(
|
||||
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
|
||||
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .first()
|
||||
* ).isVisible();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.20
|
||||
@@ -627,20 +698,38 @@ public interface LocatorAssertions {
|
||||
isVisible(null);
|
||||
}
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a>
|
||||
* and <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
* Ensures that {@code Locator} points to an attached and <a
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> To check that at least one element from the list is visible, use {@link Locator#first Locator.first()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* // A specific element is visible.
|
||||
* assertThat(page.getByText("Welcome")).isVisible();
|
||||
*
|
||||
* // At least one item in the list is visible.
|
||||
* asserThat(page.getByTestId("todo-item").first()).isVisible();
|
||||
*
|
||||
* // At least one of the two elements is visible, possibly both.
|
||||
* asserThat(
|
||||
* page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in"))
|
||||
* .or(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")))
|
||||
* .first()
|
||||
* ).isVisible();
|
||||
* }</pre>
|
||||
*
|
||||
* @since v1.20
|
||||
*/
|
||||
void isVisible(IsVisibleOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -679,8 +768,13 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -717,8 +811,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void containsText(String expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -757,8 +856,13 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -795,8 +899,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void containsText(Pattern expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -835,8 +944,13 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -873,8 +987,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void containsText(String[] expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -913,8 +1032,13 @@ public interface LocatorAssertions {
|
||||
containsText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the
|
||||
* value as well.
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. All nested elements will be considered
|
||||
* when computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1331,8 +1455,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasJSProperty(String name, Object value, HasJSPropertyOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1371,8 +1500,13 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1409,8 +1543,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasText(String expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1449,8 +1588,13 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1487,8 +1631,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasText(Pattern expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1527,8 +1676,13 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1565,8 +1719,13 @@ public interface LocatorAssertions {
|
||||
*/
|
||||
void hasText(String[] expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
@@ -1605,8 +1764,13 @@ public interface LocatorAssertions {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as
|
||||
* well.
|
||||
* Ensures the {@code Locator} points to an element with the given text. All nested elements will be considered when
|
||||
* computing the text content of the element. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Details**
|
||||
*
|
||||
* <p> When {@code expected} parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual
|
||||
* text and in the expected string before matching. When regular expression is used, the actual text is matched as is.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
|
||||
@@ -39,12 +39,12 @@ import java.util.regex.Pattern;
|
||||
public interface PageAssertions {
|
||||
class HasTitleOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasTitleOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -53,12 +53,12 @@ public interface PageAssertions {
|
||||
}
|
||||
class HasURLOptions {
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Time to retry the assertion for.
|
||||
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
|
||||
*/
|
||||
public HasURLOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
@@ -1,8 +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.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.microsoft.playwright.APIRequestContext;
|
||||
import com.microsoft.playwright.APIResponse;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
@@ -11,6 +26,7 @@ import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.RequestOptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Base64;
|
||||
@@ -85,11 +101,14 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
byte[] bytes = null;
|
||||
if (options.data instanceof byte[]) {
|
||||
bytes = (byte[]) options.data;
|
||||
} else if (options.data instanceof String && !isJsonContentType(options.headers)) {
|
||||
bytes = ((String) options.data).getBytes(StandardCharsets.UTF_8);
|
||||
} else if (options.data instanceof String) {
|
||||
String stringData = (String) options.data;
|
||||
if (!isJsonContentType(options.headers) || isJsonParsable(stringData)) {
|
||||
bytes = (stringData).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
if (bytes == null) {
|
||||
params.add("jsonData", gson().toJsonTree(options.data));
|
||||
params.addProperty("jsonData", gson().toJson(options.data));
|
||||
} else {
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
params.addProperty("postData", base64);
|
||||
@@ -193,7 +212,7 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
|
||||
private static RequestOptionsImpl ensureOptions(RequestOptions options, String method) {
|
||||
RequestOptionsImpl impl = (RequestOptionsImpl) options;
|
||||
RequestOptionsImpl impl = Utils.clone((RequestOptionsImpl) options);
|
||||
if (impl == null) {
|
||||
impl = new RequestOptionsImpl();
|
||||
}
|
||||
@@ -202,4 +221,21 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
|
||||
}
|
||||
return impl;
|
||||
}
|
||||
|
||||
private static boolean isJsonParsable(String value) {
|
||||
try {
|
||||
JsonElement result = JsonParser.parseString(value);
|
||||
if (result != null && result.isJsonPrimitive()) {
|
||||
JsonPrimitive primitive = result.getAsJsonPrimitive();
|
||||
if (primitive.isString() && value.equals(primitive.getAsString())) {
|
||||
// Gson parses unquoted strings too, but we don't want to treat them
|
||||
// as valid JSON.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (JsonSyntaxException error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.Gson;
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.microsoft.playwright.impl;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
@@ -32,13 +34,24 @@ class ArtifactImpl extends ChannelOwner {
|
||||
|
||||
public InputStream createReadStream() {
|
||||
JsonObject result = sendMessage("stream").getAsJsonObject();
|
||||
if (!result.has("stream")) {
|
||||
return null;
|
||||
}
|
||||
Stream stream = connection.getExistingObject(result.getAsJsonObject("stream").get("guid").getAsString());
|
||||
return stream.stream();
|
||||
}
|
||||
|
||||
byte[] readAllBytes() {
|
||||
final int bufLen = 1024 * 1024;
|
||||
byte[] buf = new byte[bufLen];
|
||||
int readLen;
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); InputStream stream = createReadStream()) {
|
||||
while ((readLen = stream.read(buf, 0, bufLen)) != -1) {
|
||||
outputStream.write(buf, 0, readLen);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read artifact", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
sendMessage("cancel");
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -46,11 +47,16 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
private final APIRequestContextImpl request;
|
||||
final List<PageImpl> pages = new ArrayList<>();
|
||||
final Router routes = new Router();
|
||||
private boolean isClosedOrClosing;
|
||||
private boolean closeWasCalled;
|
||||
private final WaitableEvent<EventType, ?> closePromise;
|
||||
final Map<String, BindingCallback> bindings = new HashMap<>();
|
||||
PageImpl ownerPage;
|
||||
private String closeReason;
|
||||
|
||||
private static final Map<EventType, String> eventSubscriptions() {
|
||||
Map<EventType, String> result = new HashMap<>();
|
||||
result.put(EventType.CONSOLE, "console");
|
||||
result.put(EventType.DIALOG, "dialog");
|
||||
result.put(EventType.REQUEST, "request");
|
||||
result.put(EventType.RESPONSE, "response");
|
||||
result.put(EventType.REQUESTFINISHED, "requestFinished");
|
||||
@@ -75,7 +81,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
CONSOLE,
|
||||
DIALOG,
|
||||
PAGE,
|
||||
WEBERROR,
|
||||
REQUEST,
|
||||
REQUESTFAILED,
|
||||
REQUESTFINISHED,
|
||||
@@ -89,8 +98,9 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
} else {
|
||||
browser = null;
|
||||
}
|
||||
this.tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
this.request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
|
||||
tracing = connection.getExistingObject(initializer.getAsJsonObject("tracing").get("guid").getAsString());
|
||||
request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
|
||||
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
|
||||
}
|
||||
|
||||
void setRecordHar(Path path, HarContentPolicy policy) {
|
||||
@@ -107,6 +117,16 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
}
|
||||
|
||||
String effectiveCloseReason() {
|
||||
if (closeReason != null) {
|
||||
return closeReason;
|
||||
}
|
||||
if (browser != null) {
|
||||
return browser.closeReason;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<BrowserContext> handler) {
|
||||
listeners.add(EventType.CLOSE, handler);
|
||||
@@ -117,6 +137,26 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.remove(EventType.CLOSE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsoleMessage(Consumer<ConsoleMessage> handler) {
|
||||
listeners.add(EventType.CONSOLE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offConsoleMessage(Consumer<ConsoleMessage> handler) {
|
||||
listeners.remove(EventType.CONSOLE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialog(Consumer<Dialog> handler) {
|
||||
listeners.add(EventType.DIALOG, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offDialog(Consumer<Dialog> handler) {
|
||||
listeners.remove(EventType.DIALOG, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPage(Consumer<Page> handler) {
|
||||
listeners.add(EventType.PAGE, handler);
|
||||
@@ -127,6 +167,16 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
listeners.remove(EventType.PAGE, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebError(Consumer<WebError> handler) {
|
||||
listeners.add(EventType.WEBERROR, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offWebError(Consumer<WebError> handler) {
|
||||
listeners.remove(EventType.WEBERROR, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequest(Consumer<Request> handler) {
|
||||
listeners.add(EventType.REQUEST, handler);
|
||||
@@ -188,8 +238,24 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
withLogging("BrowserContext.close", () -> closeImpl());
|
||||
public CDPSession newCDPSession(Page page) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.add("page", ((PageImpl) page).toProtocolRef());
|
||||
JsonObject result = sendMessage("newCDPSession", params).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDPSession newCDPSession(Frame frame) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.add("frame", ((FrameImpl) frame).toProtocolRef());
|
||||
JsonObject result = sendMessage("newCDPSession", params).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
withLogging("BrowserContext.close", () -> closeImpl(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,12 +263,13 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
|
||||
}
|
||||
|
||||
private void closeImpl() {
|
||||
if (isClosedOrClosing) {
|
||||
return;
|
||||
}
|
||||
isClosedOrClosing = true;
|
||||
try {
|
||||
private void closeImpl(CloseOptions options) {
|
||||
if (!closeWasCalled) {
|
||||
closeWasCalled = true;
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
for (Map.Entry<String, HarRecorder> entry : harRecorders.entrySet()) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("harId", entry.getKey());
|
||||
@@ -224,13 +291,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
artifact.delete();
|
||||
}
|
||||
|
||||
sendMessage("close");
|
||||
} catch (PlaywrightException e) {
|
||||
if (!isSafeCloseError(e)) {
|
||||
throw e;
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("close", params);
|
||||
}
|
||||
runUntil(() -> {}, closePromise);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -410,8 +474,12 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
}
|
||||
JsonObject jsonOptions = new JsonObject();
|
||||
jsonOptions.addProperty("path", har.toAbsolutePath().toString());
|
||||
jsonOptions.addProperty("content", HarContentPolicy.ATTACH.name().toLowerCase());
|
||||
jsonOptions.addProperty("mode", HarMode.MINIMAL.name().toLowerCase());
|
||||
jsonOptions.addProperty("content", options.updateContent == null ?
|
||||
HarContentPolicy.ATTACH.name().toLowerCase() :
|
||||
options.updateContent.name().toLowerCase());
|
||||
jsonOptions.addProperty("mode", options.updateMode == null ?
|
||||
HarMode.MINIMAL.name().toLowerCase() :
|
||||
options.updateMode.name().toLowerCase());
|
||||
addHarUrlFilter(jsonOptions, options.url);
|
||||
params.add("options", jsonOptions);
|
||||
JsonObject json = sendMessage("harStart", params).getAsJsonObject();
|
||||
@@ -421,6 +489,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public void setDefaultNavigationTimeout(double timeout) {
|
||||
setDefaultNavigationTimeoutImpl(timeout);
|
||||
}
|
||||
|
||||
void setDefaultNavigationTimeoutImpl(Double timeout) {
|
||||
withLogging("BrowserContext.setDefaultNavigationTimeout", () -> {
|
||||
timeoutSettings.setDefaultNavigationTimeout(timeout);
|
||||
JsonObject params = new JsonObject();
|
||||
@@ -431,6 +503,10 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public void setDefaultTimeout(double timeout) {
|
||||
setDefaultTimeoutImpl(timeout);
|
||||
}
|
||||
|
||||
void setDefaultTimeoutImpl(Double timeout) {
|
||||
withLogging("BrowserContext.setDefaultTimeout", () -> {
|
||||
timeoutSettings.setDefaultTimeout(timeout);
|
||||
JsonObject params = new JsonObject();
|
||||
@@ -492,6 +568,14 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
return tracing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unrouteAll() {
|
||||
withLogging("BrowserContext.unrouteAll", () -> {
|
||||
routes.removeAll();
|
||||
updateInterceptionPatterns();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unroute(String url, Consumer<Route> handler) {
|
||||
unroute(new UrlMatcher(this.baseUrl, url), handler);
|
||||
@@ -507,6 +591,27 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
unroute(new UrlMatcher(url), handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForCondition(BooleanSupplier predicate, WaitForConditionOptions options) {
|
||||
List<Waitable<Void>> waitables = new ArrayList<>();
|
||||
waitables.add(new WaitableContextClose<>());
|
||||
waitables.add(timeoutSettings.createWaitable(options == null ? null : options.timeout));
|
||||
waitables.add(new WaitablePredicate<>(predicate));
|
||||
runUntil(() -> {}, new WaitableRace<>(waitables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable code) {
|
||||
return withWaitLogging("BrowserContext.waitForConsoleMessage", logger -> waitForConsoleMessageImpl(options, code));
|
||||
}
|
||||
|
||||
private ConsoleMessage waitForConsoleMessageImpl(WaitForConsoleMessageOptions options, Runnable code) {
|
||||
if (options == null) {
|
||||
options = new WaitForConsoleMessageOptions();
|
||||
}
|
||||
return waitForEventWithTimeout(EventType.CONSOLE, code, options.predicate, options.timeout);
|
||||
}
|
||||
|
||||
private class WaitableContextClose<R> extends WaitableEvent<EventType, R> {
|
||||
WaitableContextClose() {
|
||||
super(BrowserContextImpl.this.listeners, EventType.CLOSE);
|
||||
@@ -514,7 +619,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
public R get() {
|
||||
throw new PlaywrightException("Context closed");
|
||||
throw new TargetClosedError(effectiveCloseReason());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,7 +640,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
updateInterceptionPatterns();
|
||||
}
|
||||
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
|
||||
route.resume();
|
||||
route.resume(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,8 +650,38 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
|
||||
@Override
|
||||
protected void handleEvent(String event, JsonObject params) {
|
||||
if ("route".equals(event)) {
|
||||
if ("dialog".equals(event)) {
|
||||
String guid = params.getAsJsonObject("dialog").get("guid").getAsString();
|
||||
DialogImpl dialog = connection.getExistingObject(guid);
|
||||
boolean hasListeners = false;
|
||||
if (listeners.hasListeners(EventType.DIALOG)) {
|
||||
hasListeners = true;
|
||||
listeners.notify(EventType.DIALOG, dialog);
|
||||
}
|
||||
PageImpl page = dialog.page();
|
||||
if (page != null) {
|
||||
if (page.listeners.hasListeners(PageImpl.EventType.DIALOG)) {
|
||||
hasListeners = true;
|
||||
page.listeners.notify(PageImpl.EventType.DIALOG, dialog);
|
||||
}
|
||||
}
|
||||
// Although we do similar handling on the server side, we still need this logic
|
||||
// on the client side due to a possible race condition between two async calls:
|
||||
// a) removing "dialog" listener subscription (client->server)
|
||||
// b) actual "dialog" event (server->client)
|
||||
if (!hasListeners) {
|
||||
if ("beforeunload".equals(dialog.type())) {
|
||||
try {
|
||||
dialog.accept();
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
} else if ("route".equals(event)) {
|
||||
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
|
||||
route.browserContext = this;
|
||||
handleRoute(route);
|
||||
} else if ("page".equals(event)) {
|
||||
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
@@ -561,6 +696,13 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
if (binding != null) {
|
||||
bindingCall.call(binding);
|
||||
}
|
||||
} else if ("console".equals(event)) {
|
||||
ConsoleMessageImpl message = new ConsoleMessageImpl(connection, params);
|
||||
listeners.notify(BrowserContextImpl.EventType.CONSOLE, message);
|
||||
PageImpl page = message.page();
|
||||
if (page != null) {
|
||||
page.listeners.notify(PageImpl.EventType.CONSOLE, message);
|
||||
}
|
||||
} else if ("request".equals(event)) {
|
||||
String guid = params.getAsJsonObject("request").get("guid").getAsString();
|
||||
RequestImpl request = connection.getExistingObject(guid);
|
||||
@@ -604,22 +746,41 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
PageImpl page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
page.listeners.notify(PageImpl.EventType.RESPONSE, response);
|
||||
}
|
||||
} else if ("pageError".equals(event)) {
|
||||
SerializedError error = gson().fromJson(params.getAsJsonObject("error"), SerializedError.class);
|
||||
String errorStr = "";
|
||||
if (error.error != null) {
|
||||
errorStr = error.error.name + ": " + error.error.message;
|
||||
if (error.error.stack != null && !error.error.stack.isEmpty()) {
|
||||
errorStr += "\n" + error.error.stack;
|
||||
}
|
||||
}
|
||||
PageImpl page;
|
||||
try {
|
||||
page = connection.getExistingObject(params.getAsJsonObject("page").get("guid").getAsString());
|
||||
} catch (PlaywrightException e) {
|
||||
page = null;
|
||||
}
|
||||
listeners.notify(BrowserContextImpl.EventType.WEBERROR, new WebErrorImpl(page, errorStr));
|
||||
if (page != null) {
|
||||
page.listeners.notify(PageImpl.EventType.PAGEERROR, errorStr);
|
||||
}
|
||||
} else if ("close".equals(event)) {
|
||||
didClose();
|
||||
}
|
||||
}
|
||||
|
||||
void didClose() {
|
||||
isClosedOrClosing = true;
|
||||
if (browser != null) {
|
||||
browser.contexts.remove(this);
|
||||
}
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
|
||||
WritableStream createTempFile(String name) {
|
||||
WritableStream createTempFile(String name, long lastModifiedMs) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("name", name);
|
||||
params.addProperty("lastModifiedMs", lastModifiedMs);
|
||||
JsonObject json = sendMessage("createTempFile", params).getAsJsonObject();
|
||||
return connection.getExistingObject(json.getAsJsonObject("writableStream").get("guid").getAsString());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.addHarUrlFilter;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
@@ -41,6 +40,9 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
boolean isConnectedOverWebSocket;
|
||||
private boolean isConnected = true;
|
||||
BrowserTypeImpl browserType;
|
||||
BrowserType.LaunchOptions launchOptions;
|
||||
private Path tracePath;
|
||||
String closeReason;
|
||||
|
||||
enum EventType {
|
||||
DISCONNECTED,
|
||||
@@ -66,11 +68,15 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
withLogging("Browser.close", () -> closeImpl());
|
||||
public void close(CloseOptions options) {
|
||||
withLogging("Browser.close", () -> closeImpl(options));
|
||||
}
|
||||
|
||||
private void closeImpl() {
|
||||
private void closeImpl(CloseOptions options) {
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
closeReason = options.reason;
|
||||
if (isConnectedOverWebSocket) {
|
||||
try {
|
||||
connection.close();
|
||||
@@ -182,7 +188,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
if (options.recordVideoDir != null) {
|
||||
JsonObject recordVideo = new JsonObject();
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toString());
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
|
||||
if (options.recordVideoSize != null) {
|
||||
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
|
||||
}
|
||||
@@ -202,6 +208,10 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
params.addProperty("noDefaultViewport", true);
|
||||
}
|
||||
}
|
||||
params.remove("acceptDownloads");
|
||||
if (options.acceptDownloads != null) {
|
||||
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
|
||||
}
|
||||
JsonElement result = sendMessage("newContext", params);
|
||||
BrowserContextImpl context = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("context").get("guid").getAsString());
|
||||
context.videosDir = options.recordVideoDir;
|
||||
@@ -209,6 +219,9 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
context.setBaseUrl(options.baseURL);
|
||||
}
|
||||
context.setRecordHar(recordHarPath, harContentPolicy);
|
||||
if (launchOptions != null) {
|
||||
context.tracing().setTracesDir(launchOptions.tracesDir);
|
||||
}
|
||||
contexts.add(context);
|
||||
return context;
|
||||
}
|
||||
@@ -227,6 +240,7 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
if (options == null) {
|
||||
options = new StartTracingOptions();
|
||||
}
|
||||
tracePath = options.path;
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
if (page != null) {
|
||||
params.add("page", ((PageImpl) page).toProtocolRef());
|
||||
@@ -241,7 +255,20 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
|
||||
private byte[] stopTracingImpl() {
|
||||
JsonObject json = sendMessage("stopTracing").getAsJsonObject();
|
||||
return Base64.getDecoder().decode(json.get("binary").getAsString());
|
||||
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject().getAsJsonObject("artifact").get("guid").getAsString());
|
||||
byte[] data = artifact.readAllBytes();
|
||||
artifact.delete();
|
||||
if (tracePath != null) {
|
||||
try {
|
||||
Files.createDirectories(tracePath.getParent());
|
||||
Files.write(tracePath, data);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to write trace file", e);
|
||||
} finally {
|
||||
tracePath = null;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private Page newPageImpl(NewPageOptions options) {
|
||||
@@ -272,6 +299,13 @@ class BrowserImpl extends ChannelOwner implements Browser {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CDPSession newBrowserCDPSession() {
|
||||
JsonObject params = new JsonObject();
|
||||
JsonObject result = sendMessage("newBrowserCDPSession", params).getAsJsonObject();
|
||||
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
|
||||
}
|
||||
|
||||
private void didClose() {
|
||||
isConnected = false;
|
||||
listeners.notify(EventType.DISCONNECTED, this);
|
||||
|
||||
@@ -33,8 +33,6 @@ import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
|
||||
class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
LocalUtils localUtils;
|
||||
|
||||
BrowserTypeImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
@@ -52,6 +50,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
JsonElement result = sendMessage("launch", params);
|
||||
BrowserImpl browser = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("browser").get("guid").getAsString());
|
||||
browser.browserType = this;
|
||||
browser.launchOptions = options;
|
||||
return browser;
|
||||
}
|
||||
|
||||
@@ -202,7 +201,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
}
|
||||
if (options.recordVideoDir != null) {
|
||||
JsonObject recordVideo = new JsonObject();
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toString());
|
||||
recordVideo.addProperty("dir", options.recordVideoDir.toAbsolutePath().toString());
|
||||
if (options.recordVideoSize != null) {
|
||||
recordVideo.add("size", gson().toJsonTree(options.recordVideoSize));
|
||||
}
|
||||
@@ -222,6 +221,10 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
params.addProperty("noDefaultViewport", true);
|
||||
}
|
||||
}
|
||||
params.remove("acceptDownloads");
|
||||
if (options.acceptDownloads != null) {
|
||||
params.addProperty("acceptDownloads", options.acceptDownloads ? "accept" : "deny");
|
||||
}
|
||||
JsonObject json = sendMessage("launchPersistentContext", params).getAsJsonObject();
|
||||
BrowserContextImpl context = connection.getExistingObject(json.getAsJsonObject("context").get("guid").getAsString());
|
||||
context.videosDir = options.recordVideoDir;
|
||||
@@ -229,6 +232,7 @@ class BrowserTypeImpl extends ChannelOwner implements BrowserType {
|
||||
context.setBaseUrl(options.baseURL);
|
||||
}
|
||||
context.setRecordHar(recordHarPath, harContentPolicy);
|
||||
context.tracing().setTracesDir(options.tracesDir);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.CDPSession;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CDPSessionImpl extends ChannelOwner implements CDPSession {
|
||||
private final ListenerCollection<String> listeners = new ListenerCollection<>(new HashMap<>(), this);
|
||||
|
||||
protected CDPSessionImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
void handleEvent(String event, JsonObject parameters) {
|
||||
super.handleEvent(event, parameters);
|
||||
if ("event".equals(event)) {
|
||||
String method = parameters.get("method").getAsString();
|
||||
JsonObject params = parameters.get("params").getAsJsonObject();
|
||||
listeners.notify(method, params);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject send(String method) {
|
||||
return send(method, null);
|
||||
}
|
||||
|
||||
public JsonObject send(String method, JsonObject params) {
|
||||
JsonObject args = new JsonObject();
|
||||
if (params != null) {
|
||||
args.add("params", params);
|
||||
}
|
||||
args.addProperty("method", method);
|
||||
JsonElement response = connection.sendMessage(guid, "send", args);
|
||||
if (response == null) return null;
|
||||
else return response.getAsJsonObject().get("result").getAsJsonObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void on(String event, Consumer<JsonObject> handler) {
|
||||
listeners.add(event, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void off(String event, Consumer<JsonObject> handler) {
|
||||
listeners.remove(event, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
sendMessage("detach");
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,11 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -34,6 +34,7 @@ class ChannelOwner extends LoggingSupport {
|
||||
final String type;
|
||||
final String guid;
|
||||
final JsonObject initializer;
|
||||
private boolean wasCollected;
|
||||
|
||||
protected ChannelOwner(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
this(parent.connection, parent, type, guid, initializer);
|
||||
@@ -57,15 +58,16 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
void disposeChannelOwner(boolean wasGarbageCollected) {
|
||||
// Clean up from parent and connection.
|
||||
if (parent != null) {
|
||||
parent.objects.remove(guid);
|
||||
}
|
||||
connection.unregisterObject(guid);
|
||||
wasCollected = wasGarbageCollected;
|
||||
// Dispose all children.
|
||||
for (ChannelOwner child : new ArrayList<>(objects.values())) {
|
||||
child.disconnect();
|
||||
child.disposeChannelOwner(wasGarbageCollected);
|
||||
}
|
||||
objects.clear();
|
||||
}
|
||||
@@ -91,6 +93,7 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
|
||||
WaitableResult<JsonElement> sendMessageAsync(String method, JsonObject params) {
|
||||
checkNotCollected();
|
||||
return connection.sendMessageAsync(guid, method, params);
|
||||
}
|
||||
|
||||
@@ -99,9 +102,15 @@ class ChannelOwner extends LoggingSupport {
|
||||
}
|
||||
|
||||
JsonElement sendMessage(String method, JsonObject params) {
|
||||
checkNotCollected();
|
||||
return connection.sendMessage(guid, method, params);
|
||||
}
|
||||
|
||||
private void checkNotCollected() {
|
||||
if (wasCollected)
|
||||
throw new PlaywrightException("The object has been collected to prevent unbounded heap growth.");
|
||||
}
|
||||
|
||||
<T> T runUntil(Runnable code, Waitable<T> waitable) {
|
||||
try {
|
||||
code.run();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
@@ -24,10 +25,13 @@ import com.microsoft.playwright.TimeoutError;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
|
||||
class Message {
|
||||
int id;
|
||||
@@ -36,6 +40,7 @@ class Message {
|
||||
JsonObject params;
|
||||
JsonElement result;
|
||||
SerializedError error;
|
||||
JsonArray log;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -66,14 +71,16 @@ public class Connection {
|
||||
isLogging = (debug != null) && debug.contains("pw:channel");
|
||||
}
|
||||
LocalUtils localUtils;
|
||||
PlaywrightImpl playwright;
|
||||
final Map<String, String> env;
|
||||
private int tracingCount;
|
||||
|
||||
class Root extends ChannelOwner {
|
||||
Root(Connection connection) {
|
||||
super(connection, "Root", "");
|
||||
}
|
||||
|
||||
Playwright initialize() {
|
||||
PlaywrightImpl initialize() {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("sdkLanguage", "java");
|
||||
JsonElement result = sendMessage("initialize", params.getAsJsonObject());
|
||||
@@ -101,8 +108,12 @@ public class Connection {
|
||||
stackTraceCollector = StackTraceCollector.createFromEnv(env);
|
||||
}
|
||||
|
||||
boolean isCollectingStacks() {
|
||||
return stackTraceCollector != null;
|
||||
void setIsTracing(boolean tracing) {
|
||||
if (tracing) {
|
||||
++tracingCount;
|
||||
} else {
|
||||
--tracingCount;
|
||||
}
|
||||
}
|
||||
|
||||
String setApiName(String name) {
|
||||
@@ -120,10 +131,10 @@ public class Connection {
|
||||
}
|
||||
|
||||
public WaitableResult<JsonElement> sendMessageAsync(String guid, String method, JsonObject params) {
|
||||
return internalSendMessage(guid, method, params);
|
||||
return internalSendMessage(guid, method, params, true);
|
||||
}
|
||||
|
||||
private WaitableResult<JsonElement> internalSendMessage(String guid, String method, JsonObject params) {
|
||||
private WaitableResult<JsonElement> internalSendMessage(String guid, String method, JsonObject params, boolean sendStack) {
|
||||
int id = ++lastId;
|
||||
WaitableResult<JsonElement> result = new WaitableResult<>();
|
||||
callbacks.put(id, result);
|
||||
@@ -133,6 +144,8 @@ public class Connection {
|
||||
message.addProperty("method", method);
|
||||
message.add("params", params);
|
||||
JsonObject metadata = new JsonObject();
|
||||
metadata.addProperty("wallTime", currentTimeMillis());
|
||||
JsonArray stack = null;
|
||||
if (apiName == null) {
|
||||
metadata.addProperty("internal", true);
|
||||
} else {
|
||||
@@ -140,16 +153,33 @@ public class Connection {
|
||||
// All but first message in an API call are considered internal and will be hidden from the inspector.
|
||||
apiName = null;
|
||||
if (stackTraceCollector != null) {
|
||||
metadata.add("stack", stackTraceCollector.currentStackTrace());
|
||||
stack = stackTraceCollector.currentStackTrace();
|
||||
if (!stack.isEmpty()) {
|
||||
JsonObject location = new JsonObject();
|
||||
JsonObject frame = stack.get(0).getAsJsonObject();
|
||||
location.addProperty("file", frame.get("file").getAsString());
|
||||
location.addProperty("line", frame.get("line").getAsInt());
|
||||
location.addProperty("column", frame.get("column").getAsInt());
|
||||
metadata.add("location", location);
|
||||
}
|
||||
}
|
||||
}
|
||||
message.add("metadata", metadata);
|
||||
transport.send(message);
|
||||
if (sendStack && tracingCount > 0 && stack != null && !method.startsWith("LocalUtils")) {
|
||||
JsonObject callData = new JsonObject();
|
||||
callData.addProperty("id", id);
|
||||
callData.add("stack", stack);
|
||||
JsonObject stackParams = new JsonObject();
|
||||
stackParams.add("callData", callData);
|
||||
internalSendMessage(localUtils.guid,"addStackToTracingNoReply", stackParams, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public PlaywrightImpl initializePlaywright() {
|
||||
return (PlaywrightImpl) this.root.initialize();
|
||||
playwright = root.initialize();
|
||||
return playwright;
|
||||
}
|
||||
|
||||
LocalUtils localUtils() {
|
||||
@@ -181,6 +211,30 @@ public class Connection {
|
||||
dispatch(messageObj);
|
||||
}
|
||||
|
||||
private static String formatCallLog(JsonArray log) {
|
||||
if (log == null) {
|
||||
return "";
|
||||
}
|
||||
boolean allEmpty = true;
|
||||
for (JsonElement e: log) {
|
||||
if (!e.getAsString().isEmpty()) {
|
||||
allEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allEmpty) {
|
||||
return "";
|
||||
}
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add("");
|
||||
lines.add("Call log:");
|
||||
for (JsonElement e: log) {
|
||||
lines.add("- " + e.getAsString());
|
||||
}
|
||||
lines.add("");
|
||||
return String.join("\n", lines);
|
||||
}
|
||||
|
||||
private void dispatch(Message message) {
|
||||
// System.out.println("Message: " + message.method + " " + message.id);
|
||||
if (message.id != 0) {
|
||||
@@ -193,12 +247,16 @@ public class Connection {
|
||||
if (message.error == null) {
|
||||
callback.complete(message.result);
|
||||
} else {
|
||||
String callLog = formatCallLog(message.log);
|
||||
if (message.error.error == null) {
|
||||
callback.completeExceptionally(new PlaywrightException(message.error.toString()));
|
||||
callback.completeExceptionally(new PlaywrightException(message.error + callLog));
|
||||
} else if ("TimeoutError".equals(message.error.error.name)) {
|
||||
callback.completeExceptionally(new TimeoutError(message.error.error.toString()));
|
||||
callback.completeExceptionally(new TimeoutError(message.error.error + callLog));
|
||||
} else if ("TargetClosedError".equals(message.error.error.name)) {
|
||||
callback.completeExceptionally(new TargetClosedError(message.error.error + callLog));
|
||||
|
||||
} else {
|
||||
callback.completeExceptionally(new DriverException(message.error.error));
|
||||
callback.completeExceptionally(new DriverException(message.error.error + callLog));
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -227,7 +285,8 @@ public class Connection {
|
||||
return;
|
||||
}
|
||||
if (message.method.equals("__dispose__")) {
|
||||
object.disconnect();
|
||||
boolean wasCollected = message.params.has("reason") && "gc".equals(message.params.get("reason").getAsString());
|
||||
object.disposeChannelOwner(wasCollected);
|
||||
return;
|
||||
}
|
||||
object.handleEvent(message.method, message.params);
|
||||
@@ -268,9 +327,6 @@ public class Connection {
|
||||
case "BrowserContext":
|
||||
result = new BrowserContextImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "ConsoleMessage":
|
||||
result = new ConsoleMessageImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "Dialog":
|
||||
result = new DialogImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
@@ -334,6 +390,9 @@ public class Connection {
|
||||
case "WritableStream":
|
||||
result = new WritableStream(parent, type, guid, initializer);
|
||||
break;
|
||||
case "CDPSession":
|
||||
result = new CDPSessionImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
default:
|
||||
throw new PlaywrightException("Unknown type " + type);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,27 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.ConsoleMessage;
|
||||
import com.microsoft.playwright.JSHandle;
|
||||
import com.microsoft.playwright.Page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
public class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
|
||||
public ConsoleMessageImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
public class ConsoleMessageImpl implements ConsoleMessage {
|
||||
private final Connection connection;
|
||||
private PageImpl page;
|
||||
private final JsonObject initializer;
|
||||
|
||||
public ConsoleMessageImpl(Connection connection, JsonObject initializer) {
|
||||
this.connection = connection;
|
||||
// Note: currently, we only report console messages for pages and they always have a page.
|
||||
// However, in the future we might report console messages for service workers or something else,
|
||||
// where page() would be null.
|
||||
if (initializer.has("page")) {
|
||||
page = connection.getExistingObject(initializer.getAsJsonObject("page").get("guid").getAsString());
|
||||
}
|
||||
this.initializer = initializer;
|
||||
}
|
||||
|
||||
public String type() {
|
||||
@@ -55,4 +67,9 @@ public class ConsoleMessageImpl extends ChannelOwner implements ConsoleMessage {
|
||||
location.get("lineNumber").getAsNumber() + ":" +
|
||||
location.get("columnNumber").getAsNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,18 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Dialog;
|
||||
import com.microsoft.playwright.Page;
|
||||
|
||||
class DialogImpl extends ChannelOwner implements Dialog {
|
||||
private PageImpl page;
|
||||
|
||||
DialogImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
// Note: dialogs that open early during page initialization block it.
|
||||
// Therefore, we must report the dialog without a page to be able to handle it.
|
||||
if (initializer.has("page")) {
|
||||
page = connection.getExistingObject(initializer.getAsJsonObject("page").get("guid").getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,6 +58,11 @@ class DialogImpl extends ChannelOwner implements Dialog {
|
||||
return initializer.get("message").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return initializer.get("type").getAsString();
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
class DriverException extends PlaywrightException {
|
||||
DriverException(SerializedError.Error error) {
|
||||
super(error.toString());
|
||||
DriverException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,12 @@ import com.microsoft.playwright.options.SelectOption;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.*;
|
||||
import static com.microsoft.playwright.impl.Utils.*;
|
||||
import static com.microsoft.playwright.impl.Utils.addLargeFileUploadParams;
|
||||
import static com.microsoft.playwright.impl.Utils.addFilePathUploadParams;
|
||||
import static com.microsoft.playwright.options.ScreenshotType.JPEG;
|
||||
import static com.microsoft.playwright.options.ScreenshotType.PNG;
|
||||
|
||||
@@ -467,16 +466,12 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
|
||||
if (frame == null) {
|
||||
throw new Error("Cannot set input files to detached element");
|
||||
}
|
||||
if (hasLargeFile(files)) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addLargeFileUploadParams(files, params, frame.page().context());
|
||||
sendMessage("setInputFilePaths", params);
|
||||
} else {
|
||||
setInputFilesImpl(Utils.toFilePayloads(files), options);
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addFilePathUploadParams(files, params, frame.page().context());
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -495,7 +490,7 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.add("files", Serialization.toJsonArray(files));
|
||||
params.add("payloads", Serialization.toJsonArray(files));
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
throw new PlaywrightException("Failed to read from file", e);
|
||||
}
|
||||
String content = new String(encoded, StandardCharsets.UTF_8);
|
||||
content += "//# sourceURL=" + options.path.toString().replace("\n", "");
|
||||
content = addSourceUrlToScript(content, options.path);
|
||||
jsonOptions.addProperty("content", content);
|
||||
}
|
||||
JsonElement json = sendMessage("addScriptTag", jsonOptions);
|
||||
@@ -407,12 +407,12 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(String testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
return locator(getByTestIdSelector(testId, connection.playwright));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
return locator(getByTestIdSelector(testId, connection.playwright));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -761,17 +761,13 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
}
|
||||
|
||||
void setInputFilesImpl(String selector, Path[] files, SetInputFilesOptions options) {
|
||||
if (hasLargeFile(files)) {
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addLargeFileUploadParams(files, params, page.context());
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("setInputFilePaths", params);
|
||||
} else {
|
||||
setInputFilesImpl(selector, Utils.toFilePayloads(files), options);
|
||||
if (options == null) {
|
||||
options = new SetInputFilesOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
addFilePathUploadParams(files, params, page.context());
|
||||
params.addProperty("selector", selector);
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -791,7 +787,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
params.add("files", toJsonArray(files));
|
||||
params.add("payloads", toJsonArray(files));
|
||||
sendMessage("setInputFiles", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.FrameLocator;
|
||||
import com.microsoft.playwright.Locator;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.AriaRole;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@@ -81,12 +82,12 @@ class FrameLocatorImpl implements FrameLocator {
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(String testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
return locator(getByTestIdSelector(testId, frame.connection.playwright));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
return locator(getByTestIdSelector(testId, frame.connection.playwright));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,6 +120,15 @@ class FrameLocatorImpl implements FrameLocator {
|
||||
return new LocatorImpl(frame, frameSelector + " >> internal:control=enter-frame >> " + selector, convertType(options, Locator.LocatorOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator locator(Locator selectorOrLocator, LocatorOptions options) {
|
||||
LocatorImpl other = (LocatorImpl) selectorOrLocator;
|
||||
if (other.frame != frame) {
|
||||
throw new PlaywrightException("Locators must belong to the same frame.");
|
||||
}
|
||||
return locator(other.selector, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameLocator nth(int index) {
|
||||
return new FrameLocatorImpl(frame, frameSelector + " >> nth=" + index);
|
||||
|
||||
@@ -73,6 +73,14 @@ public class HARRouter {
|
||||
|
||||
if ("fulfill".equals(action)) {
|
||||
int status = response.get("status").getAsInt();
|
||||
// If the response status is -1, the request was canceled or stalled, so we just stall it here.
|
||||
// See https://github.com/microsoft/playwright/issues/29311.
|
||||
// TODO: it'd be better to abort such requests, but then we likely need to respect the timing,
|
||||
// because the request might have been stalled for a long time until the very end of the
|
||||
// test when HAR was recorded but we'd abort it immediately.
|
||||
if (status == -1) {
|
||||
return;
|
||||
}
|
||||
Map<String, String> headers = fromNameValues(response.getAsJsonArray("headers"));
|
||||
byte[] buffer = Base64.getDecoder().decode(response.get("body").getAsString());
|
||||
route.fulfill(new Route.FulfillOptions()
|
||||
|
||||
@@ -20,16 +20,42 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class LocalUtils extends ChannelOwner {
|
||||
LocalUtils(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
void zip(Path zipFile, JsonArray entries) {
|
||||
JsonArray deviceDescriptors() {
|
||||
return initializer.getAsJsonArray("deviceDescriptors");
|
||||
}
|
||||
|
||||
void zip(Path zipFile, JsonArray entries, String stacksId, boolean appendMode, boolean includeSources) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("zipFile", zipFile.toString());
|
||||
params.add("entries", entries);
|
||||
params.addProperty("mode", appendMode ? "append" : "write");
|
||||
params.addProperty("stacksId", stacksId);
|
||||
params.addProperty("includeSources", includeSources);
|
||||
sendMessage("zip", params);
|
||||
}
|
||||
|
||||
void traceDiscarded(String stacksId) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("stacksId", stacksId);
|
||||
sendMessage("traceDiscarded", params);
|
||||
}
|
||||
|
||||
String tracingStarted(String tracesDir, String traceName) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (tracesDir != null) {
|
||||
params.addProperty("tracesDir", "");
|
||||
}
|
||||
params.addProperty("traceName", traceName);
|
||||
JsonObject json = connection.localUtils().sendMessage("tracingStarted", params).getAsJsonObject();
|
||||
return json.get("stacksId").getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +86,14 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void hasAttribute(String name, String text, HasAttributeOptions options) {
|
||||
ExpectedTextValue expected = new ExpectedTextValue();
|
||||
expected.string = text;
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
hasAttribute(name, expected, text, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasAttribute(String name, Pattern pattern, HasAttributeOptions options) {
|
||||
ExpectedTextValue expected = expectedRegex(pattern);
|
||||
expected.ignoreCase = shouldIgnoreCase(options);
|
||||
hasAttribute(name, expected, pattern, options);
|
||||
}
|
||||
|
||||
@@ -105,7 +107,7 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
if (expectedValue instanceof Pattern) {
|
||||
message += " matching regex";
|
||||
}
|
||||
expectImpl("to.have.attribute", expectedText, expectedValue, message, commonOptions);
|
||||
expectImpl("to.have.attribute.value", expectedText, expectedValue, message, commonOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,8 +290,10 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
|
||||
@Override
|
||||
public void isChecked(IsCheckedOptions options) {
|
||||
String expression = (options != null && options.checked != null && !options.checked) ? "to.be.unchecked" : "to.be.checked";
|
||||
expectTrue(expression, "Locator expected to be checked", convertType(options, FrameExpectOptions.class));
|
||||
boolean unchecked = options != null && options.checked != null && !options.checked;
|
||||
String expression = unchecked ? "to.be.unchecked" : "to.be.checked";
|
||||
String message = "Locator expected to be " + (unchecked ? "un" : "") + "checked";
|
||||
expectTrue(expression, message, convertType(options, FrameExpectOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -301,7 +305,8 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void isEditable(IsEditableOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean editable = options == null || options.editable == null || options.editable == true;
|
||||
expectTrue(editable ? "to.be.editable" : "to.be.readonly", "Locator expected to be editable", frameOptions);
|
||||
String message = "Locator expected to be " + (editable ? "editable" : "readonly");
|
||||
expectTrue(editable ? "to.be.editable" : "to.be.readonly", message, frameOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -313,7 +318,8 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void isEnabled(IsEnabledOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean enabled = options == null || options.enabled == null || options.enabled == true;
|
||||
expectTrue(enabled ? "to.be.enabled" : "to.be.disabled", "Locator expected to be enabled", frameOptions);
|
||||
String message = "Locator expected to be " + (enabled ? "enabled" : "disabled");
|
||||
expectTrue(enabled ? "to.be.enabled" : "to.be.disabled", message, frameOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -339,7 +345,8 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
public void isVisible(IsVisibleOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean visible = options == null || options.visible == null || options.visible == true;
|
||||
expectTrue(visible ? "to.be.visible" : "to.be.hidden", "Locator expected to be visible", frameOptions);
|
||||
String message = "Locator expected to be " + (visible ? "visible" : "hidden");
|
||||
expectTrue(visible ? "to.be.visible" : "to.be.hidden", message, frameOptions);
|
||||
}
|
||||
|
||||
private void expectTrue(String expression, String message, FrameExpectOptions options) {
|
||||
@@ -352,6 +359,14 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
|
||||
return new LocatorAssertionsImpl(actualLocator, !isNot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isAttached(IsAttachedOptions options) {
|
||||
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
|
||||
boolean attached = options == null || options.attached == null || options.attached == true;
|
||||
String message = "Locator expected to be " + (attached ? "attached" : "detached");
|
||||
expectTrue(attached ? "to.be.attached" : "to.be.detached", message, frameOptions);
|
||||
}
|
||||
|
||||
private static Boolean shouldIgnoreCase(Object options) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.JsonElement;
|
||||
@@ -20,8 +36,8 @@ import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
import static com.microsoft.playwright.impl.Utils.toJsRegexFlags;
|
||||
|
||||
class LocatorImpl implements Locator {
|
||||
private final FrameImpl frame;
|
||||
private final String selector;
|
||||
final FrameImpl frame;
|
||||
final String selector;
|
||||
|
||||
public LocatorImpl(FrameImpl frame, String selector, LocatorOptions options) {
|
||||
this.frame = frame;
|
||||
@@ -29,12 +45,21 @@ class LocatorImpl implements Locator {
|
||||
if (options.hasText != null) {
|
||||
selector += " >> internal:has-text=" + escapeForTextSelector(options.hasText, false);
|
||||
}
|
||||
if (options.hasNotText != null) {
|
||||
selector += " >> internal:has-not-text=" + escapeForTextSelector(options.hasNotText, false);
|
||||
}
|
||||
if (options.has != null) {
|
||||
LocatorImpl locator = (LocatorImpl) options.has;
|
||||
if (locator.frame != frame)
|
||||
throw new Error("Inner 'has' locator must belong to the same frame.");
|
||||
selector += " >> internal:has=" + gson().toJson(locator.selector);
|
||||
}
|
||||
if (options.hasNot != null) {
|
||||
LocatorImpl locator = (LocatorImpl) options.hasNot;
|
||||
if (locator.frame != frame)
|
||||
throw new Error("Inner 'hasNot' locator must belong to the same frame.");
|
||||
selector += " >> internal:has-not=" + gson().toJson(locator.selector);
|
||||
}
|
||||
}
|
||||
this.selector = selector;
|
||||
}
|
||||
@@ -82,6 +107,14 @@ class LocatorImpl implements Locator {
|
||||
return (List<String>) frame.evalOnSelectorAll(selector, "ee => ee.map(e => e.textContent || '')");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator and(Locator locator) {
|
||||
LocatorImpl other = (LocatorImpl) locator;
|
||||
if (other.frame != frame)
|
||||
throw new Error("Locators must belong to the same frame.");
|
||||
return new LocatorImpl(frame, selector + " >> internal:and=" + gson().toJson(other.selector), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blur(BlurOptions options) {
|
||||
frame.withLogging("Locator.blur", () -> blurImpl(options));
|
||||
@@ -261,12 +294,12 @@ class LocatorImpl implements Locator {
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(String testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
return locator(getByTestIdSelector(testId, frame.connection.playwright));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
return locator(getByTestIdSelector(testId, frame.connection.playwright));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -384,11 +417,28 @@ class LocatorImpl implements Locator {
|
||||
return new LocatorImpl(frame, this.selector + " >> " + selector, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator locator(Locator selectorOrLocator, LocatorOptions options) {
|
||||
LocatorImpl other = (LocatorImpl) selectorOrLocator;
|
||||
if (other.frame != frame) {
|
||||
throw new PlaywrightException("Locators must belong to the same frame.");
|
||||
}
|
||||
return new LocatorImpl(frame, this.selector + " >> internal:chain=" + gson().toJson(other.selector), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator nth(int index) {
|
||||
return new LocatorImpl(frame, selector + " >> nth=" + index, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator or(Locator locator) {
|
||||
LocatorImpl other = (LocatorImpl) locator;
|
||||
if (other.frame != frame)
|
||||
throw new Error("Locators must belong to the same frame.");
|
||||
return new LocatorImpl(frame, selector + " >> internal:or=" + gson().toJson(other.selector), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page page() {
|
||||
return frame.page();
|
||||
@@ -402,6 +452,11 @@ class LocatorImpl implements Locator {
|
||||
frame.press(selector, key, convertType(options, Frame.PressOptions.class).setStrict(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pressSequentially(String text, PressSequentiallyOptions options) {
|
||||
type(text, convertType(options, TypeOptions.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] screenshot(ScreenshotOptions options) {
|
||||
return withElement((h, o) -> h.screenshot(o), convertType(options, ElementHandle.ScreenshotOptions.class));
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.Locator;
|
||||
@@ -5,15 +21,10 @@ import com.microsoft.playwright.options.AriaRole;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.toJsRegexFlags;
|
||||
|
||||
public class LocatorUtils {
|
||||
private static volatile String testIdAttributeName = "data-testid";;
|
||||
|
||||
static void setTestIdAttributeName(String name) {
|
||||
testIdAttributeName = name;
|
||||
}
|
||||
|
||||
static String getByTextSelector(Object text, Locator.GetByTextOptions options) {
|
||||
boolean exact = options != null && options.exact != null && options.exact;
|
||||
return "internal:text=" + escapeForTextSelector(text, exact);
|
||||
@@ -25,13 +36,11 @@ public class LocatorUtils {
|
||||
}
|
||||
|
||||
private static String getByAttributeTextSelector(String attrName, Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return "internal:attr=[" + attrName + "=" + toJsRegExp((Pattern) value) + "]";
|
||||
}
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector((String) value, exact) + "]";
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector(value, exact) + "]";
|
||||
}
|
||||
|
||||
static String getByTestIdSelector(Object testId) {
|
||||
static String getByTestIdSelector(Object testId, PlaywrightImpl playwright) {
|
||||
String testIdAttributeName = ((SharedSelectors) playwright.selectors()).testIdAttributeName;
|
||||
return getByAttributeTextSelector(testIdAttributeName, testId, true);
|
||||
}
|
||||
|
||||
@@ -71,14 +80,7 @@ public class LocatorUtils {
|
||||
if (options.level != null)
|
||||
addAttr(result, "level", options.level.toString());
|
||||
if (options.name != null) {
|
||||
String name;
|
||||
if (options.name instanceof String) {
|
||||
name = escapeForAttributeSelector((String) options.name, options.exact != null && options.exact);
|
||||
} else if (options.name instanceof Pattern) {
|
||||
name = toJsRegExp((Pattern) options.name);
|
||||
} else {
|
||||
throw new IllegalArgumentException("options.name can be String or Pattern, found: " + options.name);
|
||||
}
|
||||
String name = escapeForAttributeSelector(options.name, options.exact != null && options.exact);
|
||||
addAttr(result, "name", name);
|
||||
}
|
||||
if (options.pressed != null)
|
||||
@@ -87,38 +89,33 @@ public class LocatorUtils {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static String escapeForTextSelector(Object text, boolean exact) {
|
||||
return escapeForTextSelector(text, exact, false);
|
||||
private static String escapeRegexForSelector(Pattern re) {
|
||||
// Even number of backslashes followed by the quote -> insert a backslash.
|
||||
return toJsRegExp(re).replaceAll("(^|[^\\\\])(\\\\\\\\)*([\"'`])", "$1$2\\\\$3").replaceAll(">>", "\\\\>\\\\>");
|
||||
}
|
||||
|
||||
private static String escapeForTextSelector(Object param, boolean exact, boolean caseSensitive) {
|
||||
if (param instanceof Pattern) {
|
||||
return toJsRegExp((Pattern) param);
|
||||
static String escapeForTextSelector(Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return escapeRegexForSelector((Pattern) value);
|
||||
}
|
||||
if (!(param instanceof String)) {
|
||||
throw new IllegalArgumentException("text parameter must be Pattern or String: " + param);
|
||||
if (value instanceof String) {
|
||||
return gson().toJson(value) + (exact ? "s" : "i");
|
||||
}
|
||||
String text = (String) param;
|
||||
if (exact) {
|
||||
return '"' + text.replace("\"", "\\\"") + '"';
|
||||
}
|
||||
|
||||
if (text.contains("\"") || text.contains(">>") || text.startsWith("/")) {
|
||||
return "/" + escapeForRegex(text).replaceAll("\\s+", "\\\\s+") + "/" + (caseSensitive ? "" : "i");
|
||||
}
|
||||
return text;
|
||||
throw new IllegalArgumentException("text parameter must be Pattern or String: " + value);
|
||||
}
|
||||
|
||||
private static String escapeForRegex(String text) {
|
||||
return text.replaceAll("[.*+?^>${}()|\\[\\]\\\\]", "\\\\\\\\$0");
|
||||
}
|
||||
|
||||
private static String escapeForAttributeSelector(String value, boolean exact) {
|
||||
// TODO: this should actually be
|
||||
// cssEscape(value).replace(/\\ /g, ' ')
|
||||
// However, our attribute selectors do not conform to CSS parsing spec,
|
||||
// so we escape them differently.
|
||||
return '"' + value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i");
|
||||
private static String escapeForAttributeSelector(Object value, boolean exact) {
|
||||
if (value instanceof Pattern) {
|
||||
return escapeRegexForSelector((Pattern) value);
|
||||
}
|
||||
if (value instanceof String) {
|
||||
// TODO: this should actually be
|
||||
// cssEscape(value).replace(/\\ /g, ' ')
|
||||
// However, our attribute selectors do not conform to CSS parsing spec,
|
||||
// so we escape them differently.
|
||||
return '"' + ((String) value).replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i");
|
||||
}
|
||||
throw new IllegalArgumentException("Attribute can be String or Pattern, found: " + value);
|
||||
}
|
||||
|
||||
private static String toJsRegExp(Pattern pattern) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.microsoft.playwright.options.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -48,8 +49,12 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private ViewportSize viewport;
|
||||
private final Router routes = new Router();
|
||||
private final Set<FrameImpl> frames = new LinkedHashSet<>();
|
||||
private final Map<Integer, Runnable> locatorHandlers = new HashMap<>();
|
||||
|
||||
private static final Map<EventType, String> eventSubscriptions() {
|
||||
Map<EventType, String> result = new HashMap<>();
|
||||
result.put(EventType.CONSOLE, "console");
|
||||
result.put(EventType.DIALOG, "dialog");
|
||||
result.put(EventType.REQUEST, "request");
|
||||
result.put(EventType.RESPONSE, "response");
|
||||
result.put(EventType.REQUESTFINISHED, "requestFinished");
|
||||
@@ -65,6 +70,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
private final TimeoutSettings timeoutSettings;
|
||||
private VideoImpl video;
|
||||
private final PageImpl opener;
|
||||
private String closeReason;
|
||||
|
||||
enum EventType {
|
||||
CLOSE,
|
||||
@@ -112,22 +118,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
protected void handleEvent(String event, JsonObject params) {
|
||||
if ("dialog".equals(event)) {
|
||||
String guid = params.getAsJsonObject("dialog").get("guid").getAsString();
|
||||
DialogImpl dialog = connection.getExistingObject(guid);
|
||||
if (listeners.hasListeners(EventType.DIALOG)) {
|
||||
listeners.notify(EventType.DIALOG, dialog);
|
||||
} else {
|
||||
if ("beforeunload".equals(dialog.type())) {
|
||||
try {
|
||||
dialog.accept();
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
} else if ("worker".equals(event)) {
|
||||
if ("worker".equals(event)) {
|
||||
String guid = params.getAsJsonObject("worker").get("guid").getAsString();
|
||||
WorkerImpl worker = connection.getExistingObject(guid);
|
||||
worker.page = this;
|
||||
@@ -137,10 +128,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
String guid = params.getAsJsonObject("webSocket").get("guid").getAsString();
|
||||
WebSocketImpl webSocket = connection.getExistingObject(guid);
|
||||
listeners.notify(EventType.WEBSOCKET, webSocket);
|
||||
} else if ("console".equals(event)) {
|
||||
String guid = params.getAsJsonObject("message").get("guid").getAsString();
|
||||
ConsoleMessageImpl message = connection.getExistingObject(guid);
|
||||
listeners.notify(EventType.CONSOLE, message);
|
||||
} else if ("download".equals(event)) {
|
||||
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
@@ -185,8 +172,12 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
frame.parentFrame.childFrames.remove(frame);
|
||||
}
|
||||
listeners.notify(EventType.FRAMEDETACHED, frame);
|
||||
} else if ("locatorHandlerTriggered".equals(event)) {
|
||||
int uid = params.get("uid").getAsInt();
|
||||
onLocatorHandlerTriggered(uid);
|
||||
} else if ("route".equals(event)) {
|
||||
RouteImpl route = connection.getExistingObject(params.getAsJsonObject("route").get("guid").getAsString());
|
||||
route.browserContext = browserContext;
|
||||
Router.HandleResult handled = routes.handle(route);
|
||||
if (handled != Router.HandleResult.NoMatchingHandler) {
|
||||
updateInterceptionPatterns();
|
||||
@@ -198,16 +189,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
String artifactGuid = params.getAsJsonObject("artifact").get("guid").getAsString();
|
||||
ArtifactImpl artifact = connection.getExistingObject(artifactGuid);
|
||||
forceVideo().setArtifact(artifact);
|
||||
} else if ("pageError".equals(event)) {
|
||||
SerializedError error = gson().fromJson(params.getAsJsonObject("error"), SerializedError.class);
|
||||
String errorStr = "";
|
||||
if (error.error != null) {
|
||||
errorStr = error.error.name + ": " + error.error.message;
|
||||
if (error.error.stack != null && !error.error.stack.isEmpty()) {
|
||||
errorStr += "\n" + error.error.stack;
|
||||
}
|
||||
}
|
||||
listeners.notify(EventType.PAGEERROR, errorStr);
|
||||
} else if ("crash".equals(event)) {
|
||||
listeners.notify(EventType.CRASH, this);
|
||||
} else if ("close".equals(event)) {
|
||||
@@ -225,6 +206,13 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
listeners.notify(EventType.CLOSE, this);
|
||||
}
|
||||
|
||||
private String effectiveCloseReason() {
|
||||
if (closeReason != null) {
|
||||
return closeReason;
|
||||
}
|
||||
return browserContext.effectiveCloseReason();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Consumer<Page> handler) {
|
||||
listeners.add(EventType.CLOSE, handler);
|
||||
@@ -510,19 +498,22 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
if (isClosed) {
|
||||
return;
|
||||
if (options == null) {
|
||||
options = new CloseOptions();
|
||||
}
|
||||
JsonObject params = options == null ? new JsonObject() : gson().toJsonTree(options).getAsJsonObject();
|
||||
closeReason = options.reason;
|
||||
try {
|
||||
sendMessage("close", params);
|
||||
} catch (PlaywrightException exception) {
|
||||
if (!isSafeCloseError(exception)) {
|
||||
throw exception;
|
||||
if (ownedContext != null) {
|
||||
ownedContext.close();
|
||||
} else {
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("close", params);
|
||||
}
|
||||
}
|
||||
if (ownedContext != null) {
|
||||
ownedContext.close();
|
||||
} catch (PlaywrightException exception) {
|
||||
if (isSafeCloseError(exception) && (options.runBeforeUnload == null || !options.runBeforeUnload)) {
|
||||
return;
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,6 +528,34 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return withLogging("Page.querySelectorAll", () -> mainFrame.querySelectorAllImpl(selector));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLocatorHandler(Locator locator, Runnable handler) {
|
||||
LocatorImpl locatorImpl = (LocatorImpl) locator;
|
||||
if (locatorImpl.frame != mainFrame) {
|
||||
throw new PlaywrightException("Locator must belong to the main frame of this page");
|
||||
}
|
||||
withLogging("Page.addLocatorHandler", () -> {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("selector", locatorImpl.selector);
|
||||
JsonObject json = (JsonObject) sendMessage("registerLocatorHandler", params);
|
||||
int uid = json.get("uid").getAsInt();
|
||||
locatorHandlers.put(uid, handler);
|
||||
});
|
||||
}
|
||||
|
||||
private void onLocatorHandlerTriggered(int uid) {
|
||||
try {
|
||||
Runnable handler = locatorHandlers.get(uid);
|
||||
if (handler != null) {
|
||||
handler.run();
|
||||
}
|
||||
} finally {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("uid", uid);
|
||||
sendMessageAsync("resolveLocatorHandlerNoReply", params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object evalOnSelector(String selector, String pageFunction, Object arg, EvalOnSelectorOptions options) {
|
||||
return withLogging("Page.evalOnSelector", () -> mainFrame.evalOnSelectorImpl(
|
||||
@@ -558,7 +577,8 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
withLogging("Page.addInitScript", () -> {
|
||||
try {
|
||||
byte[] bytes = readAllBytes(path);
|
||||
addInitScriptImpl(new String(bytes, UTF_8));
|
||||
String script = addSourceUrlToScript(new String(bytes, UTF_8), path);
|
||||
addInitScriptImpl(script);
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Failed to read script from file", e);
|
||||
}
|
||||
@@ -950,7 +970,16 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
@Override
|
||||
public void pause() {
|
||||
withLogging("Page.pause", () -> {
|
||||
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
|
||||
Double defaultNavigationTimeout = browserContext.timeoutSettings.defaultNavigationTimeout();
|
||||
Double defaultTimeout = browserContext.timeoutSettings.defaultTimeout();
|
||||
browserContext.setDefaultNavigationTimeoutImpl(0.0);
|
||||
browserContext.setDefaultTimeoutImpl(0.0);
|
||||
try {
|
||||
runUntil(() -> {}, new WaitableRace<>(asList(context().pause(), (Waitable<JsonElement>) waitableClosedOrCrashed)));
|
||||
} finally {
|
||||
browserContext.setDefaultNavigationTimeoutImpl(defaultNavigationTimeout);
|
||||
browserContext.setDefaultTimeoutImpl(defaultTimeout);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -960,9 +989,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
}
|
||||
|
||||
private byte[] pdfImpl(PdfOptions options) {
|
||||
if (!browserContext.browser().isChromium()) {
|
||||
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new PdfOptions();
|
||||
}
|
||||
@@ -1234,6 +1260,14 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
() -> mainFrame.uncheckImpl(selector, convertType(options, Frame.UncheckOptions.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unrouteAll() {
|
||||
withLogging("Page.unrouteAll", () -> {
|
||||
routes.removeAll();
|
||||
updateInterceptionPatterns();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unroute(String url, Consumer<Route> handler) {
|
||||
unroute(new UrlMatcher(browserContext.baseUrl, url), handler);
|
||||
@@ -1358,7 +1392,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new PlaywrightException("Page closed");
|
||||
throw new TargetClosedError(effectiveCloseReason());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1369,7 +1403,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new PlaywrightException("Page crashed");
|
||||
throw new TargetClosedError("Page crashed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1457,6 +1491,15 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
() -> mainFrame.waitForSelectorImpl(selector, convertType(options, Frame.WaitForSelectorOptions.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForCondition(BooleanSupplier predicate, WaitForConditionOptions options) {
|
||||
List<Waitable<Void>> waitables = new ArrayList<>();
|
||||
waitables.add(createWaitForCloseHelper());
|
||||
waitables.add(createWaitableTimeout(options == null ? null : options.timeout));
|
||||
waitables.add(new WaitablePredicate<>(predicate));
|
||||
runUntil(() -> {}, new WaitableRace<>(waitables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForTimeout(double timeout) {
|
||||
withLogging("Page.waitForTimeout", () -> mainFrame.waitForTimeoutImpl(timeout));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.APIRequest;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
@@ -63,7 +64,6 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
private final BrowserTypeImpl webkit;
|
||||
private final SelectorsImpl selectors;
|
||||
private final APIRequestImpl apiRequest;
|
||||
private final LocalUtils localUtils;
|
||||
private SharedSelectors sharedSelectors;
|
||||
|
||||
PlaywrightImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
@@ -74,10 +74,6 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
|
||||
selectors = connection.getExistingObject(initializer.getAsJsonObject("selectors").get("guid").getAsString());
|
||||
apiRequest = new APIRequestImpl(this);
|
||||
localUtils = connection.getExistingObject(initializer.getAsJsonObject("utils").get("guid").getAsString());
|
||||
chromium.localUtils = localUtils;
|
||||
firefox.localUtils = localUtils;
|
||||
webkit.localUtils = localUtils;
|
||||
}
|
||||
|
||||
void initSharedSelectors(PlaywrightImpl parent) {
|
||||
@@ -94,6 +90,10 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
sharedSelectors.removeChannel(selectors);
|
||||
}
|
||||
|
||||
public JsonArray deviceDescriptors() {
|
||||
return connection.localUtils.deviceDescriptors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrowserTypeImpl chromium() {
|
||||
return chromium;
|
||||
|
||||
@@ -32,6 +32,7 @@ class SerializedValue{
|
||||
String v;
|
||||
String d;
|
||||
String u;
|
||||
String bi;
|
||||
public static class R {
|
||||
String p;
|
||||
String f;
|
||||
@@ -46,6 +47,10 @@ class SerializedValue{
|
||||
Number h;
|
||||
Integer id;
|
||||
Integer ref;
|
||||
// JS representation of Map: [[key1, value1], [key2, value2], ...].
|
||||
SerializedValue m;
|
||||
// JS representation of Set: [item1, item2, ...].
|
||||
SerializedValue se;
|
||||
}
|
||||
|
||||
class SerializedArgument{
|
||||
|
||||
@@ -78,7 +78,13 @@ public class RequestImpl extends ChannelOwner implements Request {
|
||||
|
||||
@Override
|
||||
public FrameImpl frame() {
|
||||
return connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
|
||||
FrameImpl frame = connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
|
||||
if (frame.page == null) {
|
||||
throw new PlaywrightException("Frame for this navigation request is not available, because the request\n" +
|
||||
"was issued before the frame is created. You can check whether the request\n" +
|
||||
"is a navigation request by calling isNavigationRequest() method.");
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
public class RouteImpl extends ChannelOwner implements Route {
|
||||
private final RequestImpl request;
|
||||
private boolean handled;
|
||||
|
||||
BrowserContextImpl browserContext;
|
||||
boolean fallbackCalled;
|
||||
boolean shouldResumeIfFallbackIsCalled;
|
||||
|
||||
@@ -47,6 +47,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
withLogging("Route.abort", () -> {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("errorCode", errorCode);
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
sendMessageAsync("abort", params);
|
||||
});
|
||||
}
|
||||
@@ -57,9 +58,13 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
|
||||
@Override
|
||||
public void resume(ResumeOptions options) {
|
||||
resume(options, false);
|
||||
}
|
||||
|
||||
void resume(ResumeOptions options, boolean isFallback) {
|
||||
startHandling();
|
||||
applyOverrides(convertType(options, FallbackOptions.class));
|
||||
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume()));
|
||||
withLogging("Route.resume", () -> resumeImpl(request().fallbackOverridesForResume(), isFallback));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +75,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
}
|
||||
applyOverrides(options);
|
||||
if (shouldResumeIfFallbackIsCalled) {
|
||||
resume();
|
||||
resume(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,11 +96,14 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
} else {
|
||||
options.data = request.postDataBuffer();
|
||||
}
|
||||
APIRequestContextImpl apiRequest = request.frame().page().context().request();
|
||||
if (fetchOptions != null && fetchOptions.timeout != null) {
|
||||
options.timeout = fetchOptions.timeout;
|
||||
}
|
||||
APIRequestContextImpl apiRequest = browserContext.request();
|
||||
String url = (fetchOptions == null || fetchOptions.url == null) ? request().url() : fetchOptions.url;
|
||||
return apiRequest.fetch(url, options);
|
||||
}
|
||||
|
||||
|
||||
private void applyOverrides(FallbackOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
@@ -110,7 +118,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
request().applyFallbackOverrides(overrides);
|
||||
}
|
||||
|
||||
private void resumeImpl(RequestImpl.FallbackOverrides options) {
|
||||
private void resumeImpl(RequestImpl.FallbackOverrides options, boolean isFallback) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (options != null) {
|
||||
if (options.url != null) {
|
||||
@@ -127,6 +135,8 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
params.addProperty("postData", base64);
|
||||
}
|
||||
}
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
params.addProperty("isFallback", isFallback);
|
||||
sendMessageAsync("continue", params);
|
||||
}
|
||||
|
||||
@@ -221,6 +231,7 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
if (fetchResponseUid != null) {
|
||||
params.addProperty("fetchResponseUid", fetchResponseUid);
|
||||
}
|
||||
params.addProperty("requestUrl", request.initializer.get("url").getAsString());
|
||||
sendMessageAsync("fulfill", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ class Router {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
int size() {
|
||||
return routes.size();
|
||||
void removeAll() {
|
||||
routes.clear();
|
||||
}
|
||||
|
||||
enum HandleResult { NoMatchingHandler, Handled, Fallback, PendingHandler }
|
||||
|
||||
@@ -17,22 +17,16 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.Selectors;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
class SelectorsImpl extends ChannelOwner {
|
||||
SelectorsImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
void registerImpl(String name, String script, Selectors.RegisterOptions options) {
|
||||
void register(String name, String script, Selectors.RegisterOptions options) {
|
||||
if (options == null) {
|
||||
options = new Selectors.RegisterOptions();
|
||||
}
|
||||
@@ -41,4 +35,10 @@ class SelectorsImpl extends ChannelOwner {
|
||||
params.addProperty("source", script);
|
||||
sendMessage("register", params);
|
||||
}
|
||||
|
||||
void setTestIdAttributeName(String name) {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("testIdAttributeName", name);
|
||||
sendMessageAsync("setTestIdAttributeName", params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigInteger;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -162,6 +163,8 @@ class Serialization {
|
||||
result.d = ((LocalDateTime)value).atZone(ZoneId.systemDefault()).toInstant().toString();
|
||||
} else if (value instanceof URL) {
|
||||
result.u = ((URL)value).toString();
|
||||
} else if (value instanceof BigInteger) {
|
||||
result.bi = ((BigInteger)value).toString();
|
||||
} else if (value instanceof Pattern) {
|
||||
result.r = new SerializedValue.R();
|
||||
result.r.p = ((Pattern)value).pattern();
|
||||
@@ -236,6 +239,9 @@ class Serialization {
|
||||
throw new PlaywrightException("Unexpected value: " + value.u, e);
|
||||
}
|
||||
}
|
||||
if (value.bi != null) {
|
||||
return (T) new BigInteger(value.bi);
|
||||
}
|
||||
if (value.d != null)
|
||||
return (T)(Date.from(Instant.parse(value.d)));
|
||||
if (value.r != null)
|
||||
@@ -274,6 +280,16 @@ class Serialization {
|
||||
}
|
||||
return (T) map;
|
||||
}
|
||||
if (value.m != null) {
|
||||
Map<?, ?> map = new LinkedHashMap<>();
|
||||
idToValue.put(value.id, map);
|
||||
return (T) map;
|
||||
}
|
||||
if (value.se != null) {
|
||||
Map<?, ?> map = new LinkedHashMap<>();
|
||||
idToValue.put(value.id, map);
|
||||
return (T) map;
|
||||
}
|
||||
throw new PlaywrightException("Unexpected result: " + gson().toJson(value));
|
||||
}
|
||||
|
||||
@@ -330,6 +346,11 @@ class Serialization {
|
||||
}
|
||||
|
||||
static JsonArray toProtocol(Map<String, String> map) {
|
||||
for (String value : map.values()) {
|
||||
if (value == null) {
|
||||
throw new PlaywrightException("Value cannot be null");
|
||||
}
|
||||
}
|
||||
return toNameValueArray(map);
|
||||
}
|
||||
|
||||
@@ -348,7 +369,11 @@ class Serialization {
|
||||
for (Map.Entry<String, ?> e : map.entrySet()) {
|
||||
JsonObject item = new JsonObject();
|
||||
item.addProperty("name", e.getKey());
|
||||
item.add("value", gson().toJsonTree(e.getValue()));
|
||||
if (e.getValue() instanceof FilePayload) {
|
||||
item.add("value", gson().toJsonTree(e.getValue()));
|
||||
} else {
|
||||
item.addProperty("value", "" + e.getValue());
|
||||
}
|
||||
array.add(item);
|
||||
}
|
||||
return array;
|
||||
|
||||
@@ -25,13 +25,14 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.impl.LocatorUtils.setTestIdAttributeName;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class SharedSelectors extends LoggingSupport implements Selectors {
|
||||
private final List<SelectorsImpl> channels = new ArrayList<>();
|
||||
private final List<Registration> registrations = new ArrayList<>();
|
||||
|
||||
String testIdAttributeName = "data-testid";
|
||||
|
||||
private static class Registration {
|
||||
final String name;
|
||||
final String script;
|
||||
@@ -64,12 +65,22 @@ public class SharedSelectors extends LoggingSupport implements Selectors {
|
||||
|
||||
@Override
|
||||
public void setTestIdAttribute(String attributeName) {
|
||||
// TODO: set it per playwright insttance
|
||||
setTestIdAttributeName(attributeName);
|
||||
if (attributeName == null) {
|
||||
throw new PlaywrightException("Test id attribute cannot be null");
|
||||
}
|
||||
testIdAttributeName = attributeName;
|
||||
channels.forEach(channel -> channel.setTestIdAttributeName(testIdAttributeName));
|
||||
}
|
||||
|
||||
void addChannel(SelectorsImpl channel) {
|
||||
registrations.forEach(r -> channel.registerImpl(r.name, r.script, r.options));
|
||||
registrations.forEach(r -> {
|
||||
try {
|
||||
channel.register(r.name, r.script, r.options);
|
||||
} catch (PlaywrightException e) {
|
||||
// This should not fail except for connection closure, but just in case we catch.
|
||||
}
|
||||
channel.setTestIdAttributeName(testIdAttributeName);
|
||||
});
|
||||
channels.add(channel);
|
||||
}
|
||||
|
||||
@@ -78,7 +89,7 @@ public class SharedSelectors extends LoggingSupport implements Selectors {
|
||||
}
|
||||
|
||||
private void registerImpl(String name, String script, RegisterOptions options) {
|
||||
channels.forEach(impl -> impl.registerImpl(name, script, options));
|
||||
channels.forEach(impl -> impl.register(name, script, options));
|
||||
registrations.add(new Registration(name, script, options));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ class StackTraceCollector {
|
||||
JsonObject jsonFrame = new JsonObject();
|
||||
jsonFrame.addProperty("file", sourceFile(frame));
|
||||
jsonFrame.addProperty("line", frame.getLineNumber());
|
||||
jsonFrame.addProperty("column", 0);
|
||||
jsonFrame.addProperty("function", frame.getClassName() + "." + frame.getMethodName());
|
||||
jsonStack.add(jsonFrame);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
public class TargetClosedError extends PlaywrightException {
|
||||
public TargetClosedError() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public TargetClosedError(String message) {
|
||||
super(message != null ? message : "Target page, context or browser has been closed");
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,18 @@ class TimeoutSettings {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
void setDefaultTimeout(double timeout) {
|
||||
Double defaultTimeout() {
|
||||
return defaultTimeout;
|
||||
}
|
||||
Double defaultNavigationTimeout() {
|
||||
return defaultNavigationTimeout;
|
||||
}
|
||||
|
||||
void setDefaultTimeout(Double timeout) {
|
||||
defaultTimeout = timeout;
|
||||
}
|
||||
|
||||
void setDefaultNavigationTimeout(double timeout) {
|
||||
void setDefaultNavigationTimeout(Double timeout) {
|
||||
defaultNavigationTimeout = timeout;
|
||||
}
|
||||
|
||||
@@ -73,5 +80,4 @@ class TimeoutSettings {
|
||||
}
|
||||
return new WaitableTimeout<>(timeout(timeout));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.Tracing;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -26,86 +25,112 @@ import java.nio.file.Path;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
|
||||
class TracingImpl extends ChannelOwner implements Tracing {
|
||||
private boolean includeSources;
|
||||
private Path tracesDir;
|
||||
private boolean isTracing;
|
||||
private String stacksId;
|
||||
|
||||
|
||||
TracingImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
private void stopChunkImpl(Path path) {
|
||||
JsonObject params = new JsonObject();
|
||||
String mode = "doNotSave";
|
||||
if (path != null) {
|
||||
if (connection.isRemote) {
|
||||
mode = "compressTrace";
|
||||
} else {
|
||||
mode = "compressTraceAndSources";
|
||||
}
|
||||
if (isTracing) {
|
||||
isTracing = false;
|
||||
connection.setIsTracing(false);
|
||||
}
|
||||
params.addProperty("mode", mode);
|
||||
JsonObject params = new JsonObject();
|
||||
|
||||
// Not interested in artifacts.
|
||||
if (path == null) {
|
||||
params.addProperty("mode", "discard");
|
||||
sendMessage("tracingStopChunk", params);
|
||||
if (stacksId != null) {
|
||||
connection.localUtils().traceDiscarded(stacksId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isLocal = !connection.isRemote;
|
||||
if (isLocal) {
|
||||
params.addProperty("mode", "entries");
|
||||
JsonObject json = sendMessage("tracingStopChunk", params).getAsJsonObject();
|
||||
JsonArray entries = json.getAsJsonArray("entries");
|
||||
connection.localUtils.zip(path, entries, stacksId, false, includeSources);
|
||||
return;
|
||||
}
|
||||
|
||||
params.addProperty("mode", "archive");
|
||||
JsonObject json = sendMessage("tracingStopChunk", params).getAsJsonObject();
|
||||
// The artifact may be missing if the browser closed while stopping tracing.
|
||||
if (!json.has("artifact")) {
|
||||
if (stacksId != null) {
|
||||
connection.localUtils().traceDiscarded(stacksId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject("artifact").get("guid").getAsString());
|
||||
artifact.saveAs(path);
|
||||
artifact.delete();
|
||||
|
||||
// Add local sources to the remote trace if necessary.
|
||||
// In case of CDP connection since the connection is established by
|
||||
// the driver it is safe to consider the artifact local.
|
||||
if (connection.isRemote && json.has("sourceEntries")) {
|
||||
JsonArray entries = json.getAsJsonArray("sourceEntries");
|
||||
connection.localUtils.zip(path, entries);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(StartOptions options) {
|
||||
withLogging("Tracing.start", () -> startImpl(options));
|
||||
connection.localUtils.zip(path, new JsonArray(), stacksId, true, includeSources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startChunk(StartChunkOptions options) {
|
||||
withLogging("Tracing.startChunk", () -> {
|
||||
startChunkImpl(options);
|
||||
});
|
||||
}
|
||||
|
||||
private void startChunkImpl(StartChunkOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartChunkOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
sendMessage("tracingStartChunk", params);
|
||||
tracingStartChunk(options.name, options.title);
|
||||
}
|
||||
|
||||
private void startImpl(StartOptions options) {
|
||||
private void tracingStartChunk(String name, String title) {
|
||||
JsonObject params = new JsonObject();
|
||||
if (name != null) {
|
||||
params.addProperty("name", name);
|
||||
}
|
||||
if (title != null) {
|
||||
params.addProperty("title", title);
|
||||
}
|
||||
JsonObject result = sendMessage("tracingStartChunk", params).getAsJsonObject();
|
||||
startCollectingStacks(result.get("traceName").getAsString());
|
||||
}
|
||||
|
||||
private void startCollectingStacks(String traceName) {
|
||||
if (!isTracing) {
|
||||
isTracing = true;
|
||||
connection.setIsTracing(true);
|
||||
}
|
||||
stacksId = connection.localUtils().tracingStarted(tracesDir == null ? null : tracesDir.toString(), traceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(StartOptions options) {
|
||||
if (options == null) {
|
||||
options = new StartOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
boolean includeSources = options.sources != null && options.sources;
|
||||
includeSources = options.sources != null && options.sources;
|
||||
if (includeSources) {
|
||||
if (!connection.isCollectingStacks()) {
|
||||
throw new PlaywrightException("Source root directory must be specified via PLAYWRIGHT_JAVA_SRC environment variable when source collection is enabled");
|
||||
}
|
||||
params.addProperty("sources", true);
|
||||
}
|
||||
sendMessage("tracingStart", params);
|
||||
sendMessage("tracingStartChunk");
|
||||
tracingStartChunk(options.name, options.title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(StopOptions options) {
|
||||
withLogging("Tracing.stop", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
sendMessage("tracingStop");
|
||||
});
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
sendMessage("tracingStop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopChunk(StopChunkOptions options) {
|
||||
withLogging("Tracing.stopChunk", () -> {
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
});
|
||||
stopChunkImpl(options == null ? null : options.path);
|
||||
}
|
||||
|
||||
void setTracesDir(Path tracesDir) {
|
||||
this.tracesDir = tracesDir;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
@@ -90,6 +90,11 @@ class UrlMatcher {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
UrlMatcher that = (UrlMatcher) o;
|
||||
if (rawSource instanceof Pattern && that.rawSource instanceof Pattern) {
|
||||
Pattern a = (Pattern) rawSource;
|
||||
Pattern b = (Pattern) that.rawSource;
|
||||
return a.pattern().equals(b.pattern()) && a.flags() == b.flags();
|
||||
}
|
||||
return Objects.equals(rawSource, that.rawSource);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.HttpHeader;
|
||||
import com.microsoft.playwright.options.SelectOption;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -31,12 +30,13 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.toJsonArray;
|
||||
|
||||
class Utils {
|
||||
public class Utils {
|
||||
static <F, T> T convertType(F f, Class<T> t) {
|
||||
if (f == null) {
|
||||
return null;
|
||||
@@ -80,7 +80,16 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('/', '$', '^', '+', '.', '(', ')', '=', '!', '|'));
|
||||
public static <T> T clone(T f) {
|
||||
if (f == null) {
|
||||
return f;
|
||||
}
|
||||
return convertType(f, (Class<T>) f.getClass());
|
||||
}
|
||||
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
||||
static Set<Character> escapeGlobChars = new HashSet<>(Arrays.asList('$', '^', '+', '.', '*', '(', ')', '|', '\\', '?', '{', '}', '[', ']'));
|
||||
|
||||
static String globToRegex(String glob) {
|
||||
StringBuilder tokens = new StringBuilder();
|
||||
@@ -88,8 +97,12 @@ class Utils {
|
||||
boolean inGroup = false;
|
||||
for (int i = 0; i < glob.length(); ++i) {
|
||||
char c = glob.charAt(i);
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append("\\").append(c);
|
||||
if (c == '\\' && i + 1 < glob.length()) {
|
||||
char nextChar = glob.charAt(++i);
|
||||
if (escapeGlobChars.contains(nextChar)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(nextChar);
|
||||
continue;
|
||||
}
|
||||
if (c == '*') {
|
||||
@@ -114,6 +127,12 @@ class Utils {
|
||||
case '?':
|
||||
tokens.append('.');
|
||||
break;
|
||||
case '[':
|
||||
tokens.append('[');
|
||||
break;
|
||||
case ']':
|
||||
tokens.append(']');
|
||||
break;
|
||||
case '{':
|
||||
inGroup = true;
|
||||
tokens.append('(');
|
||||
@@ -130,7 +149,11 @@ class Utils {
|
||||
tokens.append("\\").append(c);
|
||||
break;
|
||||
default:
|
||||
if (escapeGlobChars.contains(c)) {
|
||||
tokens.append('\\');
|
||||
}
|
||||
tokens.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokens.append('$');
|
||||
@@ -150,27 +173,21 @@ class Utils {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
static final int maxUplodBufferSize = 50 * 1024 * 1024;
|
||||
|
||||
static boolean hasLargeFile(Path[] files) {
|
||||
for (Path file: files) {
|
||||
try {
|
||||
if (Files.size(file)> maxUplodBufferSize) {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot get file size.", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void addLargeFileUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
|
||||
if (context.connection.isRemote) {
|
||||
static void addFilePathUploadParams(Path[] files, JsonObject params, BrowserContextImpl context) {
|
||||
if (files.length == 0) {
|
||||
// FIXME: shouldBeAbleToResetSelectedFilesWithEmptyFileList tesst hangs in Chromium if we pass empty paths list.
|
||||
params.add("payloads", new JsonArray());
|
||||
} else if (context.connection.isRemote) {
|
||||
List<WritableStream> streams = new ArrayList<>();
|
||||
JsonArray jsonStreams = new JsonArray();
|
||||
for (Path path : files) {
|
||||
WritableStream temp = context.createTempFile(path.getFileName().toString());
|
||||
long lastModifiedMs;
|
||||
try {
|
||||
lastModifiedMs = Files.getLastModifiedTime(path).toMillis();
|
||||
} catch (IOException e) {
|
||||
throw new PlaywrightException("Cannot read file timestamp: " + path, e);
|
||||
}
|
||||
WritableStream temp = context.createTempFile(path.getFileName().toString(), lastModifiedMs);
|
||||
streams.add(temp);
|
||||
try (OutputStream out = temp.stream()) {
|
||||
Files.copy(path, out);
|
||||
@@ -193,10 +210,12 @@ class Utils {
|
||||
}
|
||||
|
||||
static void checkFilePayloadSize(FilePayload[] files) {
|
||||
long totalSize = 0;
|
||||
for (FilePayload file: files) {
|
||||
if (file.buffer.length > maxUplodBufferSize) {
|
||||
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
|
||||
}
|
||||
totalSize += file.buffer.length;
|
||||
}
|
||||
if (totalSize > 50 * 1024 * 1024) {
|
||||
throw new PlaywrightException("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +262,7 @@ class Utils {
|
||||
static void writeToFile(InputStream inputStream, Path path) {
|
||||
mkParentDirs(path);
|
||||
try (FileOutputStream out = new FileOutputStream(path.toFile())) {
|
||||
byte[] buf = new byte[8192];
|
||||
byte[] buf = new byte[1024 * 1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buf)) > 0) {
|
||||
out.write(buf, 0, length);
|
||||
@@ -322,4 +341,8 @@ class Utils {
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
static String addSourceUrlToScript(String source, Path path) {
|
||||
return source + "\n//# sourceURL=" + path.toString().replace("\n", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 java.util.function.BooleanSupplier;
|
||||
|
||||
class WaitablePredicate<T> implements Waitable<T> {
|
||||
private final BooleanSupplier predicate;
|
||||
|
||||
WaitablePredicate(BooleanSupplier predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return predicate.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.WebError;
|
||||
|
||||
public class WebErrorImpl implements WebError {
|
||||
private final PageImpl page;
|
||||
private final String error;
|
||||
|
||||
WebErrorImpl(PageImpl page, String error) {
|
||||
this.page = page;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageImpl page() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -28,6 +44,12 @@ class WritableStream extends ChannelOwner {
|
||||
params.addProperty("binary", new String(encoded.array(), StandardCharsets.UTF_8));
|
||||
sendMessage("write", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
sendMessage("close");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.junit;
|
||||
|
||||
import com.microsoft.playwright.APIRequest;
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> this API is experimental and is subject to changes.
|
||||
*
|
||||
* <p> Instances of this class are expected to be created by custom {@link OptionsFactory}
|
||||
* implementations. Implement custom factories to provide custom Playwright configurations.
|
||||
*
|
||||
* <p> For more details and usage examples see our
|
||||
* <a href="https://playwright.dev/java/docs/junit">JUnit guide</a>.
|
||||
*/
|
||||
public class Options {
|
||||
public String baseUrl;
|
||||
public String channel;
|
||||
public Boolean headless;
|
||||
public String browserName;
|
||||
public String deviceName;
|
||||
// Custom attribute to be used in page.getByTestId(). data-testid is used by default.
|
||||
public String testIdAttribute;
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
public BrowserType.LaunchOptions launchOptions;
|
||||
public Browser.NewContextOptions contextOptions;
|
||||
public APIRequest.NewContextOptions apiRequestOptions;
|
||||
public Playwright.CreateOptions playwrightCreateOptions;
|
||||
|
||||
public Options setPlaywrightCreateOptions(Playwright.CreateOptions playwrightCreateOptions) {
|
||||
this.playwrightCreateOptions = playwrightCreateOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setLaunchOptions(BrowserType.LaunchOptions launchOptions) {
|
||||
this.launchOptions = launchOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setContextOptions(Browser.NewContextOptions contextOptions) {
|
||||
this.contextOptions = contextOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setApiRequestOptions(APIRequest.NewContextOptions apiRequestOptions) {
|
||||
this.apiRequestOptions = apiRequestOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setTestIdAttribute(String name) {
|
||||
this.testIdAttribute = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setBrowserName(String browserName) {
|
||||
this.browserName = browserName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setHeadless(Boolean headless) {
|
||||
this.headless = headless;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Options setIgnoreHTTPSErrors(Boolean ignoreHTTPSErrors) {
|
||||
this.ignoreHTTPSErrors = ignoreHTTPSErrors;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> this API is experimental and is subject to changes.
|
||||
*
|
||||
* <p> Implement this interface to pass custom options to {@link UsePlaywright}
|
||||
* annotation.
|
||||
*
|
||||
* <p> An example of implementing {@code @OptionsFactory}:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.junit.Options;
|
||||
* import com.microsoft.playwright.junit.OptionsFactory;
|
||||
* import com.microsoft.playwright.junit.UsePlaywright;
|
||||
*
|
||||
* @UsePlaywright(MyTest.CustomOptions.class)
|
||||
* public class MyTest {
|
||||
*
|
||||
* public static class CustomOptions implements OptionsFactory {
|
||||
* @Override
|
||||
* public Options getOptions() {
|
||||
* return new Options()
|
||||
* .setHeadless(false)
|
||||
* .setContextOption(new Browser.NewContextOptions()
|
||||
* .setBaseURL("https://github.com"))
|
||||
* .setApiRequestOptions(new APIRequest.NewContextOptions()
|
||||
* .setBaseURL("https://playwright.dev"));
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @Test
|
||||
* public void testWithCustomOptions(Page page, APIRequestContext request) {
|
||||
* page.navigate("/");
|
||||
* assertThat(page).hasURL(Pattern.compile("github"));
|
||||
*
|
||||
* APIResponse response = request.get("/");
|
||||
* assertTrue(response.text().contains("Playwright"));
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>For more details and usage examples see our
|
||||
* <a href="https://playwright.dev/java/docs/junit">JUnit guide</a>.
|
||||
*/
|
||||
public interface OptionsFactory {
|
||||
Options getOptions();
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.junit.impl.*;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <strong>NOTE:</strong> this API is experimental and is subject to changes.
|
||||
*
|
||||
* Use {@code @UsePlaywright} annotation to automatically manage Playwright objects
|
||||
* used in your test. Custom configuration can be provided by implementing
|
||||
* {@link OptionsFactory} and passing the class as a parameter.
|
||||
*
|
||||
* <p> When a test class is annotated with {@code @UsePlaywright} each test method can
|
||||
* use any of the following arguments that will be automatically created at run time:
|
||||
* <ul>
|
||||
* <li> {@link com.microsoft.playwright.Page Page page}</li>
|
||||
* <li> {@link com.microsoft.playwright.BrowserContext BrowserContext context}</li>
|
||||
* <li> {@link com.microsoft.playwright.Browser Browser browser}</li>
|
||||
* <li> {@link com.microsoft.playwright.APIRequestContext APIRequestContext request}</li>
|
||||
* <li> {@link com.microsoft.playwright.Playwright Playwright playwright}</li>
|
||||
* </ul>
|
||||
* {@code Page} and {@code BrowserContext} are created before each test and closed
|
||||
* after the test has finished. {@code Browser} and {@code Playwright} are reused
|
||||
* between tests for better efficiency.
|
||||
*
|
||||
* <p> An example of using {@code @UsePlaywright} annotation:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.Browser;
|
||||
* import com.microsoft.playwright.BrowserContext;
|
||||
* import com.microsoft.playwright.Page;
|
||||
* import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
* import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
*
|
||||
* @UsePlaywright
|
||||
* public class TestExample {
|
||||
* @Test
|
||||
* void shouldProvidePage(Page page) {
|
||||
* page.navigate("https://playwright.dev");
|
||||
* assertThat(page).hasURL("https://playwright.dev/");
|
||||
* }
|
||||
*
|
||||
* @Test
|
||||
* void shouldResolvePlaywrightObjects(Page page, BrowserContext context, Browser browser) {
|
||||
* assertEquals(context, page.context());
|
||||
* assertEquals(browser, context.browser());
|
||||
* assertNotNull(browser.version());
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p> For more details and usage examples see our
|
||||
* <a href="https://playwright.dev/java/docs/junit">JUnit guide</a>.
|
||||
*/
|
||||
@ExtendWith({OptionsExtension.class, PlaywrightExtension.class, BrowserExtension.class, BrowserContextExtension.class,
|
||||
PageExtension.class, APIRequestContextExtension.class})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface UsePlaywright {
|
||||
Class<? extends OptionsFactory> value() default DefaultOptions.class;
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.APIRequest;
|
||||
import com.microsoft.playwright.APIRequestContext;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
|
||||
public class APIRequestContextExtension implements ParameterResolver, BeforeEachCallback, AfterAllCallback {
|
||||
private static final ThreadLocal<APIRequestContext> threadLocalAPIRequestContext = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext extensionContext) {
|
||||
threadLocalAPIRequestContext.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterAll(ExtensionContext extensionContext) {
|
||||
threadLocalAPIRequestContext.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return isParameterSupported(parameterContext, extensionContext, APIRequestContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return getOrCreateAPIRequestContext(extensionContext);
|
||||
}
|
||||
|
||||
static APIRequestContext getOrCreateAPIRequestContext(ExtensionContext extensionContext) {
|
||||
APIRequestContext apiRequestContext = threadLocalAPIRequestContext.get();
|
||||
if (apiRequestContext != null) {
|
||||
return apiRequestContext;
|
||||
}
|
||||
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
||||
apiRequestContext = playwright.request().newContext(getContextOptions(options));
|
||||
threadLocalAPIRequestContext.set(apiRequestContext);
|
||||
return apiRequestContext;
|
||||
}
|
||||
|
||||
private static APIRequest.NewContextOptions getContextOptions(Options options) {
|
||||
APIRequest.NewContextOptions contextOptions = Utils.clone(options.apiRequestOptions);
|
||||
if(contextOptions == null) {
|
||||
contextOptions = new APIRequest.NewContextOptions();
|
||||
}
|
||||
|
||||
if(options.ignoreHTTPSErrors != null) {
|
||||
contextOptions.ignoreHTTPSErrors = options.ignoreHTTPSErrors;
|
||||
}
|
||||
return contextOptions;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserContext;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.*;
|
||||
|
||||
public class BrowserContextExtension implements ParameterResolver, AfterEachCallback {
|
||||
private static final ThreadLocal<BrowserContext> threadLocalBrowserContext = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext extensionContext) {
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
threadLocalBrowserContext.remove();
|
||||
if (browserContext != null) {
|
||||
browserContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return !isClassHook(extensionContext) && isParameterSupported(parameterContext, extensionContext, BrowserContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return getOrCreateBrowserContext(extensionContext);
|
||||
}
|
||||
|
||||
static BrowserContext getOrCreateBrowserContext(ExtensionContext extensionContext) {
|
||||
BrowserContext browserContext = threadLocalBrowserContext.get();
|
||||
if (browserContext != null) {
|
||||
return browserContext;
|
||||
}
|
||||
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
||||
setTestIdAttribute(playwright, options);
|
||||
Browser browser = BrowserExtension.getOrCreateBrowser(extensionContext);
|
||||
Browser.NewContextOptions contextOptions = getContextOptions(playwright, options);
|
||||
browserContext = browser.newContext(contextOptions);
|
||||
threadLocalBrowserContext.set(browserContext);
|
||||
return browserContext;
|
||||
}
|
||||
|
||||
private static Browser.NewContextOptions getContextOptions(Playwright playwright, Options options) {
|
||||
Browser.NewContextOptions contextOptions = Utils.clone(options.contextOptions);
|
||||
if (contextOptions == null) {
|
||||
contextOptions = new Browser.NewContextOptions();
|
||||
}
|
||||
|
||||
if (options.baseUrl != null) {
|
||||
contextOptions.setBaseURL(options.baseUrl);
|
||||
}
|
||||
|
||||
if (options.deviceName != null) {
|
||||
DeviceDescriptor deviceDescriptor = DeviceDescriptor.findByName(playwright, options.deviceName);
|
||||
if (deviceDescriptor == null) {
|
||||
throw new PlaywrightException("Unknown device name: " + options.deviceName);
|
||||
}
|
||||
contextOptions.userAgent = deviceDescriptor.userAgent;
|
||||
if (deviceDescriptor.viewport != null) {
|
||||
contextOptions.setViewportSize(deviceDescriptor.viewport.width, deviceDescriptor.viewport.height);
|
||||
}
|
||||
contextOptions.deviceScaleFactor = deviceDescriptor.deviceScaleFactor;
|
||||
contextOptions.isMobile = deviceDescriptor.isMobile;
|
||||
contextOptions.hasTouch = deviceDescriptor.hasTouch;
|
||||
}
|
||||
|
||||
if(options.ignoreHTTPSErrors != null) {
|
||||
contextOptions.setIgnoreHTTPSErrors(options.ignoreHTTPSErrors);
|
||||
}
|
||||
|
||||
return contextOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.impl.Utils;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
public class BrowserExtension implements ParameterResolver, AfterAllCallback {
|
||||
private static final ThreadLocal<Browser> threadLocalBrowser = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void afterAll(ExtensionContext extensionContext) {
|
||||
Browser browser = threadLocalBrowser.get();
|
||||
threadLocalBrowser.remove();
|
||||
if (browser != null) {
|
||||
browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return isParameterSupported(parameterContext, extensionContext, Browser.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return getOrCreateBrowser(extensionContext);
|
||||
}
|
||||
|
||||
static Browser getOrCreateBrowser(ExtensionContext extensionContext) {
|
||||
Browser browser = threadLocalBrowser.get();
|
||||
if (browser != null) {
|
||||
return browser;
|
||||
}
|
||||
|
||||
Options options = OptionsExtension.getOptions(extensionContext);
|
||||
Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext);
|
||||
BrowserType.LaunchOptions launchOptions = getLaunchOptions(options);
|
||||
|
||||
BrowserType browserType = playwright.chromium();
|
||||
if (options.browserName != null) {
|
||||
browserType = getBrowserTypeForName(playwright, options.browserName);
|
||||
} else if (options.deviceName != null) {
|
||||
DeviceDescriptor deviceDescriptor = DeviceDescriptor.findByName(playwright, options.deviceName);
|
||||
if (deviceDescriptor != null && deviceDescriptor.defaultBrowserType != null) {
|
||||
browserType = getBrowserTypeForName(playwright, deviceDescriptor.defaultBrowserType);
|
||||
}
|
||||
}
|
||||
browser = browserType.launch(launchOptions);
|
||||
|
||||
threadLocalBrowser.set(browser);
|
||||
return browser;
|
||||
}
|
||||
|
||||
private static BrowserType getBrowserTypeForName(Playwright playwright, String name) {
|
||||
switch (name) {
|
||||
case "webkit":
|
||||
return playwright.webkit();
|
||||
case "firefox":
|
||||
return playwright.firefox();
|
||||
case "chromium":
|
||||
return playwright.chromium();
|
||||
default:
|
||||
throw new PlaywrightException("Invalid browser name.");
|
||||
}
|
||||
}
|
||||
|
||||
private static BrowserType.LaunchOptions getLaunchOptions(Options options) {
|
||||
BrowserType.LaunchOptions launchOptions = Utils.clone(options.launchOptions);
|
||||
if (launchOptions == null) {
|
||||
launchOptions = new BrowserType.LaunchOptions();
|
||||
}
|
||||
|
||||
if (options.headless != null) {
|
||||
launchOptions.setHeadless(options.headless);
|
||||
}
|
||||
|
||||
if (options.channel != null) {
|
||||
launchOptions.setChannel(options.channel);
|
||||
}
|
||||
|
||||
return launchOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import com.microsoft.playwright.junit.OptionsFactory;
|
||||
|
||||
public class DefaultOptions implements OptionsFactory {
|
||||
@Override
|
||||
public Options getOptions() {
|
||||
return new Options();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.impl.PlaywrightImpl;
|
||||
import com.microsoft.playwright.options.ViewportSize;
|
||||
|
||||
class DeviceDescriptor {
|
||||
public String userAgent;
|
||||
public ViewportSize viewport;
|
||||
public Double deviceScaleFactor;
|
||||
public Boolean isMobile;
|
||||
public Boolean hasTouch;
|
||||
public String defaultBrowserType;
|
||||
|
||||
static DeviceDescriptor findByName(Playwright playwright, String name) {
|
||||
JsonArray devices = ((PlaywrightImpl) playwright).deviceDescriptors();
|
||||
JsonObject descriptor = null;
|
||||
for (JsonElement item : devices) {
|
||||
if (name.equals(item.getAsJsonObject().get("name").getAsString())) {
|
||||
descriptor = item.getAsJsonObject().getAsJsonObject("descriptor");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (descriptor == null) {
|
||||
return null;
|
||||
}
|
||||
return new Gson().fromJson(descriptor, DeviceDescriptor.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ParameterContext;
|
||||
import org.junit.platform.commons.support.AnnotationSupport;
|
||||
|
||||
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
|
||||
|
||||
class ExtensionUtils {
|
||||
static boolean hasUsePlaywrightAnnotation(ExtensionContext extensionContext) {
|
||||
return AnnotationSupport.isAnnotated(extensionContext.getTestClass(), UsePlaywright.class);
|
||||
}
|
||||
|
||||
static UsePlaywright getUsePlaywrightAnnotation(ExtensionContext extensionContext) {
|
||||
return findAnnotation(extensionContext.getTestClass(), UsePlaywright.class).get();
|
||||
}
|
||||
|
||||
static boolean isClassHook(ExtensionContext extensionContext) {
|
||||
return !extensionContext.getTestMethod().isPresent();
|
||||
}
|
||||
|
||||
static boolean isParameterSupported(ParameterContext parameterContext, ExtensionContext extensionContext, Class<?> subject) {
|
||||
if (!hasUsePlaywrightAnnotation(extensionContext)) {
|
||||
return false;
|
||||
}
|
||||
Class<?> clazz = parameterContext.getParameter().getType();
|
||||
return subject.equals(clazz);
|
||||
}
|
||||
|
||||
static void setTestIdAttribute(Playwright playwright, Options options) {
|
||||
String testIdAttribute = options.testIdAttribute == null ? "data-testid" : options.testIdAttribute;
|
||||
playwright.selectors().setTestIdAttribute(testIdAttribute);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.junit.Options;
|
||||
import com.microsoft.playwright.junit.OptionsFactory;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.getUsePlaywrightAnnotation;
|
||||
|
||||
public class OptionsExtension implements AfterAllCallback {
|
||||
private static final ThreadLocal<Options> threadLocalOptions = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void afterAll(ExtensionContext extensionContext) {
|
||||
threadLocalOptions.remove();
|
||||
}
|
||||
|
||||
static Options getOptions(ExtensionContext extensionContext) {
|
||||
Options options = threadLocalOptions.get();
|
||||
if (options != null) {
|
||||
return options;
|
||||
}
|
||||
|
||||
UsePlaywright usePlaywrightAnnotation = getUsePlaywrightAnnotation(extensionContext);
|
||||
try {
|
||||
options = usePlaywrightAnnotation.value().newInstance().getOptions();
|
||||
threadLocalOptions.set(options);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new PlaywrightException("Failed to create options", e);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright.junit.impl;
|
||||
|
||||
import com.microsoft.playwright.BrowserContext;
|
||||
import com.microsoft.playwright.Page;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isClassHook;
|
||||
import static com.microsoft.playwright.junit.impl.ExtensionUtils.isParameterSupported;
|
||||
|
||||
public class PageExtension implements ParameterResolver, AfterEachCallback {
|
||||
private static final ThreadLocal<Page> threadLocalPage = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext extensionContext) {
|
||||
Page page = threadLocalPage.get();
|
||||
threadLocalPage.remove();
|
||||
if (page != null) {
|
||||
page.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return !isClassHook(extensionContext) && isParameterSupported(parameterContext, extensionContext, Page.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
|
||||
return getOrCreatePage(extensionContext);
|
||||
}
|
||||
|
||||
static Page getOrCreatePage(ExtensionContext extensionContext) {
|
||||
Page page = threadLocalPage.get();
|
||||
if (page != null) {
|
||||
return page;
|
||||
}
|
||||
|
||||
BrowserContext browserContext = BrowserContextExtension.getOrCreateBrowserContext(extensionContext);
|
||||
page = browserContext.newPage();
|
||||
threadLocalPage.set(page);
|
||||
return page;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user