Skip to content

Commit 241add2

Browse files
cherry-pick(#12025): chore(dotnet): do not use global CLI and use ps1 instead (#12047)
SHA: 7e7996a Fixes microsoft/playwright-dotnet#2005 Co-authored-by: Max Schmitt <[email protected]>
1 parent 92aa600 commit 241add2

File tree

9 files changed

+67
-54
lines changed

9 files changed

+67
-54
lines changed

docs/src/browsers.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,30 @@ you can still opt into stable channels on the bots that are typically free of su
138138
### Prerequisites for .NET
139139
* langs: csharp
140140

141-
All examples require the `Microsoft.Playwright.CLI` to be installed. You only have to do this once:
141+
To invoke Playwright CLI commands, you need to invoke a PowerShell script:
142142

143143
```bash
144-
dotnet tool install -g Microsoft.Playwright.CLI
144+
pwsh bin\Debug\netX\playwright.ps1 --help
145145
```
146146

147147
Playwright can install supported browsers by means of the CLI tool.
148148

149149
```bash csharp
150150
# Running without arguments will install all browsers
151-
playwright install
151+
pwsh bin\Debug\netX\playwright.ps1 install
152152
```
153153

154154
You can also install specific browsers by providing an argument:
155155

156156
```bash csharp
157157
# Install WebKit
158-
playwright install webkit
158+
pwsh bin\Debug\netX\playwright.ps1 install webkit
159159
```
160160

161161
See all supported browsers:
162162

163163
```bash csharp
164-
playwright install --help
164+
pwsh bin\Debug\netX\playwright.ps1 install --help
165165
```
166166

167167
## Managing browser binaries
@@ -230,17 +230,17 @@ mvn test
230230

231231
```bash bash-flavor=bash lang=csharp
232232
PLAYWRIGHT_BROWSERS_PATH=$HOME/pw-browsers
233-
playwright install
233+
pwsh bin\Debug\netX\playwright.ps1 install
234234
```
235235

236236
```bash bash-flavor=batch lang=csharp
237237
set PLAYWRIGHT_BROWSERS_PATH=%USERPROFILE%\pw-browsers
238-
playwright install
238+
pwsh bin\Debug\netX\playwright.ps1 install
239239
```
240240

241241
```bash bash-flavor=powershell lang=csharp
242242
$env:PLAYWRIGHT_BROWSERS_PATH="$env:USERPROFILE\pw-browsers"
243-
playwright install
243+
pwsh bin\Debug\netX\playwright.ps1 install
244244
```
245245

246246
When running Playwright scripts, ask it to search for browsers in a shared location.
@@ -398,17 +398,17 @@ mvn test
398398
```
399399

400400
```bash bash-flavor=bash lang=csharp
401-
HTTPS_PROXY=https://192.0.2.1 playwright install
401+
HTTPS_PROXY=https://192.0.2.1 pwsh bin\Debug\netX\playwright.ps1 install
402402
```
403403

404404
```bash bash-flavor=batch lang=csharp
405405
set HTTPS_PROXY=https://192.0.2.1
406-
playwright install
406+
pwsh bin\Debug\netX\playwright.ps1 install
407407
```
408408

409409
```bash bash-flavor=powershell lang=csharp
410410
$env:HTTPS_PROXY="https://192.0.2.1"
411-
playwright install
411+
pwsh bin\Debug\netX\playwright.ps1 install
412412
```
413413

414414
## Download from artifact repository
@@ -479,17 +479,17 @@ mvn test
479479
```
480480

481481
```bash bash-flavor=bash lang=csharp
482-
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 playwright install
482+
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 pwsh bin\Debug\netX\playwright.ps1 install
483483
```
484484

485485
```bash bash-flavor=batch lang=csharp
486486
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
487-
playwright install
487+
pwsh bin\Debug\netX\playwright.ps1 install
488488
```
489489

490490
```bash bash-flavor=powershell lang=csharp
491491
$env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
492-
playwright install
492+
pwsh bin\Debug\netX\playwright.ps1 install
493493
```
494494

495495
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
563563
```
564564

565565
```bash bash-flavor=bash lang=csharp
566-
PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 playwright install
566+
PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 pwsh bin\Debug\netX\playwright.ps1 install
567567
```
568568

569569
```bash bash-flavor=batch lang=csharp
570570
set PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3
571571
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
572-
playwright install
572+
pwsh bin\Debug\netX\playwright.ps1 install
573573
```
574574

575575
```bash bash-flavor=powershell lang=csharp
576576
$env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
577577
$env:PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST="203.0.113.3"
578-
playwright install
578+
pwsh bin\Debug\netX\playwright.ps1 install
579579
```
580580

581581
## Skip browser downloads
@@ -617,17 +617,17 @@ mvn test
617617
```
618618

619619
```bash bash-flavor=bash lang=csharp
620-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 playwright install
620+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 pwsh bin\Debug\netX\playwright.ps1 install
621621
```
622622

623623
```bash bash-flavor=batch lang=csharp
624624
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
625-
playwright install
625+
pwsh bin\Debug\netX\playwright.ps1 install
626626
```
627627

628628
```bash bash-flavor=powershell lang=csharp
629629
$env:PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
630-
playwright install
630+
pwsh bin\Debug\netX\playwright.ps1 install
631631
```
632632

633633
## Download single browser binary

docs/src/cli.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ playwright
2222
```
2323

2424
```bash csharp
25-
# Install the CLI once.
26-
dotnet tool install --global Microsoft.Playwright.CLI
2725
# Use the tools.
28-
playwright
26+
pwsh bin\Debug\netX\playwright.ps1 --help
2927
```
3028

3129
```json js
@@ -58,7 +56,7 @@ playwright install
5856

5957
```bash csharp
6058
# Running without arguments will install default browsers
61-
playwright install
59+
pwsh bin\Debug\netX\playwright.ps1 install
6260
```
6361

6462
You can also install specific browsers by providing an argument:
@@ -80,7 +78,7 @@ playwright install webkit
8078

8179
```bash csharp
8280
# Install WebKit
83-
playwright install webkit
81+
pwsh bin\Debug\netX\playwright.ps1 install webkit
8482
```
8583

8684
See all supported browsers:
@@ -174,7 +172,7 @@ playwright codegen --load-storage=auth.json my.web.app
174172

175173
```bash csharp
176174
pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json my.web.app
177-
playwright codegen --load-storage=auth.json my.web.app
175+
pwsh bin\Debug\netX\playwright.ps1 codegen --load-storage=auth.json my.web.app
178176
# Perform actions in authenticated state.
179177
```
180178

@@ -300,7 +298,7 @@ playwright open example.com
300298

301299
```bash csharp
302300
# Open page in Chromium
303-
playwright open example.com
301+
pwsh bin\Debug\netX\playwright.ps1 open example.com
304302
```
305303

306304
```bash js
@@ -320,7 +318,7 @@ playwright wk example.com
320318

321319
```bash csharp
322320
# Open page in WebKit
323-
playwright wk example.com
321+
pwsh bin\Debug\netX\playwright.ps1 wk example.com
324322
```
325323

326324
### Emulate devices
@@ -343,7 +341,7 @@ playwright open --device="iPhone 11" wikipedia.org
343341

344342
```bash csharp
345343
# Emulate iPhone 11.
346-
playwright open --device="iPhone 11" wikipedia.org
344+
pwsh bin\Debug\netX\playwright.ps1 open --device="iPhone 11" wikipedia.org
347345
```
348346

349347
### Emulate color scheme and viewport size
@@ -365,7 +363,7 @@ playwright open --viewport-size=800,600 --color-scheme=dark twitter.com
365363

366364
```bash csharp
367365
# Emulate screen size and color scheme.
368-
playwright open --viewport-size=800,600 --color-scheme=dark twitter.com
366+
pwsh bin\Debug\netX\playwright.ps1 open --viewport-size=800,600 --color-scheme=dark twitter.com
369367
```
370368

371369
### Emulate geolocation, language and timezone
@@ -391,7 +389,7 @@ playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --l
391389
```bash csharp
392390
# Emulate timezone, language & location
393391
# Once page opens, click the "my location" button to see geolocation in action
394-
playwright open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
392+
pwsh bin\Debug\netX\playwright.ps1 open --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
395393
```
396394

397395
## Inspect selectors
@@ -491,7 +489,7 @@ playwright screenshot \
491489

492490
```bash csharp
493491
# Wait 3 seconds before capturing a screenshot after page loads ('load' event fires)
494-
playwright screenshot \
492+
pwsh bin\Debug\netX\playwright.ps1 screenshot \
495493
--device="iPhone 11" \
496494
--color-scheme=dark \
497495
--wait-for-timeout=3000 \
@@ -515,7 +513,7 @@ playwright screenshot --full-page en.wikipedia.org wiki-full.png
515513

516514
```bash csharp
517515
# Capture a full page screenshot
518-
playwright screenshot --full-page en.wikipedia.org wiki-full.png
516+
pwsh bin\Debug\netX\playwright.ps1 screenshot --full-page en.wikipedia.org wiki-full.png
519517
```
520518

521519
## Generate PDF
@@ -539,7 +537,7 @@ playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
539537

540538
```bash csharp
541539
# See command help
542-
playwright pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
540+
pwsh bin\Debug\netX\playwright.ps1 pdf https://en.wikipedia.org/wiki/PDF wiki.pdf
543541
```
544542

545543
## Install system dependencies
@@ -563,7 +561,7 @@ playwright install-deps
563561

564562
```bash csharp
565563
# See command help
566-
playwright install-deps
564+
pwsh bin\Debug\netX\playwright.ps1 install-deps
567565
```
568566

569567
You can also install the dependencies for a single browser only by passing it as an argument:

docs/src/codegen.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ playwright codegen wikipedia.org
2222
```
2323

2424
```bash csharp
25-
playwright codegen wikipedia.org
25+
pwsh bin\Debug\netX\playwright.ps1 codegen wikipedia.org
2626
```
2727

2828
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
5252
```
5353

5454
```bash csharp
55-
playwright codegen --save-storage=auth.json
55+
pwsh bin\Debug\netX\playwright.ps1 codegen --save-storage=auth.json
5656
# Perform authentication and exit.
5757
# auth.json will contain the storage state.
5858
```
@@ -79,8 +79,8 @@ playwright codegen --load-storage=auth.json my.web.app
7979
```
8080

8181
```bash csharp
82-
playwright open --load-storage=auth.json my.web.app
83-
playwright codegen --load-storage=auth.json my.web.app
82+
pwsh bin\Debug\netX\playwright.ps1 open --load-storage=auth.json my.web.app
83+
pwsh bin\Debug\netX\playwright.ps1 codegen --load-storage=auth.json my.web.app
8484
# Perform actions in authenticated state.
8585
```
8686

@@ -206,7 +206,7 @@ playwright codegen --device="iPhone 11" wikipedia.org
206206

207207
```bash csharp
208208
# Emulate iPhone 11.
209-
playwright codegen --device="iPhone 11" wikipedia.org
209+
pwsh bin\Debug\netX\playwright.ps1 codegen --device="iPhone 11" wikipedia.org
210210
```
211211

212212
## Emulate color scheme and viewport size
@@ -230,7 +230,7 @@ playwright codegen --viewport-size=800,600 --color-scheme=dark twitter.com
230230

231231
```bash csharp
232232
# Emulate screen size and color scheme.
233-
playwright codegen --viewport-size=800,600 --color-scheme=dark twitter.com
233+
pwsh bin\Debug\netX\playwright.ps1 codegen --viewport-size=800,600 --color-scheme=dark twitter.com
234234
```
235235

236236
## Emulate geolocation, language and timezone
@@ -256,5 +256,5 @@ playwright codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348"
256256
```bash csharp
257257
# Emulate timezone, language & location
258258
# Once page opens, click the "my location" button to see geolocation in action
259-
playwright codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
259+
pwsh bin\Debug\netX\playwright.ps1 codegen --timezone="Europe/Rome" --geolocation="41.890221,12.492348" --lang="it-IT" maps.google.com
260260
```

docs/src/inspector.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ configures Playwright for debugging and opens the inspector.
6060
pytest -s
6161
```
6262

63+
```bash bash-flavor=bash lang=csharp
64+
PWDEBUG=1 dotnet test
65+
```
66+
67+
```bash bash-flavor=batch lang=csharp
68+
set PWDEBUG=1
69+
dotnet test
70+
```
71+
72+
```bash bash-flavor=powershell lang=csharp
73+
$env:PWDEBUG=1
74+
dotnet test
75+
```
76+
6377
Additional useful defaults are configured when `PWDEBUG=1` is set:
6478
- Browsers launch in the headed mode
6579
- Default timeout is set to 0 (= no timeout)
@@ -105,6 +119,10 @@ configures Playwright for debugging and opens the inspector.
105119
playwright codegen wikipedia.org
106120
```
107121

122+
```bash csharp
123+
pwsh bin\Debug\netX\playwright.ps1 codegen wikipedia.org
124+
```
125+
108126
## Stepping through the Playwright script
109127

110128
When `PWDEBUG=1` is set, Playwright Inspector window will be opened and the script will be

docs/src/release-notes-csharp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Playwright Trace Viewer is now **available online** at https://trace.playwright.
106106
- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.
107107
- You can now use Playwright to install stable version of Edge on Linux:
108108
```bash
109-
npx playwright install msedge
109+
pwsh bin\Debug\netX\playwright.ps1 install msedge
110110
```
111111

112112

@@ -133,7 +133,7 @@ Read more about [`method: Locator.waitFor`].
133133

134134
### 🎭 Playwright Trace Viewer
135135

136-
- run trace viewer with `npx playwright show-trace` and drop trace files to the trace viewer PWA
136+
- run trace viewer with `pwsh bin\Debug\netX\playwright.ps1 show-trace` and drop trace files to the trace viewer PWA
137137
- better visual attribution of action targets
138138

139139
Read more about [Trace Viewer](./trace-viewer).

docs/src/release-notes-java.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Playwright Trace Viewer is now **available online** at https://trace.playwright.
158158
- Playwright now supports **Ubuntu 20.04 ARM64**. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.
159159
- You can now use Playwright to install stable version of Edge on Linux:
160160
```bash
161-
npx playwright install msedge
161+
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install msedge"
162162
```
163163

164164

@@ -185,7 +185,7 @@ Read more about [`method: Locator.waitFor`].
185185

186186
### 🎭 Playwright Trace Viewer
187187

188-
- run trace viewer with `npx playwright show-trace` and drop trace files to the trace viewer PWA
188+
- 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
189189
- better visual attribution of action targets
190190

191191
Read more about [Trace Viewer](./trace-viewer).
@@ -474,10 +474,7 @@ This version of Playwright was also tested against the following stable channels
474474
- [Selecting elements based on layout](./selectors.md#selecting-elements-based-on-layout) with `:left-of()`, `:right-of()`, `:above()` and `:below()`.
475475
- Playwright now includes [command line interface](./cli.md), former playwright-cli.
476476
```bash js
477-
npx playwright --help
478-
```
479-
```bash python
480-
playwright --help
477+
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="--help"
481478
```
482479
- [`method: Page.selectOption`] now waits for the options to be present.
483480
- New methods to [assert element state](./actionability#assertions) like [`method: Page.isEditable`].

0 commit comments

Comments
 (0)