chore(dotnet): do not use global CLI and use ps1 instead (#12025)

Fixes https://github.com/microsoft/playwright-dotnet/issues/2005
This commit is contained in:
Max Schmitt 2022-02-11 20:26:16 +01:00 committed by GitHub
parent 619d1d8617
commit 7e7996a7b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 54 deletions

View file

@ -138,30 +138,30 @@ you can still opt into stable channels on the bots that are typically free of su
### Prerequisites for .NET ### Prerequisites for .NET
* langs: csharp * langs: csharp
All examples require the `Microsoft.Playwright.CLI` to be installed. You only have to do this once: To invoke Playwright CLI commands, you need to invoke a PowerShell script:
```bash ```bash
dotnet tool install -g Microsoft.Playwright.CLI pwsh bin\Debug\netX\playwright.ps1 --help
``` ```
Playwright can install supported browsers by means of the CLI tool. Playwright can install supported browsers by means of the CLI tool.
```bash csharp ```bash csharp
# Running without arguments will install all browsers # Running without arguments will install all browsers
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
You can also install specific browsers by providing an argument: You can also install specific browsers by providing an argument:
```bash csharp ```bash csharp
# Install WebKit # Install WebKit
playwright install webkit pwsh bin\Debug\netX\playwright.ps1 install webkit
``` ```
See all supported browsers: See all supported browsers:
```bash csharp ```bash csharp
playwright install --help pwsh bin\Debug\netX\playwright.ps1 install --help
``` ```
## Managing browser binaries ## Managing browser binaries
@ -230,17 +230,17 @@ mvn test
```bash bash-flavor=bash lang=csharp ```bash bash-flavor=bash lang=csharp
PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=batch lang=csharp ```bash bash-flavor=batch lang=csharp
set PLAYWRIGHT_BROWSERS_PATH=%USERPROFILE%\pw-browsers set PLAYWRIGHT_BROWSERS_PATH=%USERPROFILE%\pw-browsers
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=powershell lang=csharp ```bash bash-flavor=powershell lang=csharp
$env:PLAYWRIGHT_BROWSERS_PATH="$env:USERPROFILE\pw-browsers" $env:PLAYWRIGHT_BROWSERS_PATH="$env:USERPROFILE\pw-browsers"
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
When running Playwright scripts, ask it to search for browsers in a shared location. When running Playwright scripts, ask it to search for browsers in a shared location.
@ -398,17 +398,17 @@ mvn test
``` ```
```bash bash-flavor=bash lang=csharp ```bash bash-flavor=bash lang=csharp
HTTPS_PROXY=https://192.0.2.1 playwright install HTTPS_PROXY=https://192.0.2.1 pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=batch lang=csharp ```bash bash-flavor=batch lang=csharp
set HTTPS_PROXY=https://192.0.2.1 set HTTPS_PROXY=https://192.0.2.1
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=powershell lang=csharp ```bash bash-flavor=powershell lang=csharp
$env:HTTPS_PROXY="https://192.0.2.1" $env:HTTPS_PROXY="https://192.0.2.1"
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
## Download from artifact repository ## Download from artifact repository
@ -479,17 +479,17 @@ mvn test
``` ```
```bash bash-flavor=bash lang=csharp ```bash bash-flavor=bash lang=csharp
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 playwright install PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=batch lang=csharp ```bash bash-flavor=batch lang=csharp
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=powershell lang=csharp ```bash bash-flavor=powershell lang=csharp
$env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1" $env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
It is also possible to use a per-browser download hosts using `PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST`, `PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST` and `PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST` env variables that It is also possible to use a per-browser download hosts using `PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST`, `PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST` and `PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST` env variables that
@ -563,19 +563,19 @@ mvn test
``` ```
```bash bash-flavor=bash lang=csharp ```bash bash-flavor=bash lang=csharp
PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 playwright install PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=batch lang=csharp ```bash bash-flavor=batch lang=csharp
set PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 set PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=powershell lang=csharp ```bash bash-flavor=powershell lang=csharp
$env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1" $env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
$env:PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST="203.0.113.3" $env:PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST="203.0.113.3"
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
## Skip browser downloads ## Skip browser downloads
@ -617,17 +617,17 @@ mvn test
``` ```
```bash bash-flavor=bash lang=csharp ```bash bash-flavor=bash lang=csharp
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 playwright install PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=batch lang=csharp ```bash bash-flavor=batch lang=csharp
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
```bash bash-flavor=powershell lang=csharp ```bash bash-flavor=powershell lang=csharp
$env:PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 $env:PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
## Download single browser binary ## Download single browser binary

View file

@ -22,10 +22,8 @@ playwright
``` ```
```bash csharp ```bash csharp
# Install the CLI once.
dotnet tool install --global Microsoft.Playwright.CLI
# Use the tools. # Use the tools.
playwright pwsh bin\Debug\netX\playwright.ps1 --help
``` ```
```json js ```json js
@ -58,7 +56,7 @@ playwright install
```bash csharp ```bash csharp
# Running without arguments will install default browsers # Running without arguments will install default browsers
playwright install pwsh bin\Debug\netX\playwright.ps1 install
``` ```
You can also install specific browsers by providing an argument: You can also install specific browsers by providing an argument:
@ -80,7 +78,7 @@ playwright install webkit
```bash csharp ```bash csharp
# Install WebKit # Install WebKit
playwright install webkit pwsh bin\Debug\netX\playwright.ps1 install webkit
``` ```
See all supported browsers: See all supported browsers:
@ -174,7 +172,7 @@ playwright codegen --load-storage=auth.json my.web.app
```bash csharp ```bash csharp
pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json my.web.app pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json my.web.app
playwright codegen --load-storage=auth.json my.web.app pwsh bin\Debug\netX\playwright.ps1 codegen --load-storage=auth.json my.web.app
# Perform actions in authenticated state. # Perform actions in authenticated state.
``` ```
@ -300,7 +298,7 @@ playwright open example.com
```bash csharp ```bash csharp
# Open page in Chromium # Open page in Chromium
playwright open example.com pwsh bin\Debug\netX\playwright.ps1 open example.com
``` ```
```bash js ```bash js
@ -320,7 +318,7 @@ playwright wk example.com
```bash csharp ```bash csharp
# Open page in WebKit # Open page in WebKit
playwright wk example.com pwsh bin\Debug\netX\playwright.ps1 wk example.com
``` ```
### Emulate devices ### Emulate devices
@ -343,7 +341,7 @@ playwright open --device="iPhone 11" wikipedia.org
```bash csharp ```bash csharp
# Emulate iPhone 11. # Emulate iPhone 11.
playwright open --device="iPhone 11" wikipedia.org pwsh bin\Debug\netX\playwright.ps1 open --device="iPhone 11" wikipedia.org
``` ```
### Emulate color scheme and viewport size ### Emulate color scheme and viewport size
@ -365,7 +363,7 @@ playwright open --viewport-size=800,600 --color-scheme=dark twitter.com
```bash csharp ```bash csharp
# Emulate screen size and color scheme. # Emulate screen size and color scheme.
playwright open --viewport-size=800,600 --color-scheme=dark twitter.com pwsh bin\Debug\netX\playwright.ps1 open --viewport-size=800,600 --color-scheme=dark twitter.com
``` ```
### Emulate geolocation, language and timezone ### Emulate geolocation, language and timezone
@ -391,7 +389,7 @@ playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --l
```bash csharp ```bash csharp
# Emulate timezone, language & location # Emulate timezone, language & location
# Once page opens, click the "my location" button to see geolocation in action # Once page opens, click the "my location" button to see geolocation in action
playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com pwsh bin\Debug\netX\playwright.ps1 open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
``` ```
## Inspect selectors ## Inspect selectors
@ -491,7 +489,7 @@ playwright screenshot \
```bash csharp ```bash csharp
# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires) # Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)
playwright screenshot \ pwsh bin\Debug\netX\playwright.ps1 screenshot \
--device="iPhone 11" \ --device="iPhone 11" \
--color-scheme=dark \ --color-scheme=dark \
--wait-for-timeout=3000 \ --wait-for-timeout=3000 \
@ -515,7 +513,7 @@ playwright screenshot --full-page en.wikipedia.org wiki-full.png
```bash csharp ```bash csharp
# Capture a full page screenshot # Capture a full page screenshot
playwright screenshot --full-page en.wikipedia.org wiki-full.png pwsh bin\Debug\netX\playwright.ps1 screenshot --full-page en.wikipedia.org wiki-full.png
``` ```
## Generate PDF ## Generate PDF
@ -539,7 +537,7 @@ playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
```bash csharp ```bash csharp
# See command help # See command help
playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf pwsh bin\Debug\netX\playwright.ps1 pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
``` ```
## Install system dependencies ## Install system dependencies
@ -563,7 +561,7 @@ playwright install-deps
```bash csharp ```bash csharp
# See command help # See command help
playwright install-deps pwsh bin\Debug\netX\playwright.ps1 install-deps
``` ```
You can also install the dependencies for a single browser only by passing it as an argument: You can also install the dependencies for a single browser only by passing it as an argument:

View file

@ -22,7 +22,7 @@ playwright codegen wikipedia.org
``` ```
```bash csharp ```bash csharp
playwright codegen wikipedia.org pwsh bin\Debug\netX\playwright.ps1 codegen wikipedia.org
``` ```
Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `codegen` will attempt to generate resilient text-based selectors. Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `codegen` will attempt to generate resilient text-based selectors.
@ -52,7 +52,7 @@ playwright codegen --save-storage=auth.json
``` ```
```bash csharp ```bash csharp
playwright codegen --save-storage=auth.json pwsh bin\Debug\netX\playwright.ps1 codegen --save-storage=auth.json
# Perform authentication and exit. # Perform authentication and exit.
# auth.json will contain the storage state. # auth.json will contain the storage state.
``` ```
@ -79,8 +79,8 @@ playwright codegen --load-storage=auth.json my.web.app
``` ```
```bash csharp ```bash csharp
playwright open --load-storage=auth.json my.web.app pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json my.web.app
playwright codegen --load-storage=auth.json my.web.app pwsh bin\Debug\netX\playwright.ps1 codegen --load-storage=auth.json my.web.app
# Perform actions in authenticated state. # Perform actions in authenticated state.
``` ```
@ -206,7 +206,7 @@ playwright codegen --device="iPhone 11" wikipedia.org
```bash csharp ```bash csharp
# Emulate iPhone 11. # Emulate iPhone 11.
playwright codegen --device="iPhone 11" wikipedia.org pwsh bin\Debug\netX\playwright.ps1 codegen --device="iPhone 11" wikipedia.org
``` ```
## Emulate color scheme and viewport size ## Emulate color scheme and viewport size
@ -230,7 +230,7 @@ playwright codegen --viewport-size=800,600 --color-scheme=dark twitter.com
```bash csharp ```bash csharp
# Emulate screen size and color scheme. # Emulate screen size and color scheme.
playwright codegen --viewport-size=800,600 --color-scheme=dark twitter.com pwsh bin\Debug\netX\playwright.ps1 codegen --viewport-size=800,600 --color-scheme=dark twitter.com
``` ```
## Emulate geolocation, language and timezone ## Emulate geolocation, language and timezone
@ -256,5 +256,5 @@ playwright codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348"
```bash csharp ```bash csharp
# Emulate timezone, language & location # Emulate timezone, language & location
# Once page opens, click the "my location" button to see geolocation in action # Once page opens, click the "my location" button to see geolocation in action
playwright codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com pwsh bin\Debug\netX\playwright.ps1 codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
``` ```

View file

@ -60,6 +60,20 @@ configures Playwright for debugging and opens the inspector.
pytest -s pytest -s
``` ```
```bash bash-flavor=bash lang=csharp
PWDEBUG=1 dotnet test
```
```bash bash-flavor=batch lang=csharp
set PWDEBUG=1
dotnet test
```
```bash bash-flavor=powershell lang=csharp
$env:PWDEBUG=1
dotnet test
```
Additional useful defaults are configured when `PWDEBUG=1` is set: Additional useful defaults are configured when `PWDEBUG=1` is set:
- Browsers launch in the headed mode - Browsers launch in the headed mode
- Default timeout is set to 0 (= no timeout) - Default timeout is set to 0 (= no timeout)
@ -105,6 +119,10 @@ configures Playwright for debugging and opens the inspector.
playwright codegen wikipedia.org playwright codegen wikipedia.org
``` ```
```bash csharp
pwsh bin\Debug\netX\playwright.ps1 codegen wikipedia.org
```
## Stepping through the Playwright script ## Stepping through the Playwright script
When `PWDEBUG=1` is set, Playwright Inspector window will be opened and the script will be When `PWDEBUG=1` is set, Playwright Inspector window will be opened and the script will be

View file

@ -106,7 +106,7 @@ Playwright Trace Viewer is now **available online** at https://trace.playwright.
- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi. - Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.
- You can now use Playwright to install stable version of Edge on Linux: - You can now use Playwright to install stable version of Edge on Linux:
```bash ```bash
npx playwright install msedge pwsh bin\Debug\netX\playwright.ps1 install msedge
``` ```
@ -133,7 +133,7 @@ Read more about [`method: Locator.waitFor`].
### 🎭 Playwright Trace Viewer ### 🎭 Playwright Trace Viewer
- run trace viewer with `npx playwright show-trace` and drop trace files to the trace viewer PWA - run trace viewer with `pwsh bin\Debug\netX\playwright.ps1 show-trace` and drop trace files to the trace viewer PWA
- better visual attribution of action targets - better visual attribution of action targets
Read more about [Trace Viewer](./trace-viewer). Read more about [Trace Viewer](./trace-viewer).

View file

@ -158,7 +158,7 @@ Playwright Trace Viewer is now **available online** at https://trace.playwright.
- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi. - Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.
- You can now use Playwright to install stable version of Edge on Linux: - You can now use Playwright to install stable version of Edge on Linux:
```bash ```bash
npx playwright install msedge mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install msedge"
``` ```
@ -185,7 +185,7 @@ Read more about [`method: Locator.waitFor`].
### 🎭 Playwright Trace Viewer ### 🎭 Playwright Trace Viewer
- run trace viewer with `npx playwright show-trace` and drop trace files to the trace viewer PWA - run trace viewer with `mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="show-trace"` and drop trace files to the trace viewer PWA
- better visual attribution of action targets - better visual attribution of action targets
Read more about [Trace Viewer](./trace-viewer). Read more about [Trace Viewer](./trace-viewer).
@ -474,10 +474,7 @@ This version of Playwright was also tested against the following stable channels
- [Selecting elements based on layout](./selectors.md#selecting-elements-based-on-layout) with `:left-of()`, `:right-of()`, `:above()` and `:below()`. - [Selecting elements based on layout](./selectors.md#selecting-elements-based-on-layout) with `:left-of()`, `:right-of()`, `:above()` and `:below()`.
- Playwright now includes [command line interface](./cli.md), former playwright-cli. - Playwright now includes [command line interface](./cli.md), former playwright-cli.
```bash js ```bash js
npx playwright --help mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="--help"
```
```bash python
playwright --help
``` ```
- [`method: Page.selectOption`] now waits for the options to be present. - [`method: Page.selectOption`] now waits for the options to be present.
- New methods to [assert element state](./actionability#assertions) like [`method: Page.isEditable`]. - New methods to [assert element state](./actionability#assertions) like [`method: Page.isEditable`].

View file

@ -151,7 +151,7 @@ playwright show-trace trace.zip
``` ```
```bash csharp ```bash csharp
playwright show-trace trace.zip pwsh bin\Debug\netX\playwright.ps1 show-trace trace.zip
``` ```
## Actions ## Actions
@ -218,5 +218,5 @@ playwright show-trace https://example.com/trace.zip
``` ```
```bash csharp ```bash csharp
playwright show-trace https://example.com/trace.zip pwsh bin\Debug\netX\playwright.ps1 show-trace https://example.com/trace.zip
``` ```

View file

@ -611,7 +611,7 @@ function buildBasePlaywrightCLICommand(cliTargetLang: string | undefined): strin
case 'java': case 'java':
return `mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="...options.."`; return `mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="...options.."`;
case 'csharp': case 'csharp':
return `playwright`; return `pwsh bin\\Debug\\netX\\playwright.ps1`;
default: default:
return `npx playwright`; return `npx playwright`;
} }

View file

@ -716,7 +716,7 @@ export function buildPlaywrightCLICommand(sdkLanguage: string, parameters: strin
case 'java': case 'java':
return `mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="${parameters}"`; return `mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="${parameters}"`;
case 'csharp': case 'csharp':
return `playwright ${parameters}`; return `pwsh bin\\Debug\\netX\\playwright.ps1 ${parameters}`;
default: default:
return `npx playwright ${parameters}`; return `npx playwright ${parameters}`;
} }