mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-03 08:54:05 +03:00
docs: add java examples for CLI (#5727)
This commit is contained in:
parent
e56f56c11e
commit
0306fcb11b
@ -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.pdf
|
||||
|
@ -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
|
||||
```
|
||||
|
@ -115,6 +115,14 @@ By default, Playwright runs the browsers in headless mode. To see the browser UI
|
||||
playwright.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 requirements
|
||||
|
||||
Playwright requires **Java 8** or newer. The browser binaries for Chromium,
|
||||
|
Loading…
Reference in New Issue
Block a user