Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs: add java examples for CLI (#5727)
Yury Semikhatsky0306fcb11bcb
diff --git a/docs/src/cli.md b/docs/src/cli.mdindex 763b33fa89..81ca048f16 100644--- a/docs/src/cli.md+++ b/docs/src/cli.md@@ -13,6 +13,10 @@ Playwright comes with the command line tools that run via `npx` or as a part of$ npx playwright --help```+```sh java+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI+```+```sh python$ playwright```@@ -32,6 +36,10 @@ $ playwright$ npx playwright codegen wikipedia.org```+```sh java+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen wikipedia.org"+```+```sh python$ playwright codegen wikipedia.org```@@ -50,6 +58,12 @@ $ npx playwright codegen --save-storage=auth.json# auth.json will contain the storage state.```+```sh java+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen --save-storage=auth.json"+# Perform authentication and exit.+# auth.json will contain the storage state.+```+```sh python$ playwright codegen --save-storage=auth.json# Perform authentication and exit.@@ -64,6 +78,13 @@ $ npx playwright codegen --load-storage=auth.json my.web.app# Perform actions in authenticated state.```+```sh java+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="open --load-storage=auth.json my.web.app"+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen --load-storage=auth.json my.web.app"+# Perform authentication and exit.+# auth.json will contain the storage state.+```+```sh python$ playwright open --load-storage=auth.json my.web.app$ playwright codegen --load-storage=auth.json my.web.app@@ -157,6 +178,11 @@ With `open`, you can use Playwright bundled browsers to browse web pages. Playwr$ npx playwright open example.com```+```sh java+# Open page in Chromium+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="open example.com"+```+```sh python# Open page in Chromium$ playwright open example.com@@ -167,6 +193,11 @@ $ playwright open example.com$ npx playwright wk example.com```+```sh java+# Open page in WebKit+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="wk example.com"+```+```sh python# Open page in WebKit$ playwright wk example.com@@ -180,6 +211,11 @@ $ playwright wk example.com$ npx playwright open --device="iPhone 11" wikipedia.org```+```sh java+# Emulate iPhone 11.+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args='open --device="iPhone 11" wikipedia.org'+```+```sh python# Emulate iPhone 11.$ playwright open --device="iPhone 11" wikipedia.org@@ -190,6 +226,10 @@ $ playwright open --device="iPhone 11" wikipedia.org# Emulate screen size and color scheme.$ npx playwright open --viewport-size=800,600 --color-scheme=dark twitter.com```+```sh java+# Emulate screen size and color scheme.+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="open --viewport-size=800,600 --color-scheme=dark twitter.com"+``````sh python# Emulate screen size and color scheme.$ playwright open --viewport-size=800,600 --color-scheme=dark twitter.com@@ -201,6 +241,11 @@ $ playwright open --viewport-size=800,600 --color-scheme=dark twitter.com# Once page opens, click the "my location" button to see geolocation in action$ npx playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com```+```sh java+# Emulate timezone, language & location+# Once page opens, click the "my location" button to see geolocation in action+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args='open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com'+``````sh python# Emulate timezone, language & location# Once page opens, click the "my location" button to see geolocation in action@@ -257,6 +302,11 @@ Generates selector for the given element.$ npx playwright screenshot --help```+```sh java+# See command help+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="screenshot --help"+```+```sh python# See command help$ playwright screenshot --help@@ -271,6 +321,11 @@ $ npx playwright screenshot \twitter.com twitter-iphone.png```+```sh java+# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args='screenshot --device="iPhone 11" --color-scheme=dark --wait-for-timeout=3000 twitter.com twitter-iphone.png'+```+```sh python# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)$ playwright screenshot \@@ -285,6 +340,11 @@ $ playwright screenshot \$ npx playwright screenshot --full-page en.wikipedia.org wiki-full.png```+```sh java+# Capture a full page screenshot+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args='screenshot --full-page en.wikipedia.org wiki-full.png'+```+```sh python# Capture a full page screenshot$ playwright screenshot --full-page en.wikipedia.org wiki-full.png@@ -299,6 +359,11 @@ PDF generation only works in Headless Chromium.$ npx playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf```+```sh java+# See command help+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="pdf https://en.wikipedia.org/wiki/PDF wiki.pdf"+```+```sh python# See command help$ playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdfdiff --git a/docs/src/inspector.md b/docs/src/inspector.mdindex 01b67d5227..a8d3252923 100644--- a/docs/src/inspector.md+++ b/docs/src/inspector.md@@ -74,6 +74,10 @@ configures Playwright for debugging and opens the inspector.$ npx playwright codegen wikipedia.org```+ ```sh java+ $ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen wikipedia.org"+ ```+```sh python$ playwright codegen wikipedia.org```diff --git a/docs/src/intro-java.md b/docs/src/intro-java.mdindex cafac9016b..d3627788c1 100644--- a/docs/src/intro-java.md+++ b/docs/src/intro-java.md@@ -115,6 +115,14 @@ By default, Playwright runs the browsers in headless mode. To see the browser UIplaywright.firefox().launch(new BrowserType.LaunchOptions().withHeadless(false).withSlowMo(50));```+## Record scripts++Command Line Interface [CLI](./cli.md) can be used to record user interactions and generate Java code.++```sh+$ mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen wikipedia.org"+```+## System requirementsPlaywright requires **Java 8** or newer. The browser binaries for Chromium,