├── driver ├── src │ └── main │ │ ├── resources │ │ └── .gitkeep │ │ └── java │ │ └── com │ │ └── microsoft │ │ └── playwright │ │ └── impl │ │ └── driver │ │ └── DriverLogging.java └── pom.xml ├── utils └── docker │ ├── .gitignore │ ├── README.md │ └── build.sh ├── playwright └── src │ ├── test │ ├── resources │ │ ├── empty.html │ │ ├── serviceworkers │ │ │ ├── empty │ │ │ │ ├── sw.js │ │ │ │ └── sw.html │ │ │ ├── fetch │ │ │ │ ├── style.css │ │ │ │ ├── sw.js │ │ │ │ └── sw.html │ │ │ └── fetchdummy │ │ │ │ ├── sw.html │ │ │ │ └── sw.js │ │ ├── simple.json │ │ ├── es6 │ │ │ ├── es6module.js │ │ │ ├── es6import.js │ │ │ ├── .eslintrc │ │ │ └── es6pathimport.js │ │ ├── file-to-upload.txt │ │ ├── har-sha1-main-response.txt │ │ ├── jscoverage │ │ │ ├── script1.js │ │ │ ├── script2.js │ │ │ ├── unused.html │ │ │ ├── eval.html │ │ │ ├── ranges.html │ │ │ ├── multiple.html │ │ │ ├── sourceurl.html │ │ │ ├── simple.html │ │ │ └── involved.html │ │ ├── title.html │ │ ├── frames │ │ │ ├── script.js │ │ │ ├── style.css │ │ │ ├── one-frame.html │ │ │ ├── child-redirect.html │ │ │ ├── redirect-my-parent.html │ │ │ ├── frameset.html │ │ │ ├── frame.html │ │ │ ├── two-frames.html │ │ │ ├── lazy-frame.html │ │ │ └── nested-frames.html │ │ ├── csscoverage │ │ │ ├── stylesheet1.css │ │ │ ├── stylesheet2.css │ │ │ ├── media.html │ │ │ ├── sourceurl.html │ │ │ ├── simple.html │ │ │ ├── unused.html │ │ │ ├── Dosis-Regular.ttf │ │ │ ├── multiple.html │ │ │ └── involved.html │ │ ├── global-var.html │ │ ├── injectedstyle.css │ │ ├── networkidle.html │ │ ├── one-style.css │ │ ├── cached │ │ │ ├── one-style.css │ │ │ └── one-style.html │ │ ├── networkidle-frame.html │ │ ├── tamperable.html │ │ ├── dummy_bad_browser_executable.js │ │ ├── csp.html │ │ ├── mobile.html │ │ ├── one-style.html │ │ ├── snapshot │ │ │ ├── one.css │ │ │ ├── two.css │ │ │ └── snapshot-with-css.html │ │ ├── pptr.png │ │ ├── to-do-notifications │ │ │ ├── README.md │ │ │ └── manifest.webapp │ │ ├── injectedfile.js │ │ ├── movie.mp4 │ │ ├── movie.ogv │ │ ├── digits │ │ │ ├── 0.png │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ └── 9.png │ │ ├── har.html │ │ ├── wasm │ │ │ ├── table2.wasm │ │ │ └── table2.html │ │ ├── keys │ │ │ └── keystore.jks │ │ ├── self-request.html │ │ ├── historyapi.html │ │ ├── redirectloop2.html │ │ ├── expectations │ │ │ ├── hide-should-work-firefox.png │ │ │ ├── hide-should-work-webkit.png │ │ │ ├── hide-should-work-chromium.png │ │ │ ├── remove-should-work-firefox.png │ │ │ ├── remove-should-work-webkit.png │ │ │ └── remove-should-work-chromium.png │ │ ├── formatted-number.html │ │ ├── client-certificates │ │ │ ├── server │ │ │ │ └── server_keystore.p12 │ │ │ ├── client │ │ │ │ ├── trusted │ │ │ │ │ ├── keystore.p12 │ │ │ │ │ └── csr.pem │ │ │ │ └── self-signed │ │ │ │ │ └── csr.pem │ │ │ ├── generate_java.sh │ │ │ └── README.md │ │ ├── consolelog.html │ │ ├── popup │ │ │ ├── window-open.html │ │ │ └── popup.html │ │ ├── background-color.html │ │ ├── sectionselectorengine.js │ │ ├── beforeunload.html │ │ ├── geolocation.html │ │ ├── dom.html │ │ ├── screenshots │ │ │ ├── translateZ.html │ │ │ ├── canvas.html │ │ │ └── controls.html │ │ ├── error.html │ │ ├── redirectloop1.html │ │ ├── input │ │ │ ├── fileupload.html │ │ │ ├── fileupload-multi.html │ │ │ ├── folderupload.html │ │ │ ├── rotatedButton.html │ │ │ ├── textarea.html │ │ │ ├── scrollable.html │ │ │ ├── button.html │ │ │ ├── checkbox.html │ │ │ ├── animating-button.html │ │ │ ├── touches.html │ │ │ └── keyboard.html │ │ ├── worker │ │ │ ├── worker.html │ │ │ └── worker.js │ │ ├── detect-touch.html │ │ ├── video_mp4.html │ │ ├── playground.html │ │ ├── video.html │ │ ├── css-transition.html │ │ ├── networkidle.js │ │ ├── web-animation.html │ │ ├── overflow.html │ │ ├── overflow-large.html │ │ ├── shadow.html │ │ ├── grid-iframe-in-shadow.html │ │ ├── wrappedlink.html │ │ ├── rotate-z.html │ │ ├── rotate-pseudo.html │ │ ├── download-blob.html │ │ ├── dynamic-oopif.html │ │ ├── checkerboard.html │ │ ├── button-overlay-oopif.html │ │ ├── rotate-z-shadow-dom.html │ │ ├── drag-n-drop.html │ │ ├── react.html │ │ ├── resetcss.html │ │ ├── deep-shadow.html │ │ ├── player.html │ │ ├── offscreenbuttons.html │ │ └── grid.html │ └── java │ │ └── com │ │ └── microsoft │ │ └── playwright │ │ ├── junit │ │ ├── FixtureAbstractClass.java │ │ ├── TestFixtureWithBaseClass.java │ │ ├── TestFixturesWithNestedClass.java │ │ ├── FixtureTest.java │ │ └── BrowserTypeParameterResolver.java │ │ ├── TestRequestGC.java │ │ ├── TestPageLocatorConvenience.java │ │ ├── TestBeforeunload.java │ │ ├── TestLocatorList.java │ │ ├── TestPageEventPopup.java │ │ ├── TestAutoClose.java │ │ ├── TestPageRequestIntercept.java │ │ ├── TestUnrouteBehavior.java │ │ ├── TestPageAddScriptTag.java │ │ ├── TestVideo.java │ │ ├── TestLocatorHighlight.java │ │ └── TestBrowserContextServiceWorkerPolicy.java │ └── main │ └── java │ └── com │ └── microsoft │ └── playwright │ ├── impl │ ├── WebSocketFrameImpl.java │ ├── Logger.java │ ├── Waitable.java │ ├── DriverException.java │ ├── Transport.java │ ├── junit │ │ └── DefaultOptions.java │ ├── WaitableNever.java │ ├── AssertionsTimeout.java │ ├── RemoteBrowser.java │ ├── WebErrorImpl.java │ ├── TargetClosedError.java │ ├── WaitablePredicate.java │ ├── TouchscreenImpl.java │ ├── WebSocketRouter.java │ ├── WaitableTimeout.java │ ├── WaitableRace.java │ └── LoggingSupport.java │ ├── options │ ├── Media.java │ ├── HarMode.java │ ├── Contrast.java │ ├── ForcedColors.java │ ├── HarNotFound.java │ ├── ScreenshotType.java │ ├── ScreenshotCaret.java │ ├── ScreenshotScale.java │ ├── MouseButton.java │ ├── ReducedMotion.java │ ├── ServiceWorkerPolicy.java │ ├── ColorScheme.java │ ├── HarContentPolicy.java │ ├── HttpCredentialsSend.java │ ├── SameSiteAttribute.java │ ├── ScreenshotAnimations.java │ ├── LoadState.java │ ├── FunctionCallback.java │ ├── RouteFromHarUpdateContentPolicy.java │ ├── WaitUntilState.java │ ├── KeyboardModifier.java │ ├── WaitForSelectorState.java │ ├── ElementState.java │ ├── ServerAddr.java │ ├── Position.java │ ├── HttpHeader.java │ ├── BrowserChannel.java │ ├── ScreenSize.java │ ├── ViewportSize.java │ ├── RecordVideoSize.java │ ├── BindingCallback.java │ ├── Location.java │ ├── BoundingBox.java │ ├── FilePayload.java │ ├── Clip.java │ ├── Sizes.java │ ├── Geolocation.java │ ├── SecurityDetails.java │ └── SelectOption.java │ ├── TimeoutError.java │ ├── PlaywrightException.java │ ├── WebSocketFrame.java │ ├── WebError.java │ └── CLI.java ├── scripts ├── DRIVER_VERSION ├── update_readme.sh ├── set_maven_version.sh ├── playwright.java ├── generate_api.sh ├── roll_driver.sh └── download_driver.sh ├── tools ├── api-generator │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── .gitignore │ └── pom.xml ├── test-local-installation │ ├── src │ │ └── README.md │ └── create_project_and_run_tests.sh ├── test-spring-boot-starter │ ├── package_and_run_async_test.sh │ └── pom.xml ├── test-cli-fatjar │ ├── test.sh │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── microsoft │ │ │ └── playwright │ │ │ └── testclifatjar │ │ │ └── TestApp.java │ └── pom.xml └── test-cli-version │ ├── src │ └── main │ │ └── java │ │ └── com │ │ └── microsoft │ │ └── playwright │ │ └── testcliversion │ │ └── TestApp.java │ ├── test.sh │ └── pom.xml ├── driver-bundle ├── src │ └── main │ │ └── resources │ │ └── .gitignore └── pom.xml ├── CodeQL.yml ├── .gitattributes ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── question.yml │ ├── feature.yml │ └── documentation.yml ├── dependabot.yml └── workflows │ ├── test_cli.yml │ ├── publish_docker.yml │ ├── verify_api.yml │ └── test_docker.yml ├── examples ├── README.md ├── src │ └── main │ │ └── java │ │ └── org │ │ └── example │ │ ├── PrintTitle.java │ │ ├── WebKitScreenshot.java │ │ ├── InterceptNetworkRequests.java │ │ ├── EvaluateInBrowserContext.java │ │ ├── PageScreenshot.java │ │ └── SelectorsAndKeyboardManipulation.java └── pom.xml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── ROLLING.md ├── SUPPORT.md └── .devcontainer └── devcontainer.json /driver/src/main/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /utils/docker/.gitignore: -------------------------------------------------------------------------------- 1 | oras/ 2 | 3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/empty.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/DRIVER_VERSION: -------------------------------------------------------------------------------- 1 | 1.57.0-beta-1764692940000 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/empty/sw.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /playwright/src/test/resources/simple.json: -------------------------------------------------------------------------------- 1 | {"foo": "bar"} 2 | -------------------------------------------------------------------------------- /tools/api-generator/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | api.json 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/es6/es6module.js: -------------------------------------------------------------------------------- 1 | export default 42; -------------------------------------------------------------------------------- /playwright/src/test/resources/file-to-upload.txt: -------------------------------------------------------------------------------- 1 | contents of the file -------------------------------------------------------------------------------- /playwright/src/test/resources/har-sha1-main-response.txt: -------------------------------------------------------------------------------- 1 | Hello, world -------------------------------------------------------------------------------- /driver-bundle/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | driver/ 2 | local-driver/ 3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/script1.js: -------------------------------------------------------------------------------- 1 | console.log(3); 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/script2.js: -------------------------------------------------------------------------------- 1 | console.log(3); 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/title.html: -------------------------------------------------------------------------------- 1 | Woof-Woof 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/script.js: -------------------------------------------------------------------------------- 1 | console.log('Cheers!'); 2 | -------------------------------------------------------------------------------- /CodeQL.yml: -------------------------------------------------------------------------------- 1 | path_classifiers: 2 | tests: 3 | - "playwright/src/test/**" 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | color: blue; 3 | } 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/stylesheet1.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/one-frame.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/global-var.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /playwright/src/test/resources/injectedstyle.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: red; 3 | } 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/unused.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/networkidle.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/one-style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: pink; 3 | } 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/cached/one-style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: pink; 3 | } 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/eval.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/networkidle-frame.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/tamperable.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/stylesheet2.css: -------------------------------------------------------------------------------- 1 | html { 2 | margin: 0; 3 | padding: 0; 4 | } 5 | -------------------------------------------------------------------------------- /playwright/src/test/resources/dummy_bad_browser_executable.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | process.exit(1); 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/es6/es6import.js: -------------------------------------------------------------------------------- 1 | import num from './es6module.js'; 2 | window.__es6injected = num; -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/child-redirect.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/fetch/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: pink; 3 | } 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csp.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/es6/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "sourceType": "module" 4 | } 5 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/es6/es6pathimport.js: -------------------------------------------------------------------------------- 1 | import num from './es6/es6module.js'; 2 | window.__es6injected = num; -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/ranges.html: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/mobile.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/one-style.html: -------------------------------------------------------------------------------- 1 | 2 |
hello, world!
3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/snapshot/one.css: -------------------------------------------------------------------------------- 1 | @import url(./two.css); 2 | 3 | body { 4 | background-color: pink; 5 | } 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/cached/one-style.html: -------------------------------------------------------------------------------- 1 | 2 |
hello, world!
3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/multiple.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/sourceurl.html: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/redirect-my-parent.html: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/pptr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/pptr.png -------------------------------------------------------------------------------- /playwright/src/test/resources/to-do-notifications/README.md: -------------------------------------------------------------------------------- 1 | Source: https://github.com/mdn/dom-examples/tree/main/to-do-notifications 2 | -------------------------------------------------------------------------------- /playwright/src/test/resources/injectedfile.js: -------------------------------------------------------------------------------- 1 | window.__injected = 42; 2 | window.injected = 123; 3 | window.__injectedError = new Error('hi'); -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/simple.html: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/movie.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/movie.mp4 -------------------------------------------------------------------------------- /playwright/src/test/resources/movie.ogv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/movie.ogv -------------------------------------------------------------------------------- /playwright/src/test/resources/snapshot/two.css: -------------------------------------------------------------------------------- 1 | .imaged { 2 | width: 200px; 3 | height: 200px; 4 | background: url(../pptr.png); 5 | } 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/0.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/1.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/2.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/3.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/4.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/5.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/6.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/7.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/8.png -------------------------------------------------------------------------------- /playwright/src/test/resources/digits/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/digits/9.png -------------------------------------------------------------------------------- /playwright/src/test/resources/har.html: -------------------------------------------------------------------------------- 1 | HAR Page 2 | 3 |
hello, world!
4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/media.html: -------------------------------------------------------------------------------- 1 | 3 |
hello, world
4 | 5 | -------------------------------------------------------------------------------- /playwright/src/test/resources/wasm/table2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/wasm/table2.wasm -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/sourceurl.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /playwright/src/test/resources/keys/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/keys/keystore.jks -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/simple.html: -------------------------------------------------------------------------------- 1 | 5 |
hello, world
6 | 7 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/empty/sw.html: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/unused.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /playwright/src/test/resources/self-request.html: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # text files must be lf for golden file tests to work 2 | * text=auto eol=lf 3 | 4 | # make project show as TS on GitHub 5 | *.js linguist-detectable=false 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/historyapi.html: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/Dosis-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/csscoverage/Dosis-Regular.ttf -------------------------------------------------------------------------------- /tools/test-local-installation/src/README.md: -------------------------------------------------------------------------------- 1 | This directory is populated with test files from playwright and playwright-driver projects. They are copied 2 | here on each test run. 3 | -------------------------------------------------------------------------------- /playwright/src/test/resources/redirectloop2.html: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/expectations/hide-should-work-firefox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/expectations/hide-should-work-firefox.png -------------------------------------------------------------------------------- /playwright/src/test/resources/expectations/hide-should-work-webkit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/expectations/hide-should-work-webkit.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /playwright/src/test/resources/expectations/hide-should-work-chromium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/expectations/hide-should-work-chromium.png -------------------------------------------------------------------------------- /playwright/src/test/resources/expectations/remove-should-work-firefox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/expectations/remove-should-work-firefox.png -------------------------------------------------------------------------------- /playwright/src/test/resources/expectations/remove-should-work-webkit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/expectations/remove-should-work-webkit.png -------------------------------------------------------------------------------- /playwright/src/test/resources/formatted-number.html: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/junit/FixtureAbstractClass.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.junit; 2 | 3 | @UsePlaywright 4 | public abstract class FixtureAbstractClass { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /playwright/src/test/resources/client-certificates/server/server_keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/client-certificates/server/server_keystore.p12 -------------------------------------------------------------------------------- /playwright/src/test/resources/expectations/remove-should-work-chromium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/expectations/remove-should-work-chromium.png -------------------------------------------------------------------------------- /playwright/src/test/resources/client-certificates/client/trusted/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/playwright-java/HEAD/playwright/src/test/resources/client-certificates/client/trusted/keystore.p12 -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Join our Discord Server 4 | url: https://aka.ms/playwright/discord 5 | about: Ask questions and discuss with other community members 6 | -------------------------------------------------------------------------------- /tools/test-spring-boot-starter/package_and_run_async_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | cd "$(dirname "$0")" 7 | mvn package -D skipTests --no-transfer-progress 8 | java -jar target/test-spring-boot-starter*.jar --async 9 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | This directory contains sample [`pom.xml`](./pom.xml) and source code for the Playwright examples. 2 | 3 | You can run them in terminal like this: 4 | 5 | ```sh 6 | mvn compile exec:java -Dexec.mainClass=org.example.PageScreenshot 7 | ``` 8 | -------------------------------------------------------------------------------- /playwright/src/test/resources/consolelog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | console.log test 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/frameset.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/fetch/sw.js: -------------------------------------------------------------------------------- 1 | self.addEventListener('fetch', event => { 2 | event.respondWith(fetch(event.request)); 3 | }); 4 | 5 | self.addEventListener('activate', event => { 6 | event.waitUntil(clients.claim()); 7 | }); 8 | -------------------------------------------------------------------------------- /tools/test-cli-fatjar/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap "cd $(pwd -P)" EXIT 7 | cd "$(dirname $0)" 8 | 9 | echo "Running TestApp..." 10 | mvn compile exec:java -e -Dexec.mainClass=com.microsoft.playwright.testclifatjar.TestApp 11 | -------------------------------------------------------------------------------- /playwright/src/test/resources/popup/window-open.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Popup test 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /utils/docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker build infra 2 | 3 | This folder contains the infra to build the Docker images for Java. It's based on 4 | the upstream code located in [`microsoft/playwright/utils/docker`](https://github.com/microsoft/playwright/tree/main/utils/docker). 5 | -------------------------------------------------------------------------------- /playwright/src/test/resources/background-color.html: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /playwright/src/test/resources/popup/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Popup 5 | 8 | 9 | 10 | I am a popup 11 | 12 | 13 | -------------------------------------------------------------------------------- /playwright/src/test/resources/sectionselectorengine.js: -------------------------------------------------------------------------------- 1 | ({ 2 | create(root, target) { 3 | }, 4 | query(root, selector) { 5 | return root.querySelector('section'); 6 | }, 7 | queryAll(root, selector) { 8 | return Array.from(root.querySelectorAll('section')); 9 | } 10 | }) -------------------------------------------------------------------------------- /playwright/src/test/resources/beforeunload.html: -------------------------------------------------------------------------------- 1 |
beforeunload demo.
2 | 10 | 11 | -------------------------------------------------------------------------------- /playwright/src/test/resources/geolocation.html: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # Package Files # 8 | *.jar 9 | *.zip 10 | *.tar.gz 11 | 12 | # Maven output dir 13 | target/ 14 | .project 15 | .classpath 16 | .settings 17 | .DS_Store 18 | *.swp 19 | .vscode 20 | 21 | .idea 22 | *.iml 23 | 24 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/fetch/sw.html: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/dom.html: -------------------------------------------------------------------------------- 1 |
Text, 2 | more text
3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /playwright/src/test/resources/screenshots/translateZ.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
-------------------------------------------------------------------------------- /playwright/src/test/resources/error.html: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /playwright/src/test/resources/redirectloop1.html: -------------------------------------------------------------------------------- 1 | > 10 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/multiple.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /playwright/src/test/resources/jscoverage/involved.html: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /playwright/src/test/resources/screenshots/canvas.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/fileupload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | File upload test 5 | 6 | 7 |
8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /playwright/src/test/resources/worker/worker.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Worker test 5 | 6 | 7 | 13 | 14 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 |
Hi, I'm frame
16 | -------------------------------------------------------------------------------- /playwright/src/test/resources/detect-touch.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Detect Touch Test 5 | 6 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/fileupload-multi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | File upload test 5 | 6 | 7 |
8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/folderupload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Folder upload test 5 | 6 | 7 |
8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /playwright/src/test/resources/client-certificates/generate_java.sh: -------------------------------------------------------------------------------- 1 | cd "$(dirname "$0")" 2 | CWD=$(pwd) 3 | 4 | cd server 5 | openssl pkcs12 -export -in server_cert.pem -inkey server_key.pem -out server_keystore.p12 -name myalias -passout pass: 6 | 7 | cd "$CWD/client/trusted" 8 | openssl pkcs12 -export -in cert.pem -inkey key.pem -out keystore.p12 -name myalias -passout pass: 9 | -------------------------------------------------------------------------------- /playwright/src/test/resources/video_mp4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 |

10 | Video courtesy of 11 | Big Buck Bunny. 12 |

13 | 14 | 15 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/two-frames.html: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /playwright/src/test/resources/wasm/table2.html: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /playwright/src/test/resources/playground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Playground 5 | 6 | 7 | 8 | 9 |
First div
10 |
11 | Second div 12 | Inner span 13 |
14 | 15 | -------------------------------------------------------------------------------- /playwright/src/test/resources/video.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 |

11 | Video courtesy of 12 | Big Buck Bunny. 13 |

14 | 15 | 16 | -------------------------------------------------------------------------------- /playwright/src/test/resources/client-certificates/README.md: -------------------------------------------------------------------------------- 1 | # Client Certificate test-certificates 2 | 3 | Regenerate all certificates by running: 4 | 5 | ``` 6 | bash generate.sh 7 | ``` 8 | 9 | ## Java: Convert PEM Files to PKCS12 10 | 11 | 12 | Java server understands only PKCS12 keys, after copying the certificates from Node.js Playwright we need to convert them. 13 | 14 | ``` 15 | bash generate_java.sh 16 | ``` 17 | -------------------------------------------------------------------------------- /playwright/src/test/resources/screenshots/controls.html: -------------------------------------------------------------------------------- 1 |

2 |

3 |

4 |

5 |

6 |

7 |

8 | -------------------------------------------------------------------------------- /playwright/src/test/resources/worker/worker.js: -------------------------------------------------------------------------------- 1 | console.log('hello from the worker'); 2 | 3 | function workerFunction() { 4 | return 'worker function result'; 5 | } 6 | 7 | self.addEventListener('message', event => { 8 | console.log('got this data: ' + event.data); 9 | }); 10 | 11 | (async function() { 12 | while (true) { 13 | self.postMessage(workerFunction.toString()); 14 | await new Promise(x => setTimeout(x, 100)); 15 | } 16 | })(); -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/lazy-frame.html: -------------------------------------------------------------------------------- 1 |
One
2 |
Two
3 |
Three
4 |
Four
5 |
Five
6 | 7 | -------------------------------------------------------------------------------- /tools/test-local-installation/create_project_and_run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap "cd $(pwd -P)" EXIT 7 | cd "$(dirname $0)" 8 | 9 | 10 | PROJECT_DIR=$(mktemp -d) 11 | echo "Creating project in $PROJECT_DIR" 12 | cp -R . $PROJECT_DIR 13 | cp -R ../../driver-bundle/src/test/ $PROJECT_DIR/src/ 14 | cp -R ../../playwright/src/test/ $PROJECT_DIR/src/ 15 | cd $PROJECT_DIR 16 | 17 | mvn test --no-transfer-progress 18 | 19 | rm -rf $PROJECT_DIR 20 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /scripts/update_readme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap "cd $(pwd -P)" EXIT 7 | 8 | cd "$(dirname $0)/.." 9 | 10 | # Remove artifacts from previous driver (for local builds). 11 | mvn clean 12 | 13 | # Built from source and do local install. 14 | mvn install --no-transfer-progress -D skipTests 15 | 16 | echo "Updating browser versions in README.md" 17 | mvn compile exec:java --f ./tools/update-docs-version -D exec.mainClass=com.microsoft.playwright.tools.UpdateBrowserVersions 18 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/fetchdummy/sw.html: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /playwright/src/test/resources/css-transition.html: -------------------------------------------------------------------------------- 1 | 2 | 16 |
17 | 22 | -------------------------------------------------------------------------------- /playwright/src/test/resources/networkidle.js: -------------------------------------------------------------------------------- 1 | async function sleep(delay) { 2 | return new Promise(resolve => setTimeout(resolve, delay)); 3 | } 4 | 5 | async function main() { 6 | window.ws = new WebSocket('ws://localhost:' + window.location.port + '/ws'); 7 | window.ws.addEventListener('message', message => {}); 8 | 9 | const roundOne = Promise.all([ 10 | fetch('fetch-request-a.js'), 11 | ]); 12 | 13 | await roundOne; 14 | await sleep(50); 15 | await fetch('fetch-request-d.js'); 16 | } 17 | 18 | main(); 19 | -------------------------------------------------------------------------------- /playwright/src/test/resources/web-animation.html: -------------------------------------------------------------------------------- 1 | 2 | 12 |
13 | 24 | -------------------------------------------------------------------------------- /scripts/set_maven_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | if [[ $# == 0 ]]; then 7 | echo "Missing version parameter." 8 | echo "Usage:" 9 | echo " $(basename $0) 0.170.3-SNAPSHOT" 10 | exit 1 11 | fi 12 | 13 | trap "cd $(pwd -P)" EXIT 14 | cd "$(dirname $0)/.." 15 | 16 | VERSION=$1 17 | POM_FILES=( 18 | pom.xml 19 | tools/*/pom.xml 20 | examples/pom.xml 21 | ) 22 | 23 | for name in ${POM_FILES[*]}; 24 | do 25 | mvn versions:set -D generateBackupPoms=false -D newVersion=$VERSION -f $name 26 | done 27 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/rotatedButton.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Rotated button test 5 | 6 | 7 | 8 | 9 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /playwright/src/test/resources/overflow.html: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 23 | -------------------------------------------------------------------------------- /playwright/src/test/resources/overflow-large.html: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 23 | -------------------------------------------------------------------------------- /playwright/src/test/resources/shadow.html: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /playwright/src/test/resources/grid-iframe-in-shadow.html: -------------------------------------------------------------------------------- 1 | 6 | 17 | -------------------------------------------------------------------------------- /tools/test-cli-version/src/main/java/com/microsoft/playwright/testcliversion/TestApp.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.testcliversion; 2 | 3 | import com.microsoft.playwright.Playwright; 4 | 5 | import java.io.IOException; 6 | 7 | public class TestApp { 8 | public static void main(String[] args) throws IOException, InterruptedException { 9 | String version = Playwright.class.getPackage().getImplementationVersion(); 10 | if (version == null) { 11 | throw new RuntimeException("FAIL: Version is null"); 12 | } 13 | System.out.println("ImplementationVersion " + version); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /playwright/src/test/resources/to-do-notifications/manifest.webapp: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1", 3 | "name": "To-do list", 4 | "description": "Store to-do items on your device, and be notified when the deadlines are up.", 5 | "launch_path": "/to-do-notifications/index.html", 6 | "icons": { 7 | "128": "/to-do-notifications/img/icon-128.png" 8 | }, 9 | "developer": { 10 | "name": "Chris Mills", 11 | "url": "http://chrisdavidmills.github.io/to-do-notifications/" 12 | }, 13 | "permissions": { 14 | "desktop-notification": { 15 | "description": "Needed for creating system notifications." 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/wrappedlink.html: -------------------------------------------------------------------------------- 1 | 25 |
26 | 123321 27 |
28 | 33 | -------------------------------------------------------------------------------- /playwright/src/test/resources/csscoverage/involved.html: -------------------------------------------------------------------------------- 1 | 24 |
woof!
25 | fancy text 26 | 27 | -------------------------------------------------------------------------------- /playwright/src/test/resources/serviceworkers/fetchdummy/sw.js: -------------------------------------------------------------------------------- 1 | self.addEventListener('fetch', event => { 2 | if (event.request.url.endsWith('.html') || event.request.url.includes('passthrough')) { 3 | event.respondWith(fetch(event.request)); 4 | return; 5 | } 6 | const slash = event.request.url.lastIndexOf('/'); 7 | const name = event.request.url.substring(slash + 1); 8 | const blob = new Blob(["responseFromServiceWorker:" + name], {type : 'text/css'}); 9 | const response = new Response(blob, { "status" : 200 , "statusText" : "OK" }); 10 | event.respondWith(response); 11 | }); 12 | 13 | self.addEventListener('activate', event => { 14 | event.waitUntil(clients.claim()); 15 | }); 16 | -------------------------------------------------------------------------------- /playwright/src/test/resources/rotate-z.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/textarea.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Textarea test 5 | 6 | 7 | 8 | 9 |
10 |
Plain div
11 | 12 | 19 | 20 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/junit/TestFixtureWithBaseClass.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.junit; 2 | 3 | import com.microsoft.playwright.Page; 4 | import org.junit.jupiter.api.Nested; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; 8 | 9 | public class TestFixtureWithBaseClass extends FixtureAbstractClass { 10 | 11 | @Test 12 | void worksWithBaseClassProvidingFixtures(Page page) { 13 | assertNotNull(page); 14 | } 15 | 16 | @Nested 17 | public class NestedClass { 18 | @Test 19 | void worksWithNestedClassInsideClassThatExtendsBaseClassThatProvidesFixtures(Page page) { 20 | assertNotNull(page); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WebSocketFrameImpl.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.impl; 2 | 3 | import com.microsoft.playwright.WebSocketFrame; 4 | 5 | import java.nio.charset.StandardCharsets; 6 | import java.util.Base64; 7 | 8 | class WebSocketFrameImpl implements WebSocketFrame { 9 | private byte[] bytes; 10 | private String text; 11 | 12 | WebSocketFrameImpl(String payload, boolean isBase64) { 13 | if (isBase64) { 14 | bytes = Base64.getDecoder().decode(payload); 15 | } else { 16 | text = payload; 17 | } 18 | } 19 | 20 | @Override 21 | public byte[] binary() { 22 | return bytes; 23 | } 24 | 25 | @Override 26 | public String text() { 27 | return text; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /playwright/src/test/resources/frames/nested-frames.html: -------------------------------------------------------------------------------- 1 | 19 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Media.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum Media { 20 | SCREEN, 21 | PRINT 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/Logger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | interface Logger { 20 | void log(String message); 21 | } 22 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/HarMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum HarMode { 20 | FULL, 21 | MINIMAL 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Contrast.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum Contrast { 20 | NO_PREFERENCE, 21 | MORE 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ForcedColors.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ForcedColors { 20 | ACTIVE, 21 | NONE 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/HarNotFound.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum HarNotFound { 20 | ABORT, 21 | FALLBACK 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ScreenshotType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ScreenshotType { 20 | PNG, 21 | JPEG 22 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/input/scrollable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scrollable test 5 | 6 | 7 | 8 | 22 | 23 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ScreenshotCaret.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ScreenshotCaret { 20 | HIDE, 21 | INITIAL 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ScreenshotScale.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ScreenshotScale { 20 | CSS, 21 | DEVICE 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/MouseButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum MouseButton { 20 | LEFT, 21 | RIGHT, 22 | MIDDLE 23 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ReducedMotion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ReducedMotion { 20 | REDUCE, 21 | NO_PREFERENCE 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ServiceWorkerPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ServiceWorkerPolicy { 20 | ALLOW, 21 | BLOCK 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ColorScheme.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ColorScheme { 20 | LIGHT, 21 | DARK, 22 | NO_PREFERENCE 23 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/HarContentPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum HarContentPolicy { 20 | OMIT, 21 | EMBED, 22 | ATTACH 23 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/HttpCredentialsSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum HttpCredentialsSend { 20 | UNAUTHORIZED, 21 | ALWAYS 22 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/SameSiteAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum SameSiteAttribute { 20 | STRICT, 21 | LAX, 22 | NONE 23 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ScreenshotAnimations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ScreenshotAnimations { 20 | DISABLED, 21 | ALLOW 22 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/rotate-pseudo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 28 | 29 | 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/LoadState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum LoadState { 20 | LOAD, 21 | DOMCONTENTLOADED, 22 | NETWORKIDLE 23 | } -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/junit/TestFixturesWithNestedClass.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.junit; 2 | 3 | import com.microsoft.playwright.Page; 4 | import org.junit.jupiter.api.Nested; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; 8 | 9 | @FixtureTest 10 | @UsePlaywright 11 | public class TestFixturesWithNestedClass { 12 | 13 | @Test 14 | void worksWithOuterClass(Page page) { 15 | assertNotNull(page); 16 | } 17 | 18 | @Nested 19 | class NestedClass { 20 | @Test 21 | void worksWithNestedClasses(Page page) { 22 | assertNotNull(page); 23 | } 24 | 25 | @Nested 26 | class DeeplyNestedClass { 27 | @Test 28 | void worksWithDeeplyNestedClass(Page page) { 29 | assertNotNull(page); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/FunctionCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public interface FunctionCallback { 20 | Object call(Object... args); 21 | } 22 | -------------------------------------------------------------------------------- /ROLLING.md: -------------------------------------------------------------------------------- 1 | # Rolling Playwright-Java to the latest Playwright driver 2 | 3 | * make sure to have at least Java 8 and Maven 3.6.3 4 | * clone playwright for java: http://github.com/microsoft/playwright-java 5 | * `./scripts/roll_driver.sh 1.47.0-beta-1726138322000` 6 | * commit & send PR with the roll 7 | 8 | ## Finding driver version 9 | 10 | 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` 11 | image 12 | 13 | 14 | # Updating Version 15 | 16 | ```bash 17 | ./scripts/set_maven_version.sh 1.15.0 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/RouteFromHarUpdateContentPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum RouteFromHarUpdateContentPolicy { 20 | EMBED, 21 | ATTACH 22 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" # Location of the pom.xml file 5 | schedule: 6 | interval: "monthly" 7 | open-pull-requests-limit: 10 8 | groups: 9 | # Create a group of dependencies to be updated together in one pull request 10 | all: 11 | applies-to: version-updates 12 | patterns: 13 | - "*" 14 | update-types: 15 | - "minor" 16 | - "patch" 17 | allow: 18 | - dependency-type: "direct" # Optional: Only update direct dependencies 19 | - dependency-type: "indirect" # Optional: Only update indirect (transitive) dependencies 20 | - package-ecosystem: "github-actions" 21 | directory: "/" 22 | schedule: 23 | interval: "monthly" 24 | groups: 25 | actions: 26 | patterns: 27 | - "*" 28 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses GitHub issues to track bugs and feature requests. Please search the [existing issues][gh-issues] before filing new ones to avoid duplicates. For new issues, file your bug or feature request as a new issue using corresponding template. 6 | 7 | For help and questions about using this project, please see the [docs site for Playwright for Java][docs]. 8 | 9 | Join our community [Discord Server][discord-server] to connect with other developers using Playwright and ask questions in our 'help-playwright' forum. 10 | 11 | ## Microsoft Support Policy 12 | 13 | Support for Playwright for Java is limited to the resources listed above. 14 | 15 | [gh-issues]: https://github.com/microsoft/playwright-java/issues/ 16 | [docs]: https://playwright.dev/java/ 17 | [discord-server]: https://aka.ms/playwright/discord 18 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/WaitUntilState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum WaitUntilState { 20 | LOAD, 21 | DOMCONTENTLOADED, 22 | NETWORKIDLE, 23 | COMMIT 24 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/KeyboardModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum KeyboardModifier { 20 | ALT, 21 | CONTROL, 22 | CONTROLORMETA, 23 | META, 24 | SHIFT 25 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/WaitForSelectorState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum WaitForSelectorState { 20 | ATTACHED, 21 | DETACHED, 22 | VISIBLE, 23 | HIDDEN 24 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/download-blob.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Blob Download Example 5 | 6 | 7 | 27 | Download 28 | 29 | 30 | -------------------------------------------------------------------------------- /playwright/src/test/resources/dynamic-oopif.html: -------------------------------------------------------------------------------- 1 | 13 | 32 | -------------------------------------------------------------------------------- /playwright/src/test/resources/checkerboard.html: -------------------------------------------------------------------------------- 1 | 2 | 8 | 35 | 36 |
37 |
38 |
39 |
40 |
41 |
42 | 43 | -------------------------------------------------------------------------------- /driver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.microsoft.playwright 8 | parent-pom 9 | 1.50.0-SNAPSHOT 10 | 11 | 12 | driver 13 | Playwright - Driver 14 | 15 | This module provides API for discovery and launching of Playwright driver. 16 | 17 | 18 | 19 | 20 | org.junit.jupiter 21 | junit-jupiter-engine 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ElementState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public enum ElementState { 20 | VISIBLE, 21 | HIDDEN, 22 | STABLE, 23 | ENABLED, 24 | DISABLED, 25 | EDITABLE 26 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/Waitable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import java.util.function.Function; 20 | 21 | interface Waitable { 22 | boolean isDone(); 23 | T get(); 24 | void dispose(); 25 | } 26 | -------------------------------------------------------------------------------- /tools/test-cli-version/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap "cd $(pwd -P)" EXIT 7 | cd "$(dirname $0)" 8 | 9 | TMP_DIR=$(mktemp -d) 10 | echo "Created ${TMP_DIR}" 11 | 12 | echo "Running CLI..." 13 | mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="--version" 2>&1 | tee ${TMP_DIR}/cli.txt 14 | 15 | echo "Running TestApp..." 16 | mvn compile exec:java -e -Dexec.mainClass=com.microsoft.playwright.testcliversion.TestApp 2>&1 | tee ${TMP_DIR}/app.txt 17 | 18 | DRIVER_VERSION=$(cat ${TMP_DIR}/cli.txt | tail -n 1 | cut -d\ -f2) 19 | PACKAGE_VERSION=$(cat ${TMP_DIR}/app.txt | grep ImplementationVersion | cut -d\ -f2) 20 | 21 | rm -rf $TMP_DIR 22 | 23 | echo "Comparing versions: ${DRIVER_VERSION} and ${PACKAGE_VERSION}" 24 | 25 | if [[ "$DRIVER_VERSION" == "$PACKAGE_VERSION" ]]; 26 | then 27 | echo "SUCCESS."; 28 | else 29 | echo "FAIL."; 30 | exit 1; 31 | fi; 32 | 33 | -------------------------------------------------------------------------------- /scripts/playwright.java: -------------------------------------------------------------------------------- 1 | ///usr/bin/env jbang "$0" "$@" ; exit $? 2 | //DEPS com.microsoft.playwright:playwright:RELEASE 3 | //DESCRIPTION Playwright lets you automate Chromium, Firefox and Webkit with a single API. 4 | //DESCRIPTION With this cli you can install, trace, generate pdf and screenshots and more. 5 | //DESCRIPTION 6 | //DESCRIPTION Example on how to record and run a script: 7 | //DESCRIPTION ``` 8 | //DESCRIPTION jbang playwright@microsoft/playwright-java codegen -o Example.java` 9 | //DESCRIPTION jbang --deps com.microsoft.playwright:playwright:RELEASE Example.java 10 | //DESCRIPTION ``` 11 | 12 | // NOTE: this file is referenced from https://github.com/microsoft/jbang-catalog/blob/702c9b4355c76ae6f7294e1aaf6f2698b03631aa/jbang-catalog.json#L17 13 | public class playwright { 14 | 15 | public static void main(String... args) throws Exception { 16 | com.microsoft.playwright.CLI.main(args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ServerAddr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class ServerAddr { 20 | /** 21 | * IPv4 or IPV6 address of the server. 22 | */ 23 | public String ipAddress; 24 | public int port; 25 | 26 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class Position { 20 | public double x; 21 | public double y; 22 | 23 | public Position(double x, double y) { 24 | this.x = x; 25 | this.y = y; 26 | } 27 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: 'Questions / Help 💬' 2 | description: If you have questions, please check StackOverflow or Discord 3 | title: '[Please read the message below]' 4 | labels: [':speech_balloon: Question'] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | ## Questions and Help 💬 10 | 11 | This issue tracker is reserved for bug reports and feature requests. 12 | 13 | For anything else, such as questions or getting help, please see: 14 | 15 | - [The Playwright documentation](https://playwright.dev/java) 16 | - [Our Discord server](https://aka.ms/playwright/discord) 17 | - type: checkboxes 18 | id: no-post 19 | attributes: 20 | label: | 21 | Please do not submit this issue. 22 | description: | 23 | > [!IMPORTANT] 24 | > This issue will be closed. 25 | options: 26 | - label: I understand 27 | required: true 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 🚀 2 | description: Submit a proposal for a new feature 3 | title: '[Feature]: ' 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | ### Thank you for taking the time to suggest a new feature! 9 | - type: textarea 10 | id: description 11 | attributes: 12 | label: '🚀 Feature Request' 13 | description: A clear and concise description of what the feature is. 14 | validations: 15 | required: true 16 | - type: textarea 17 | id: example 18 | attributes: 19 | label: Example 20 | description: Describe how this feature would be used. 21 | validations: 22 | required: false 23 | - type: textarea 24 | id: motivation 25 | attributes: 26 | label: Motivation 27 | description: | 28 | Outline your motivation for the proposal. How will it make Playwright better? 29 | validations: 30 | required: true 31 | -------------------------------------------------------------------------------- /scripts/generate_api.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap 'cd $(pwd -P)' EXIT 7 | cd "$(dirname "$0")/.." 8 | 9 | PLAYWRIGHT_CLI="unknown" 10 | case $(uname) in 11 | Darwin) 12 | PLAYWRIGHT_CLI=./driver-bundle/src/main/resources/driver/mac/package/cli.js 13 | ;; 14 | Linux) 15 | PLAYWRIGHT_CLI=./driver-bundle/src/main/resources/driver/linux/package/cli.js 16 | ;; 17 | MINGW64*) 18 | PLAYWRIGHT_CLI=./driver-bundle/src/main/resources/driver/win32_x64/package/cli.js 19 | ;; 20 | *) 21 | echo "Unknown platform '$(uname)'" 22 | exit 1; 23 | ;; 24 | esac 25 | 26 | echo "Updating api.json from $($PLAYWRIGHT_CLI --version)" 27 | 28 | node $PLAYWRIGHT_CLI print-api-json > ./tools/api-generator/src/main/resources/api.json 29 | 30 | mvn compile -f ./tools/api-generator --no-transfer-progress 31 | 32 | echo "Regenerating Java interfaces" 33 | mvn exec:java --f ./tools/api-generator -D exec.mainClass=com.microsoft.playwright.tools.ApiGenerator 34 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/HttpHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class HttpHeader { 20 | /** 21 | * Name of the header. 22 | */ 23 | public String name; 24 | /** 25 | * Value of the header. 26 | */ 27 | public String value; 28 | 29 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/button-overlay-oopif.html: -------------------------------------------------------------------------------- 1 | 23 | 40 | -------------------------------------------------------------------------------- /playwright/src/test/resources/rotate-z-shadow-dom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 31 | 32 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/BrowserChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | @Deprecated 20 | public enum BrowserChannel { 21 | CHROME, 22 | CHROME_BETA, 23 | CHROME_DEV, 24 | CHROME_CANARY, 25 | MSEDGE, 26 | MSEDGE_BETA, 27 | MSEDGE_DEV, 28 | MSEDGE_CANARY, 29 | @Deprecated FIREFOX_STABLE 30 | } 31 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/button.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Button test 5 | 6 | 7 | 8 | 9 | 31 | 32 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/DriverException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.microsoft.playwright.PlaywrightException; 20 | 21 | import java.io.PrintStream; 22 | import java.io.PrintWriter; 23 | 24 | class DriverException extends PlaywrightException { 25 | DriverException(String error) { 26 | super(error); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/Transport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.google.gson.JsonObject; 20 | 21 | import java.io.IOException; 22 | import java.time.Duration; 23 | 24 | public interface Transport { 25 | void send(JsonObject message); 26 | JsonObject poll(Duration timeout); 27 | void close() throws IOException; 28 | } 29 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/junit/DefaultOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl.junit; 18 | 19 | import com.microsoft.playwright.junit.Options; 20 | import com.microsoft.playwright.junit.OptionsFactory; 21 | 22 | public class DefaultOptions implements OptionsFactory { 23 | @Override 24 | public Options getOptions() { 25 | return new Options(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ScreenSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class ScreenSize { 20 | /** 21 | * page width in pixels. 22 | */ 23 | public int width; 24 | /** 25 | * page height in pixels. 26 | */ 27 | public int height; 28 | 29 | public ScreenSize(int width, int height) { 30 | this.width = width; 31 | this.height = height; 32 | } 33 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/drag-n-drop.html: -------------------------------------------------------------------------------- 1 | 14 | 15 | 33 | 34 | 35 |
36 |

37 | Select this element, drag it to the Drop Zone and then release the selection to move the element.

38 |
39 |
Drop Zone
40 | 41 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/ViewportSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class ViewportSize { 20 | /** 21 | * page width in pixels. 22 | */ 23 | public int width; 24 | /** 25 | * page height in pixels. 26 | */ 27 | public int height; 28 | 29 | public ViewportSize(int width, int height) { 30 | this.width = width; 31 | this.height = height; 32 | } 33 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/RecordVideoSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class RecordVideoSize { 20 | /** 21 | * Video frame width. 22 | */ 23 | public int width; 24 | /** 25 | * Video frame height. 26 | */ 27 | public int height; 28 | 29 | public RecordVideoSize(int width, int height) { 30 | this.width = width; 31 | this.height = height; 32 | } 33 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WaitableNever.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | public class WaitableNever implements Waitable { 20 | @Override 21 | public boolean isDone() { 22 | return false; 23 | } 24 | 25 | @Override 26 | public T get() { 27 | throw new IllegalStateException("Should never be called"); 28 | } 29 | 30 | @Override 31 | public void dispose() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/checkbox.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Selection Test 5 | 6 | 7 | 8 | 9 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the 2 | // README at: https://github.com/devcontainers/templates/tree/main/src/java 3 | { 4 | "name": "Java", 5 | // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile 6 | "image": "mcr.microsoft.com/devcontainers/java:1-21-bookworm", 7 | 8 | "features": { 9 | "ghcr.io/devcontainers/features/java:1": { 10 | "version": "none", 11 | "installGradle": "false", 12 | "installMaven": "true" 13 | }, 14 | "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} 15 | } 16 | 17 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 18 | // "forwardPorts": [], 19 | 20 | // Use 'postCreateCommand' to run commands after the container is created. 21 | // "postCreateCommand": "java -version", 22 | 23 | // Configure tool-specific properties. 24 | // "customizations": {}, 25 | 26 | // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. 27 | // "remoteUser": "root" 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/test_cli.yml: -------------------------------------------------------------------------------- 1 | name: Test CLI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - release-* 7 | pull_request: 8 | branches: 9 | - main 10 | - release-* 11 | jobs: 12 | verify: 13 | timeout-minutes: 30 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v6 17 | - name: Cache Maven packages 18 | uses: actions/cache@v4 19 | with: 20 | path: ~/.m2 21 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 22 | restore-keys: ${{ runner.os }}-m2 23 | - name: Download drivers 24 | run: scripts/download_driver.sh 25 | - name: Intall Playwright 26 | run: mvn install -D skipTests --no-transfer-progress 27 | - name: Test CLI 28 | run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -f playwright/pom.xml -D exec.args=-V 29 | - name: Test CLI version 30 | shell: bash 31 | run: tools/test-cli-version/test.sh 32 | - name: Test CLI Fatjar 33 | shell: bash 34 | run: tools/test-cli-fatjar/test.sh 35 | -------------------------------------------------------------------------------- /tools/test-cli-fatjar/src/main/java/com/microsoft/playwright/testclifatjar/TestApp.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.testclifatjar; 2 | 3 | import com.microsoft.playwright.Browser; 4 | import com.microsoft.playwright.Page; 5 | import com.microsoft.playwright.Playwright; 6 | import com.microsoft.playwright.impl.driver.Driver; 7 | import com.microsoft.playwright.impl.driver.jar.DriverJar; 8 | 9 | import java.io.IOException; 10 | import java.net.URI; 11 | import java.net.URISyntaxException; 12 | import java.nio.file.FileSystem; 13 | import java.nio.file.FileSystems; 14 | import java.util.Collections; 15 | 16 | public class TestApp { 17 | public static void main(String[] args) throws IOException, URISyntaxException { 18 | URI uri = DriverJar.getDriverResourceURI(); 19 | FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap()); 20 | if (fs == null) { 21 | throw new RuntimeException(); 22 | } 23 | try (Playwright playwright = Playwright.create()) { 24 | Browser browser = playwright.chromium().launch(); 25 | Page page = browser.newPage(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /scripts/roll_driver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap "cd $(pwd -P)" EXIT 7 | cd "$(dirname $0)" 8 | 9 | if [ "$#" -ne 1 ]; then 10 | echo "" 11 | echo "Usage: scripts/roll_driver.sh [new version]" 12 | echo "" 13 | exit 1 14 | fi 15 | 16 | NEW_VERSION=$1 17 | CURRENT_VERSION=$(head -1 ./DRIVER_VERSION) 18 | 19 | if [[ "$CURRENT_VERSION" == "$NEW_VERSION" ]]; then 20 | echo "Current version is up to date. Skipping driver download."; 21 | else 22 | echo $NEW_VERSION > ./DRIVER_VERSION 23 | ./download_driver.sh 24 | fi; 25 | 26 | ./generate_api.sh 27 | ./update_readme.sh 28 | 29 | node -e "$(cat < parseInt(part, 10)); 31 | minorVersion[1]--; 32 | const previousMajorVersion = majorVersion + '.' + minorVersion + '.0'; 33 | fs.writeFileSync('../examples/pom.xml', fs.readFileSync('../examples/pom.xml', 'utf8') 34 | .replace(/.*<\/playwright\.version>/, '' + previousMajorVersion + '') 35 | ); 36 | EOF 37 | )" $NEW_VERSION 38 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/AssertionsTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.microsoft.playwright.PlaywrightException; 20 | 21 | public class AssertionsTimeout { 22 | static double defaultTimeout = 5_000; 23 | 24 | public static void setDefaultTimeout(double ms) { 25 | if (ms < 0) { 26 | throw new PlaywrightException("Timeout cannot be negative"); 27 | } 28 | defaultTimeout = ms; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/src/main/java/org/example/PrintTitle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.example; 18 | 19 | import com.microsoft.playwright.*; 20 | 21 | public class PrintTitle { 22 | public static void main(String[] args) { 23 | try (Playwright playwright = Playwright.create()) { 24 | Browser browser = playwright.chromium().launch(); 25 | Page page = browser.newPage(); 26 | page.navigate("http://playwright.dev"); 27 | System.out.println(page.title()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/BindingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | import com.microsoft.playwright.BrowserContext; 20 | import com.microsoft.playwright.Frame; 21 | import com.microsoft.playwright.Page; 22 | 23 | public interface BindingCallback { 24 | interface Source { 25 | BrowserContext context(); 26 | Page page(); 27 | Frame frame(); 28 | } 29 | 30 | Object call(Source source, Object... args); 31 | } 32 | -------------------------------------------------------------------------------- /.github/workflows/publish_docker.yml: -------------------------------------------------------------------------------- 1 | name: Publish Release Docker 2 | on: 3 | release: 4 | types: [published] 5 | workflow_dispatch: 6 | jobs: 7 | publish-canary-docker: 8 | name: publish to DockerHub 9 | runs-on: ubuntu-22.04 10 | permissions: 11 | id-token: write # This is required for OIDC login (azure/login) to succeed 12 | contents: read # This is required for actions/checkout to succeed 13 | environment: Docker 14 | if: github.repository == 'microsoft/playwright-java' 15 | steps: 16 | - uses: actions/checkout@v6 17 | - name: Azure login 18 | uses: azure/login@v2 19 | with: 20 | client-id: ${{ secrets.AZURE_DOCKER_CLIENT_ID }} 21 | tenant-id: ${{ secrets.AZURE_DOCKER_TENANT_ID }} 22 | subscription-id: ${{ secrets.AZURE_DOCKER_SUBSCRIPTION_ID }} 23 | - name: Login to ACR via OIDC 24 | run: az acr login --name playwright 25 | - name: Set up Docker QEMU for arm64 docker builds 26 | uses: docker/setup-qemu-action@v3 27 | with: 28 | platforms: arm64 29 | - uses: actions/checkout@v6 30 | - run: ./utils/docker/publish_docker.sh stable 31 | -------------------------------------------------------------------------------- /utils/docker/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set +x 4 | 5 | if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then 6 | echo "usage: $(basename $0) {--arm64,--amd64} {jammy,noble} playwright:localbuild-noble" 7 | echo 8 | echo "Build Playwright docker image and tag it as 'playwright:localbuild-noble'." 9 | echo "Once image is built, you can run it with" 10 | echo "" 11 | echo " docker run --rm -it playwright:localbuild-noble /bin/bash" 12 | echo "" 13 | echo "NOTE: this requires on Playwright PIP dependencies to be installed" 14 | echo "" 15 | exit 0 16 | fi 17 | 18 | function cleanup() { 19 | : 20 | } 21 | 22 | trap "cleanup; cd $(pwd -P)" EXIT 23 | cd "$(dirname "$0")" 24 | 25 | PLATFORM="" 26 | if [[ "$1" == "--arm64" ]]; then 27 | PLATFORM="linux/arm64"; 28 | elif [[ "$1" == "--amd64" ]]; then 29 | PLATFORM="linux/amd64" 30 | else 31 | echo "ERROR: unknown platform specifier - $1. Only --arm64 or --amd64 is supported" 32 | exit 1 33 | fi 34 | 35 | PW_TARGET_ARCH=$(echo $1 | cut -c3-) 36 | 37 | docker build --platform "${PLATFORM}" --build-arg "PW_TARGET_ARCH=${PW_TARGET_ARCH}" -t "$3" -f "Dockerfile.$2" ../../ 38 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Location.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class Location { 20 | public String file; 21 | public Integer line; 22 | public Integer column; 23 | 24 | public Location(String file) { 25 | this.file = file; 26 | } 27 | public Location setLine(int line) { 28 | this.line = line; 29 | return this; 30 | } 31 | public Location setColumn(int column) { 32 | this.column = column; 33 | return this; 34 | } 35 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/react.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 33 | 34 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/RemoteBrowser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.google.gson.JsonObject; 20 | 21 | public class RemoteBrowser extends ChannelOwner { 22 | RemoteBrowser(ChannelOwner parent, String type, String guid, JsonObject initializer) { 23 | super(parent, type, guid, initializer); 24 | } 25 | 26 | BrowserImpl browser() { 27 | return connection.getExistingObject(initializer.getAsJsonObject("browser").get("guid").getAsString()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/BoundingBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class BoundingBox { 20 | /** 21 | * the x coordinate of the element in pixels. 22 | */ 23 | public double x; 24 | /** 25 | * the y coordinate of the element in pixels. 26 | */ 27 | public double y; 28 | /** 29 | * the width of the element in pixels. 30 | */ 31 | public double width; 32 | /** 33 | * the height of the element in pixels. 34 | */ 35 | public double height; 36 | 37 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/FilePayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class FilePayload { 20 | /** 21 | * File name 22 | */ 23 | public String name; 24 | /** 25 | * File type 26 | */ 27 | public String mimeType; 28 | /** 29 | * File content 30 | */ 31 | public byte[] buffer; 32 | 33 | public FilePayload(String name, String mimeType, byte[] buffer) { 34 | this.name = name; 35 | this.mimeType = mimeType; 36 | this.buffer = buffer; 37 | } 38 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/input/animating-button.html: -------------------------------------------------------------------------------- 1 | 8 | 43 | -------------------------------------------------------------------------------- /examples/src/main/java/org/example/WebKitScreenshot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.example; 18 | 19 | import com.microsoft.playwright.*; 20 | import java.nio.file.Paths; 21 | 22 | public class WebKitScreenshot { 23 | public static void main(String[] args) { 24 | try (Playwright playwright = Playwright.create()) { 25 | Browser browser = playwright.webkit().launch(); 26 | Page page = browser.newPage(); 27 | page.navigate("https://playwright.dev/"); 28 | page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("example.png"))); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WebErrorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.microsoft.playwright.WebError; 20 | 21 | public class WebErrorImpl implements WebError { 22 | private final PageImpl page; 23 | private final String error; 24 | 25 | WebErrorImpl(PageImpl page, String error) { 26 | this.page = page; 27 | this.error = error; 28 | } 29 | 30 | @Override 31 | public PageImpl page() { 32 | return page; 33 | } 34 | 35 | @Override 36 | public String error() { 37 | return error; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/TimeoutError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | /** 20 | * TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. {@link Page#waitForSelector 21 | * Page.waitForSelector()} or {@link BrowserType#launch BrowserType.launch()}. 22 | */ 23 | public class TimeoutError extends PlaywrightException { 24 | public TimeoutError(String message) { 25 | super(message); 26 | } 27 | 28 | public TimeoutError(String message, Throwable exception) { 29 | super(message, exception); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/TargetClosedError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.microsoft.playwright.PlaywrightException; 20 | 21 | public class TargetClosedError extends PlaywrightException { 22 | public TargetClosedError() { 23 | super(null); 24 | } 25 | 26 | public TargetClosedError(String message) { 27 | this(message, null); 28 | } 29 | 30 | public TargetClosedError(String message, Throwable cause) { 31 | super(message != null ? message : "Target page, context or browser has been closed", cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Documentation 📖 2 | description: Submit a request to add or update documentation 3 | title: '[Docs]: ' 4 | labels: ['Documentation :book:'] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | ### Thank you for helping us improve our documentation! 10 | 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. 11 | - type: textarea 12 | id: links 13 | attributes: 14 | label: Page(s) 15 | description: | 16 | Links to one or more documentation pages that should be modified. 17 | If you are reporting an issue with a specific section of a page, try to link directly to the nearest anchor. 18 | If you are suggesting that a new page be created, link to the parent of the proposed page. 19 | validations: 20 | required: true 21 | - type: textarea 22 | id: description 23 | attributes: 24 | label: Description 25 | description: | 26 | Describe the change you are requesting. 27 | If the issue pertains to a single function or matcher, be sure to specify the entire call signature. 28 | validations: 29 | required: true 30 | -------------------------------------------------------------------------------- /driver-bundle/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.microsoft.playwright 8 | parent-pom 9 | 1.50.0-SNAPSHOT 10 | 11 | 12 | driver-bundle 13 | Playwright - Drivers For All Platforms 14 | 15 | This module includes Playwright driver and related utilities for all supported platforms. 16 | It is intended to be used on the systems where Playwright driver is not preinstalled. 17 | 18 | 19 | 20 | 21 | com.microsoft.playwright 22 | driver 23 | ${project.version} 24 | compile 25 | 26 | 27 | org.junit.jupiter 28 | junit-jupiter-engine 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/junit/FixtureTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.junit; 18 | 19 | import org.junit.jupiter.api.Tag; 20 | import org.junit.jupiter.api.extension.ExtendWith; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | @ExtendWith({ServerLifecycle.class, BrowserTypeParameterResolver.class}) 28 | @Tag("fixtures") 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.TYPE) 31 | public @interface FixtureTest { 32 | } 33 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/PlaywrightException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | /** 20 | * PlaywrightException is thrown whenever certain operations are terminated abnormally, e.g. browser closes while {@link 21 | * Page#evaluate Page.evaluate()} is running. All Playwright exceptions inherit from this class. 22 | */ 23 | public class PlaywrightException extends RuntimeException { 24 | public PlaywrightException(String message) { 25 | super(message); 26 | } 27 | 28 | public PlaywrightException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/junit/BrowserTypeParameterResolver.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.junit; 2 | 3 | import com.microsoft.playwright.BrowserType; 4 | import com.microsoft.playwright.Playwright; 5 | import com.microsoft.playwright.impl.junit.PlaywrightExtension; 6 | import org.junit.jupiter.api.extension.ExtensionContext; 7 | import org.junit.jupiter.api.extension.ParameterContext; 8 | import org.junit.jupiter.api.extension.ParameterResolutionException; 9 | import org.junit.jupiter.api.extension.ParameterResolver; 10 | 11 | import static com.microsoft.playwright.Utils.getBrowserTypeFromEnv; 12 | 13 | public class BrowserTypeParameterResolver implements ParameterResolver { 14 | @Override 15 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { 16 | return BrowserType.class.equals(parameterContext.getParameter().getType()); 17 | } 18 | 19 | @Override 20 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { 21 | Playwright playwright = PlaywrightExtension.getOrCreatePlaywright(extensionContext); 22 | return getBrowserTypeFromEnv(playwright); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/touches.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Touch test 5 | 6 | 7 | 8 | 9 | 34 | 35 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WaitablePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import java.util.function.BooleanSupplier; 20 | 21 | class WaitablePredicate implements Waitable { 22 | private final BooleanSupplier predicate; 23 | 24 | WaitablePredicate(BooleanSupplier predicate) { 25 | this.predicate = predicate; 26 | } 27 | 28 | @Override 29 | public boolean isDone() { 30 | return predicate.getAsBoolean(); 31 | } 32 | 33 | @Override 34 | public T get() { 35 | return null; 36 | } 37 | 38 | @Override 39 | public void dispose() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.github/workflows/verify_api.yml: -------------------------------------------------------------------------------- 1 | name: Verify API 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - release-* 7 | paths: 8 | - 'scripts/*' 9 | - 'api-generator/*' 10 | pull_request: 11 | branches: 12 | - main 13 | - release-* 14 | paths: 15 | - 'scripts/**' 16 | - 'api-generator/**' 17 | jobs: 18 | verify: 19 | timeout-minutes: 30 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v6 23 | - name: Download drivers 24 | run: scripts/download_driver.sh 25 | - name: Regenerate APIs 26 | run: scripts/generate_api.sh 27 | - name: Build & Install 28 | run: mvn -B install -D skipTests --no-transfer-progress 29 | - name: Install browsers 30 | run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps" -f playwright/pom.xml --no-transfer-progress 31 | - name: Update browser versions in README 32 | run: scripts/update_readme.sh 33 | - name: Verify API is up to date 34 | run: | 35 | if [[ -n $(git status -s) ]]; then 36 | echo "ERROR: generated interfaces/docs differ from the current sources:" 37 | git diff 38 | exit 1 39 | fi 40 | -------------------------------------------------------------------------------- /examples/src/main/java/org/example/InterceptNetworkRequests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.example; 18 | 19 | import com.microsoft.playwright.*; 20 | 21 | public class InterceptNetworkRequests { 22 | public static void main(String[] args) { 23 | try (Playwright playwright = Playwright.create()) { 24 | Browser browser = playwright.webkit().launch(); 25 | BrowserContext context = browser.newContext(); 26 | Page page = context.newPage(); 27 | page.route("**", route -> { 28 | System.out.println(route.request().url()); 29 | route.resume(); 30 | }); 31 | page.navigate("http://todomvc.com"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Clip.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class Clip { 20 | /** 21 | * x-coordinate of top-left corner of clip area 22 | */ 23 | public double x; 24 | /** 25 | * y-coordinate of top-left corner of clip area 26 | */ 27 | public double y; 28 | /** 29 | * width of clipping area 30 | */ 31 | public double width; 32 | /** 33 | * height of clipping area 34 | */ 35 | public double height; 36 | 37 | public Clip(double x, double y, double width, double height) { 38 | this.x = x; 39 | this.y = y; 40 | this.width = width; 41 | this.height = height; 42 | } 43 | } -------------------------------------------------------------------------------- /tools/test-cli-version/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.microsoft.playwright 6 | test-cli-version 7 | 1.50.0-SNAPSHOT 8 | Test Playwright Command Line Version 9 | 10 | 1.8 11 | UTF-8 12 | 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-compiler-plugin 18 | 3.12.1 19 | 20 | ${compiler.version} 21 | ${compiler.version} 22 | 23 | 24 | 25 | 26 | 27 | 28 | com.microsoft.playwright 29 | playwright 30 | ${project.version} 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /playwright/src/test/resources/resetcss.html: -------------------------------------------------------------------------------- 1 | 51 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestRequestGC.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright; 2 | 3 | import com.microsoft.playwright.junit.FixtureTest; 4 | import com.microsoft.playwright.junit.UsePlaywright; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static com.microsoft.playwright.Utils.mapOf; 8 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | import static org.junit.jupiter.api.Assertions.assertNull; 11 | 12 | @FixtureTest 13 | @UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class) 14 | public class TestRequestGC { 15 | 16 | @Test 17 | void shouldWork(Page page) { 18 | page.evaluate("() => {\n" + 19 | " globalThis.objectToDestroy = { hello: 'world' };\n" + 20 | " globalThis.weakRef = new WeakRef(globalThis.objectToDestroy);\n" + 21 | " }"); 22 | 23 | page.requestGC(); 24 | assertEquals(mapOf("hello", "world"), page.evaluate("() => globalThis.weakRef.deref()")); 25 | 26 | page.requestGC(); 27 | assertEquals(mapOf("hello", "world"), page.evaluate("() => globalThis.weakRef.deref()")); 28 | 29 | page.evaluate("() => globalThis.objectToDestroy = null"); 30 | page.requestGC(); 31 | assertNull(page.evaluate("() => globalThis.weakRef.deref()")); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestPageLocatorConvenience.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | public class TestPageLocatorConvenience extends TestBase { 24 | @Test 25 | void shouldReturnPage() { 26 | page.navigate(server.PREFIX + "/frames/two-frames.html"); 27 | Locator outer = page.locator("#outer"); 28 | assertEquals(page, outer.page()); 29 | Locator inner = outer.locator("#inner"); 30 | assertEquals(page, inner.page()); 31 | Locator inFrame = page.frames().get(1).locator("div"); 32 | assertEquals(page, inFrame.page()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/TouchscreenImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.google.gson.JsonObject; 20 | import com.microsoft.playwright.Touchscreen; 21 | 22 | import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT; 23 | 24 | class TouchscreenImpl implements Touchscreen { 25 | private final PageImpl page; 26 | 27 | TouchscreenImpl(PageImpl page) { 28 | this.page = page; 29 | } 30 | 31 | @Override 32 | public void tap(double x, double y) { 33 | JsonObject params = new JsonObject(); 34 | params.addProperty("x", x); 35 | params.addProperty("y", y); 36 | page.sendMessage("touchscreenTap", params, NO_TIMEOUT); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestBeforeunload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import com.microsoft.playwright.junit.FixtureTest; 20 | import com.microsoft.playwright.junit.UsePlaywright; 21 | import org.junit.jupiter.api.Test; 22 | 23 | @FixtureTest 24 | @UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class) 25 | public class TestBeforeunload { 26 | @Test 27 | void shouldBeAbleToNavigateAwayFromPageWithBeforeunload(Page page, Server server) { 28 | page.navigate(server.PREFIX + "/beforeunload.html"); 29 | // We have to interact with a page so that "beforeunload" handlers 30 | // fire. 31 | page.click("body"); 32 | page.navigate(server.EMPTY_PAGE); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestLocatorList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import static java.util.Arrays.asList; 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | 27 | public class TestLocatorList extends TestBase { 28 | @Test 29 | void locatorAllShouldWork() { 30 | page.setContent("

A

B

C

"); 31 | List texts = new ArrayList<>(); 32 | for (Locator p : page.locator("div >> p").all()) { 33 | texts.add(p.textContent()); 34 | } 35 | assertEquals(asList("A", "B", "C"), texts); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/WebSocketFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | 20 | /** 21 | * The {@code WebSocketFrame} class represents frames sent over {@code WebSocket} connections in the page. Frame payload is 22 | * returned by either {@link com.microsoft.playwright.WebSocketFrame#text WebSocketFrame.text()} or {@link 23 | * com.microsoft.playwright.WebSocketFrame#binary WebSocketFrame.binary()} method depending on the its type. 24 | */ 25 | public interface WebSocketFrame { 26 | /** 27 | * Returns binary payload. 28 | * 29 | * @since v1.9 30 | */ 31 | byte[] binary(); 32 | /** 33 | * Returns text payload. 34 | * 35 | * @since v1.9 36 | */ 37 | String text(); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestPageEventPopup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | public class TestPageEventPopup extends TestBase { 24 | @Test 25 | void shouldWorkWithClickingTarget_blank() { 26 | page.navigate(server.EMPTY_PAGE); 27 | page.setContent("yo"); 28 | Page popup = page.waitForPopup(() -> page.click("a")); 29 | assertEquals(false, page.evaluate("() => !!window.opener")); 30 | assertEquals(true, popup.evaluate("() => !!window.opener")); 31 | assertEquals(popup, popup.mainFrame().page()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /playwright/src/test/resources/input/keyboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Keyboard test 5 | 6 | 7 | 8 | 41 | 42 | -------------------------------------------------------------------------------- /tools/test-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.3 9 | 10 | com.microsoft.playwright 11 | test-spring-boot-starter 12 | 1.50.0-SNAPSHOT 13 | Test Playwright With Spring Boot 14 | 15 | 2.4.3 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter 21 | 22 | 23 | com.microsoft.playwright 24 | playwright 25 | ${project.version} 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-maven-plugin 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestAutoClose.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | /** 24 | * This test simply makes sure that all 4 main interfaces implement AutoCloseable. If it compiles, then it passes. 25 | */ 26 | public class TestAutoClose { 27 | @Test 28 | void shouldAllowUsingTryWithResources() { 29 | try (Playwright playwright = Playwright.create(); 30 | Browser browser = Utils.getBrowserTypeFromEnv(playwright).launch(); 31 | BrowserContext context = browser.newContext(); 32 | Page page = context.newPage()) { 33 | assertEquals(2021, page.evaluate("() => 2021")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Sizes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class Sizes { 20 | /** 21 | * Size of the request body (POST data payload) in bytes. Set to 0 if there was no body. 22 | */ 23 | public int requestBodySize; 24 | /** 25 | * Total number of bytes from the start of the HTTP request message until (and including) the double CRLF before the body. 26 | */ 27 | public int requestHeadersSize; 28 | /** 29 | * Size of the received response body (encoded) in bytes. 30 | */ 31 | public int responseBodySize; 32 | /** 33 | * Total number of bytes from the start of the HTTP response message until (and including) the double CRLF before the body. 34 | */ 35 | public int responseHeadersSize; 36 | 37 | } -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/Geolocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class Geolocation { 20 | /** 21 | * Latitude between -90 and 90. 22 | */ 23 | public double latitude; 24 | /** 25 | * Longitude between -180 and 180. 26 | */ 27 | public double longitude; 28 | /** 29 | * Non-negative accuracy value. Defaults to {@code 0}. 30 | */ 31 | public Double accuracy; 32 | 33 | public Geolocation(double latitude, double longitude) { 34 | this.latitude = latitude; 35 | this.longitude = longitude; 36 | } 37 | /** 38 | * Non-negative accuracy value. Defaults to {@code 0}. 39 | */ 40 | public Geolocation setAccuracy(double accuracy) { 41 | this.accuracy = accuracy; 42 | return this; 43 | } 44 | } -------------------------------------------------------------------------------- /playwright/src/test/resources/snapshot/snapshot-with-css.html: -------------------------------------------------------------------------------- 1 | 2 | 9 |
hello, world!
10 | 11 |
12 | 48 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestPageRequestIntercept.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; 22 | 23 | public class TestPageRequestIntercept extends TestBase { 24 | @Test 25 | void shouldFulfillPopupMainRequestUsingAlias() { 26 | page.context().route("**/*", route -> { 27 | APIResponse response = route.fetch(); 28 | route.fulfill(new Route.FulfillOptions().setResponse(response).setBody("hello" )); 29 | }); 30 | page.setContent("click me"); 31 | Page popup = page.waitForPopup(() -> page.getByText("click me").click()); 32 | assertThat(popup.locator("body")).hasText("hello"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WebSocketRouter.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.playwright.impl; 2 | 3 | import com.google.gson.JsonObject; 4 | import com.microsoft.playwright.WebSocketRoute; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.function.Consumer; 9 | import java.util.stream.Collectors; 10 | 11 | public class WebSocketRouter { 12 | private List routes = new ArrayList<>(); 13 | 14 | private static class RouteInfo { 15 | final UrlMatcher matcher; 16 | private final Consumer handler; 17 | 18 | RouteInfo(UrlMatcher matcher, Consumer handler) { 19 | this.matcher = matcher; 20 | this.handler = handler; 21 | } 22 | 23 | void handle(WebSocketRouteImpl route) { 24 | handler.accept(route); 25 | route.afterHandle(); 26 | } 27 | } 28 | 29 | void add(UrlMatcher matcher, Consumer handler) { 30 | routes.add(0, new RouteInfo(matcher, handler)); 31 | } 32 | 33 | boolean handle(WebSocketRouteImpl route) { 34 | for (RouteInfo routeInfo: routes) { 35 | if (routeInfo.matcher.test(route.url())) { 36 | routeInfo.handle(route); 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | JsonObject interceptionPatterns() { 44 | List matchers = routes.stream().map(r -> r.matcher).collect(Collectors.toList()); 45 | return Utils.interceptionPatterns(matchers); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /playwright/src/test/resources/deep-shadow.html: -------------------------------------------------------------------------------- 1 | 37 | -------------------------------------------------------------------------------- /playwright/src/test/resources/player.html: -------------------------------------------------------------------------------- 1 | 55 | 56 | 60 | 61 | -------------------------------------------------------------------------------- /tools/test-cli-fatjar/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.microsoft.playwright 6 | test-cli-fatjar 7 | 1.50.0-SNAPSHOT 8 | Test Playwright Command Line FatJar 9 | 10 | 1.8 11 | UTF-8 12 | 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-compiler-plugin 18 | 3.12.1 19 | 20 | ${compiler.version} 21 | ${compiler.version} 22 | 23 | 24 | 25 | 26 | 27 | 28 | com.microsoft.playwright 29 | playwright 30 | ${project.version} 31 | 32 | 33 | com.microsoft.playwright 34 | driver-bundle 35 | ${project.version} 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /examples/src/main/java/org/example/EvaluateInBrowserContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.example; 18 | 19 | import com.microsoft.playwright.*; 20 | 21 | public class EvaluateInBrowserContext { 22 | public static void main(String[] args) { 23 | try (Playwright playwright = Playwright.create()) { 24 | Browser browser = playwright.firefox().launch(); 25 | BrowserContext context = browser.newContext(); 26 | Page page = context.newPage(); 27 | page.navigate("https://www.example.com/"); 28 | Object dimensions = page.evaluate("() => {\n" + 29 | " return {\n" + 30 | " width: document.documentElement.clientWidth,\n" + 31 | " height: document.documentElement.clientHeight,\n" + 32 | " deviceScaleFactor: window.devicePixelRatio\n" + 33 | " }\n" + 34 | "}"); 35 | System.out.println(dimensions); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /playwright/src/test/resources/offscreenbuttons.html: -------------------------------------------------------------------------------- 1 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 56 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WaitableTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import com.microsoft.playwright.TimeoutError; 20 | 21 | class WaitableTimeout implements Waitable { 22 | private final long deadline; 23 | private final double timeout; 24 | 25 | WaitableTimeout(double millis) { 26 | timeout = millis; 27 | deadline = System.nanoTime() + (long) millis * 1_000_000; 28 | } 29 | 30 | @Override 31 | public boolean isDone() { 32 | return System.nanoTime() > deadline; 33 | } 34 | 35 | @Override 36 | public T get() { 37 | String timeoutStr = Double.toString(timeout); 38 | if (timeoutStr.endsWith(".0")) { 39 | timeoutStr = timeoutStr.substring(0, timeoutStr.length() - 2); 40 | } 41 | throw new TimeoutError("Timeout " + timeoutStr + "ms exceeded"); 42 | } 43 | 44 | @Override 45 | public void dispose() { 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /driver/src/main/java/com/microsoft/playwright/impl/driver/DriverLogging.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl.driver; 18 | 19 | import java.time.ZoneId; 20 | import java.time.ZonedDateTime; 21 | import java.time.format.DateTimeFormatter; 22 | 23 | class DriverLogging { 24 | private static final boolean isEnabled; 25 | static { 26 | String debug = System.getenv("DEBUG"); 27 | isEnabled = (debug != null) && debug.contains("pw:install"); 28 | } 29 | 30 | private static final DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern( 31 | "yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneId.of("UTC")); 32 | 33 | static void logWithTimestamp(String message) { 34 | if (!isEnabled) { 35 | return; 36 | } 37 | // This matches log format produced by the server. 38 | String timestamp = ZonedDateTime.now().format(timestampFormat); 39 | System.err.println(timestamp + " " + message); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tools/api-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.microsoft.playwright 8 | api-generator 9 | 1.50.0-SNAPSHOT 10 | Playwright - API Generator 11 | 12 | This is an internal module used to generate Java API from the upstream Playwright 13 | definitions. It's an internal development module not intended for external use. 14 | 15 | 16 | 1.8 17 | 2.8.9 18 | UTF-8 19 | 20 | 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-compiler-plugin 26 | 3.12.1 27 | 28 | ${compiler.version} 29 | ${compiler.version} 30 | 31 | 32 | 33 | 34 | 35 | 36 | com.google.code.gson 37 | gson 38 | ${gson.version} 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | examples 9 | 1.50.0-SNAPSHOT 10 | Playwright Client Examples 11 | 12 | UTF-8 13 | 1.57.0 14 | 15 | 16 | 17 | com.microsoft.playwright 18 | playwright 19 | ${playwright.version} 20 | 21 | 22 | 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-compiler-plugin 27 | 3.12.1 28 | 29 | 1.8 30 | 1.8 31 | 32 | 33 | 34 | 35 | 36 | 37 | snapshots-repo 38 | https://oss.sonatype.org/content/repositories/snapshots 39 | false 40 | true 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/SecurityDetails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class SecurityDetails { 20 | /** 21 | * Common Name component of the Issuer field. from the certificate. This should only be used for informational purposes. 22 | * Optional. 23 | */ 24 | public String issuer; 25 | /** 26 | * The specific TLS protocol used. (e.g. {@code TLS 1.3}). Optional. 27 | */ 28 | public String protocol; 29 | /** 30 | * Common Name component of the Subject field from the certificate. This should only be used for informational purposes. 31 | * Optional. 32 | */ 33 | public String subjectName; 34 | /** 35 | * Unix timestamp (in seconds) specifying when this cert becomes valid. Optional. 36 | */ 37 | public Double validFrom; 38 | /** 39 | * Unix timestamp (in seconds) specifying when this cert becomes invalid. Optional. 40 | */ 41 | public Double validTo; 42 | 43 | } -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestUnrouteBehavior.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | public class TestUnrouteBehavior extends TestBase { 24 | @Test 25 | void contextUnrouteAllRemovesAllHandlers() { 26 | context.route("**/*", route -> { 27 | route.abort(); 28 | }); 29 | context.route("**/empty.html", route -> { 30 | route.abort(); 31 | }); 32 | context.unrouteAll(); 33 | page.navigate(server.EMPTY_PAGE); 34 | } 35 | 36 | @Test 37 | void pageUnrouteAllRemovesAllRoutes() { 38 | page.route("**/*", route -> { 39 | route.abort(); 40 | }); 41 | page.route("**/empty.html", route -> { 42 | route.abort(); 43 | }); 44 | page.unrouteAll(); 45 | Response response = page.navigate(server.EMPTY_PAGE); 46 | assertTrue(response.ok()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/WebError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | 20 | /** 21 | * {@code WebError} class represents an unhandled exception thrown in the page. It is dispatched via the {@link 22 | * com.microsoft.playwright.BrowserContext#onWebError BrowserContext.onWebError()} event. 23 | *
{@code
24 |  * // Log all uncaught errors to the terminal
25 |  * context.onWebError(webError -> {
26 |  *   System.out.println("Uncaught exception: " + webError.error());
27 |  * });
28 |  *
29 |  * // Navigate to a page with an exception.
30 |  * page.navigate("data:text/html,");
31 |  * }
32 | */ 33 | public interface WebError { 34 | /** 35 | * The page that produced this unhandled exception, if any. 36 | * 37 | * @since v1.38 38 | */ 39 | Page page(); 40 | /** 41 | * Unhandled error that was thrown. 42 | * 43 | * @since v1.38 44 | */ 45 | String error(); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/CLI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import com.microsoft.playwright.impl.driver.Driver; 20 | 21 | import java.io.IOException; 22 | import java.nio.file.Path; 23 | import java.util.Collections; 24 | 25 | import static java.util.Arrays.asList; 26 | 27 | /** 28 | * Use this class to launch playwright cli. 29 | */ 30 | public class CLI { 31 | public static void main(String[] args) throws IOException, InterruptedException { 32 | Driver driver = Driver.ensureDriverInstalled(Collections.emptyMap(), false); 33 | ProcessBuilder pb = driver.createProcessBuilder(); 34 | pb.command().addAll(asList(args)); 35 | String version = Playwright.class.getPackage().getImplementationVersion(); 36 | if (version != null) { 37 | pb.environment().put("PW_CLI_DISPLAY_VERSION", version); 38 | } 39 | pb.inheritIO(); 40 | Process process = pb.start(); 41 | System.exit(process.waitFor()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/options/SelectOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.options; 18 | 19 | public class SelectOption { 20 | /** 21 | * Matches by {@code option.value}. Optional. 22 | */ 23 | public String value; 24 | /** 25 | * Matches by {@code option.label}. Optional. 26 | */ 27 | public String label; 28 | /** 29 | * Matches by the index. Optional. 30 | */ 31 | public Integer index; 32 | 33 | /** 34 | * Matches by {@code option.value}. Optional. 35 | */ 36 | public SelectOption setValue(String value) { 37 | this.value = value; 38 | return this; 39 | } 40 | /** 41 | * Matches by {@code option.label}. Optional. 42 | */ 43 | public SelectOption setLabel(String label) { 44 | this.label = label; 45 | return this; 46 | } 47 | /** 48 | * Matches by the index. Optional. 49 | */ 50 | public SelectOption setIndex(int index) { 51 | this.index = index; 52 | return this; 53 | } 54 | } -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestPageAddScriptTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.condition.DisabledIf; 21 | 22 | import java.io.File; 23 | import java.nio.file.Path; 24 | import java.nio.file.Paths; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertTrue; 27 | 28 | public class TestPageAddScriptTag extends TestBase { 29 | @Test 30 | @DisabledIf(value="com.microsoft.playwright.TestBase#isWebKit", disabledReason="Upstream behavior") 31 | void shouldIncludeSourceURLWhenPathIsProvided() { 32 | page.navigate(server.EMPTY_PAGE); 33 | Path path = Paths.get("src/test/resources/injectedfile.js"); 34 | page.addScriptTag(new Page.AddScriptTagOptions().setPath(path)); 35 | String result = (String) page.evaluate("() => window['__injectedError'].stack"); 36 | assertTrue(result.contains("resources" + File.separator + "injectedfile.js"), result); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/src/main/java/org/example/PageScreenshot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.example; 18 | 19 | import com.microsoft.playwright.*; 20 | 21 | import java.nio.file.Paths; 22 | import java.util.Arrays; 23 | import java.util.List; 24 | 25 | public class PageScreenshot { 26 | public static void main(String[] args) { 27 | try (Playwright playwright = Playwright.create()) { 28 | List browserTypes = Arrays.asList( 29 | playwright.chromium(), 30 | playwright.webkit(), 31 | playwright.firefox() 32 | ); 33 | for (BrowserType browserType : browserTypes) { 34 | try (Browser browser = browserType.launch()) { 35 | BrowserContext context = browser.newContext(); 36 | Page page = context.newPage(); 37 | page.navigate("https://playwright.dev/"); 38 | page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png"))); 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/WaitableRace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import java.util.Collection; 20 | 21 | class WaitableRace implements Waitable { 22 | private final Collection> waitables; 23 | private Waitable firstReady; 24 | 25 | WaitableRace(Collection> waitables) { 26 | this.waitables = waitables; 27 | } 28 | 29 | @Override 30 | public boolean isDone() { 31 | if (firstReady != null) { 32 | return true; 33 | } 34 | for (Waitable w : waitables) { 35 | if (w.isDone()) { 36 | firstReady = w; 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | @Override 44 | public T get() { 45 | try { 46 | return firstReady.get(); 47 | } finally { 48 | dispose(); 49 | } 50 | } 51 | 52 | @Override 53 | public void dispose() { 54 | for (Waitable w : waitables) { 55 | w.dispose(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestVideo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.io.TempDir; 21 | 22 | import java.nio.file.Files; 23 | import java.nio.file.Path; 24 | 25 | import static com.microsoft.playwright.Utils.relativePathOrSkipTest; 26 | import static org.junit.jupiter.api.Assertions.assertTrue; 27 | 28 | public class TestVideo extends TestBase { 29 | @Test 30 | void shouldWorkWithRelativePathForRecordVideoDir(@TempDir Path tmpDir) { 31 | Path relativeDir = relativePathOrSkipTest(tmpDir); 32 | BrowserContext context = browser.newContext(new Browser.NewContextOptions() 33 | .setRecordVideoSize(320, 240).setRecordVideoDir(relativeDir)); 34 | Page page = context.newPage(); 35 | Path videoPath = page.video().path(); 36 | context.close(); 37 | assertTrue(videoPath.isAbsolute(), "videosPath = " + videoPath); 38 | assertTrue(Files.exists(videoPath), "videosPath = " + videoPath); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/src/main/java/org/example/SelectorsAndKeyboardManipulation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.example; 18 | 19 | import java.nio.file.Paths; 20 | import com.microsoft.playwright.*; 21 | 22 | public class SelectorsAndKeyboardManipulation { 23 | public static void main(String[] args) { 24 | try(Playwright playwright = Playwright.create()) { 25 | Browser browser = playwright.firefox().launch(); 26 | BrowserContext context = browser.newContext(); 27 | Page page = context.newPage(); 28 | page.navigate("https://playwright.dev/java/"); 29 | page.locator("text=SearchK").click(); 30 | page.locator("[placeholder=\"Search docs\"]").fill("getting started"); 31 | page.locator("div[role=\"button\"]:has-text(\"CancelIntroductionGetting startedInstallation​Getting startedUsage​Getting start\")").click(); 32 | page.waitForSelector("h1:has-text(\"Getting started\")"); // Waits for the new page to load before screenshotting. 33 | page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("Screenshot.png"))); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /playwright/src/test/resources/grid.html: -------------------------------------------------------------------------------- 1 | 28 | 29 | 63 | -------------------------------------------------------------------------------- /playwright/src/test/resources/client-certificates/client/trusted/csr.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIEVTCCAj0CAQAwEDEOMAwGA1UEAwwFQWxpY2UwggIiMA0GCSqGSIb3DQEBAQUA 3 | A4ICDwAwggIKAoICAQC4ggn74iAHLgOWOiOvB2CPe+Hr7W6STYJLZOoqPdh7mv7Q 4 | Gm8cYxfD+26p13aEaW4/qn45losWdEPPy2ZiVIF+kcOP0R4AqsB0w9UHT4WSzCWt 5 | Dqs8ywDMJ6tHge0++8S1bTpdutn/m8DPnKtkD9RQUzLFmGDO+mB08Xu+egTzJvUR 6 | bHXRJ27E+CXUXLEHbAJd8EKjJiQYXhcj4lzUXOUg+xkpPAGe1dgQ6BDkv3xq/81S 7 | 9NTIT5YriHEm6egi9AFJLZbbZtCpRQm1MDMq7zfD7oL6ECLGrJ/aaxLEM49gMdw2 8 | SscYHotVxX2OMAKgN/ytB18L/mIQ4pOWp3HJQ+nks9Zu1V8cg7Pz5pWwjqoncbyU 9 | aBi3vGsitAot3cyLXbN9hH8zQB8QqGyNLvqQnCJOBlYxOPA8M8NQGDThWKspcix0 10 | LhkmnYsWWt3+KEGEpFRcJCEthm/DAd1GImP7/dg1/btT/zOsIIkIoCyBwznuR4M4 11 | XoNTbIBsiTnO/6PjOdTrjLVX7vMueTjdbCgK3VeOuwetbZ7aZ/hvMJCjJ4wuM3l2 12 | ZyfEQlP4gJLJS3Fw2PRsySZJl9JyEzwTqYVosDF5SF8uw0HIcFaliZCqBbgYfOiQ 13 | zjIX/GiHZdor1ZrhAbO/MpSxuxGzxF7Em4n+4p816NnC9S2JbHRetkM9P1adHwID 14 | AQABoAAwDQYJKoZIhvcNAQELBQADggIBACpScaAoLAs9DuTcI5Y4dbHf7LwF4Zxx 15 | UgPNzE1HB1Pr6NaHRiOWrlCtDEB5UwHrr0oZuRTqSEGg3Pe5Z2QtPG/sdFgfm4BP 16 | 29o6qo0CXiEVBwU7/K0/lL2/0a7uSbD0Tkw9d6Bgik7/Z5rzXZIi2vtUcrOtHskP 17 | C+Z9w3vH9a+RnUeo52mCnRi4SaiSEnD5jvhmgaI9iF+k5pYBiMrKRj5W/F1QCkf4 18 | 7OuSK97xN0eG/I4Oxgzi/qt51ySCYZbqoh7dIpwi/a4UsK8kdzDDI1M3J7bU07cO 19 | CJRfr0EETqCQw/gAKoag3tRFNvWQB6Z9G3Ev5jeaCLpcc32NlpN5xH3VW8A0Zb81 20 | dn5BXkPSxjwJaD0a3cLFkfgrasoe7ZMmHrVpQDw+9USuGCYXMPzNZLEeTFbrRkUn 21 | sqi30e28E1H69zVWj+OKzCWEH/azVlfaoVbwM+njUJDe5V09KvFtI7aZYmvLxbUX 22 | 4ifoRUVoKedyKnueVmoIG57lF2VzeEhX5YjCngxIg+YuE99HkMQAZSlS6uJcVM92 23 | tsC/+pYECBk8ukenbxmKXROl3u4p2M1iCSL/8EOVROuyjnuzCXJZOpNptdpX4ZgL 24 | kHP1erq7/U8ZU8HviUsfMoisagx8dA8uj/4fk0jfNxOJqlZL9eJhpgBfYHqmAz3h 25 | m+PQVw96eeoK 26 | -----END CERTIFICATE REQUEST----- 27 | -------------------------------------------------------------------------------- /playwright/src/test/resources/client-certificates/client/self-signed/csr.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIEUzCCAjsCAQAwDjEMMAoGA1UEAwwDQm9iMIICIjANBgkqhkiG9w0BAQEFAAOC 3 | Ag8AMIICCgKCAgEAzQMXYOZz3ILrbF9qpDng2pw2wJf1UFopehwaYyu7riWJ9+AD 4 | rhSnCSFBM3ScMBc/8dIR6etWwci8QwJ/MtvIU0yx4llq+53G+19Bc1teC6q/b4QC 5 | RDIcTGxOZoR+jfYZVjPODEyJ5y5MZIo34ZP4bu+JnpT4W7+uojm3jOoyNPqXMcc7 6 | 0uAhfSKG+JfrwZKteA4T5VKFytVcWgh4v03z8zTYeW3kD4lCsongBz6yu2dn3D6X 7 | MROnxiPwi+IRQqX1pwnJ0UA3CTeOHEw1jA3koxWIIg44PWaPaCj9Udrhf4ew00XL 8 | PWVZP8T5rVf8yUfecWQCR7FueJFqoLhPMMFi17rYmGZUvw3/YkXBjay4Q9e+G2WS 9 | 3Xk8u+I1sCuVBJNBRv9DqtMC9D/N9NI8GkLrXwZmk82SXG+cQ0TSkNUHYI/03YKo 10 | qsn5H8PsG7Tc+Y2Ca6TaCWims7lvOg7U0E6lu2h5NGcdWHFPJ9qfe+xho/yfYYwG 11 | qEKanGAu1kd5SbIaX6/YiM5/Pp/96MeRNrB9kLzDnZTNuGtdCawVFgbkWmfX2Z6/ 12 | a0d6SvZGDzBxxTVZRB0my01E1FP53MS8YRH98HUjGEwNRVq2e1W+aXldKppgZ85G 13 | ZD3l2YTeuI0iPJCDUzQiaWzFtWc8s13YQ1HLCOyOXF7QqMyNCiLGb4xQ56kCAwEA 14 | AaAAMA0GCSqGSIb3DQEBCwUAA4ICAQAn/ZI7IkBUEfhZHefwtF+QHCyxSEKvqwHq 15 | fSqKVdarBPz8Ik8m3icj8R/DcS3y5jgzx3x8bXQoDpgsAQgeb825NRv2wAQAGoH1 16 | 8vh204lTyjqzrgtK7eQeQDc7fjeigIkxQsAK9zk4BaFUWp0wEC0RLVAgvlQTl7vu 17 | n1jSSrhK8tvGy62/cIxZfwD0bAMHlW4m1A4fUuSGWQX2KldgA8tnmT6wx0If/nKb 18 | VB68AMbyMHUeb32v9wEvx2nHlwMjqNFeg7vYyJXOfBdDILUl+OTBoQY1X+jSx5iM 19 | txTzmA8Hcgx0Fq+BnbQuZCLqFpNWEfenAtQtaAFuJwMiKCf6kgbqkDVShJkmt+vC 20 | j3dcsVMZDsdMk4qRpiJhaTQOYmsMGCj4uoDpFGjwPoUwlDkjYgHAAsm9uCkshc+m 21 | WZO7I6Z3Tbi3XskJvAMc3dTWjtc6nApEtr/mn8LcETfOp7RRSfjllj6ijWUrVwUy 22 | BpzU9C/zLTkhFX0DVDCIV+jEefF8JPfzSKLgXyRbInTz1/6/sKXtswXW0NjzqLMI 23 | C9ggMBhOiDv9KJn3G/mY4CqIfo9KMzF+++4t+wdXTir8DWNlMUAn1vlBwxZAgKCM 24 | GonVExBU0VIGCpyTRLkesEHnPMgybP6gLzP3++54x288OS5JwuPPtkDcsBHUjTq8 25 | HxTJvUul/Q== 26 | -----END CERTIFICATE REQUEST----- 27 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestLocatorHighlight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import com.google.gson.Gson; 20 | import com.microsoft.playwright.options.BoundingBox; 21 | import org.junit.jupiter.api.Disabled; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | 27 | public class TestLocatorHighlight extends TestBase { 28 | @Disabled("Requires isUnderTest to be true https://github.com/microsoft/playwright/pull/12420") 29 | @Test 30 | void shouldHighlightLocator() { 31 | page.setContent(""); 32 | page.locator("input").highlight(); 33 | assertThat(page.locator("x-pw-tooltip")).hasText("input"); 34 | assertThat(page.locator("x-pw-highlight")).isVisible(); 35 | BoundingBox box1 = page.locator("input").boundingBox(); 36 | BoundingBox box2 = page.locator("x-pw-highlight").boundingBox(); 37 | assertEquals(new Gson().toJson(box2), new Gson().toJson(box1)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /scripts/download_driver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set +x 5 | 6 | trap "cd $(pwd -P)" EXIT 7 | cd "$(dirname $0)" 8 | 9 | if [[ ($1 == '-h') || ($1 == '--help') ]]; then 10 | echo "" 11 | echo "This script for downloading playwright driver for all platforms." 12 | echo "The downloaded files will be put under 'driver-bundle/src/main/resources/driver'." 13 | echo "" 14 | echo "Usage: scripts/download_driver.sh [option]" 15 | echo "" 16 | echo "Options:" 17 | echo " -h, --help display help information" 18 | echo "" 19 | exit 0 20 | fi 21 | 22 | DRIVER_VERSION=$(head -1 ./DRIVER_VERSION) 23 | FILE_PREFIX=playwright-$DRIVER_VERSION 24 | 25 | cd ../driver-bundle/src/main/resources 26 | 27 | if [[ -d 'driver' ]]; then 28 | echo "Deleting existing drivers from $(pwd)" 29 | rm -rf driver 30 | fi 31 | 32 | mkdir -p driver 33 | cd driver 34 | 35 | for PLATFORM in mac mac-arm64 linux linux-arm64 win32_x64 36 | do 37 | FILE_NAME=$FILE_PREFIX-$PLATFORM.zip 38 | mkdir $PLATFORM 39 | cd $PLATFORM 40 | echo "Downloading driver for $PLATFORM to $(pwd)" 41 | 42 | URL=https://cdn.playwright.dev/builds/driver 43 | if [[ "$DRIVER_VERSION" == *-alpha* || "$DRIVER_VERSION" == *-beta* || "$DRIVER_VERSION" == *-next* ]]; then 44 | URL=$URL/next 45 | fi 46 | URL=$URL/$FILE_NAME 47 | echo "Using url: $URL" 48 | # Ubuntu 24.04-arm64 emulated via qemu has a bug, so we prefer wget over curl. 49 | # See https://github.com/microsoft/playwright-java/issues/1678. 50 | if command -v wget &> /dev/null; then 51 | wget $URL 52 | else 53 | curl -O $URL 54 | fi 55 | unzip $FILE_NAME -d . 56 | rm $FILE_NAME 57 | 58 | cd - 59 | done 60 | 61 | echo "" 62 | echo "All drivers have been successfully downloaded." 63 | echo "" 64 | -------------------------------------------------------------------------------- /playwright/src/main/java/com/microsoft/playwright/impl/LoggingSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright.impl; 18 | 19 | import java.time.ZoneId; 20 | import java.time.ZonedDateTime; 21 | import java.time.format.DateTimeFormatter; 22 | 23 | class LoggingSupport { 24 | private static final boolean isEnabled; 25 | static { 26 | String debug = System.getenv("DEBUG"); 27 | isEnabled = (debug != null) && debug.contains("pw:api"); 28 | } 29 | 30 | private static final DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern( 31 | "yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneId.of("UTC")); 32 | 33 | static void logWithTimestamp(String message) { 34 | // This matches log format produced by the server. 35 | String timestamp = ZonedDateTime.now().format(timestampFormat); 36 | System.err.println(timestamp + " " + message); 37 | } 38 | 39 | static void logApiIfEnabled(String message) { 40 | if (isEnabled) { 41 | logApi(message); 42 | } 43 | } 44 | 45 | static void logApi(String message) { 46 | // This matches log format produced by the server. 47 | logWithTimestamp("pw:api " + message); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /.github/workflows/test_docker.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | on: 3 | push: 4 | paths: 5 | - '.github/workflows/test_docker.yml' 6 | - '**/Dockerfile*' 7 | branches: 8 | - main 9 | - release-* 10 | pull_request: 11 | paths: 12 | - .github/workflows/test_docker.yml 13 | - '**/Dockerfile*' 14 | - scripts/DRIVER_VERSION 15 | - '**/pom.xml' 16 | branches: 17 | - main 18 | - release-* 19 | jobs: 20 | test: 21 | name: Test 22 | timeout-minutes: 120 23 | runs-on: ${{ matrix.runs-on }} 24 | env: 25 | PW_MAX_RETRIES: 3 26 | strategy: 27 | fail-fast: false 28 | matrix: 29 | flavor: [jammy, noble] 30 | runs-on: [ubuntu-24.04, ubuntu-24.04-arm] 31 | steps: 32 | - uses: actions/checkout@v6 33 | - name: Build Docker image 34 | run: | 35 | ARCH="${{ matrix.runs-on == 'ubuntu-24.04-arm' && 'arm64' || 'amd64' }}" 36 | bash utils/docker/build.sh --$ARCH ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }} 37 | - name: Start container 38 | run: | 39 | CONTAINER_ID=$(docker run --rm -e CI -e PW_MAX_RETRIES --ipc=host -v "$(pwd)":/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash) 40 | echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV 41 | 42 | - name: Run test in container 43 | run: | 44 | docker exec "$CONTAINER_ID" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh 45 | 46 | - name: Test ClassLoader 47 | run: | 48 | docker exec "${CONTAINER_ID}" /root/playwright/tools/test-spring-boot-starter/package_and_run_async_test.sh 49 | 50 | - name: Stop container 51 | run: | 52 | docker stop "$CONTAINER_ID" 53 | -------------------------------------------------------------------------------- /playwright/src/test/java/com/microsoft/playwright/TestBrowserContextServiceWorkerPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft Corporation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.microsoft.playwright; 18 | 19 | import com.microsoft.playwright.options.ServiceWorkerPolicy; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; 23 | 24 | public class TestBrowserContextServiceWorkerPolicy extends TestBase { 25 | @Test 26 | void shouldAllowServiceWorkersByDefault() { 27 | page.navigate(server.PREFIX + "/serviceworkers/empty/sw.html"); 28 | assertNotNull(page.evaluate("() => window['registrationPromise']")); 29 | } 30 | 31 | @Test 32 | void blocksServiceWorkerRegistration() { 33 | try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setServiceWorkers(ServiceWorkerPolicy.BLOCK))) { 34 | Page page = context.newPage(); 35 | ConsoleMessage message = page.waitForConsoleMessage(new Page.WaitForConsoleMessageOptions() 36 | .setPredicate(m -> "Service Worker registration blocked by Playwright".equals(m.text())), 37 | () -> page.navigate(server.PREFIX + "/serviceworkers/empty/sw.html")); 38 | assertNotNull(message); 39 | } 40 | } 41 | 42 | } 43 | --------------------------------------------------------------------------------