Add ability to use AND and OR expression via grep from command line
To bring Windows usage up to par with usage on Mac OS X or Linux,
npx playwright test -g "tag1|tag2"
should also work from the Windows command line. Please.
Edit by maintainers: Here are Git Bash and PowerShell solutions:
PowerShell:
npx playwright test --grep "`"@test1|@test2"`"
Git Bash
npx playwright test --grep "@test1^|@test2"
@humbienri : on Windows do this:
npx playwright test -g "tag1^|tag2"
@pavelfeldman I tried the fix on new project but it doesn't seem to be working for me
I'm on windows 10
powershell:
doesn't work

CMD:
works with just -g tag1|tag2

Git Bash:
works with just -g tag1|tag2

and how can I adapt to predefined sript (in package.json) "scripts": { "onchrome":"playwright test tests/smoke/smokeTests.spec.ts --config=playwright.config.ts --project=chrome" }
so it is working but i would like to use with scriptcommand e.g. npm run onchrome -g "list|response"
how to use and condition in grep?
-g "xy&yz" is not working
how to use and condition in grep?
-g "xy&yz" is not working
Grep is just matching the test title, so you could do something like
-g "xy.+yz"
I also get 'commission' is not recognized as an internal or external command, operable program or batch file.
my full command on Powershell: npx playwright test -g "register|commission" --config=playwright.config.js --workers=3 --retries=1
P.S.: tried escaping it, but still didn't help
In Powershell the stop-parsing token helps:
npx playwright test -g --% "tag1|tag2"
Could someone execute this from the package.json script ?
I m trying: "test:textbox": "npx playwright test --config=./configs/playwright-web.config.js --project=chromium --grep text1 | text2" "test:textbox": "npx playwright test --config=./configs/playwright-web.config.js --project=chromium -g text1|text2"
And also using the stop-parsing token mentioned above. Always getting the same kind of error
"'text2' is not recognized as an internal or external command"
p-parsing token mentioned above. Always getting the same kind of erro
Still facing the issue.
@imartinflores - same here...
"test:form": "npx playwright test --project=chromium -g @payx|@ezlm"
The issue in pwsh is how the command is interpreted! One workaround is by starting the npm process manually and passing the arguments split by pipe as it is used on bash:
$npxArgs = "playwright", "test", "-g", "tag1|tag2|tag3"
Start-Process npx -ArgumentList $npxArgs -Wait -NoNewWindow -ErrorAction Stop
how to use and condition in grep? -g "xy&yz" is not working
Grep is just matching the test title, so you could do something like
-g "xy.+yz"
- This has really worked in Windows / VSCode powershll.
-
-g "xy.+yz"is a And condition
Could someone execute this from the package.json script ?
I m trying: "test:textbox": "npx playwright test --config=./configs/playwright-web.config.js --project=chromium --grep text1 | text2" "test:textbox": "npx playwright test --config=./configs/playwright-web.config.js --project=chromium -g text1|text2"
And also using the stop-parsing token mentioned above. Always getting the same kind of error
"'text2' is not recognized as an internal or external command"
i tried this way with grep under projects in playwright.config.js, and it is working for me, grep:/^(?=.\bsmoke\b)(?=.\bregression\b).*$/m,
This is will read your test title and perform regex on it
npx playwright test -g "tag1^|tag2"
This clearly doesn't work on Windows and many people have already mentioned this, however, it is still being replied as answer to multiple threads.
Any updates on this?
Is there any way to --grep based on three annotations? Condition: Run test that contain @API or @UI on @PROD
Escaping a pipe symbol in PowerShell is unfortunately not straightforward. Escaping it in Git Bash and PowerShell is both different:
PowerShell:
npx playwright test --grep "`"@slow|@fast"`"
Git Bash
npx playwright test --grep "@slow^|@fast"
Unfortunately this is not something we can fix on our side (since the "magic" happens inside the terminals), but what we can do is update our docs to include these two workarounds.
Here are tested solutions (W11 in VS Code) :
Logical OR for tags
PowerShell:
npx playwright test --grep --% "@fast^|@slow"
Git Bash:
npx playwright test -g "@fast|@slow"
CMD:
npx playwright test --grep "@fast^|@slow"
For npm script in package.json:
"npx playwright test -g \"@fast|@slow\""
Logical AND for tags works in all terminals
npx playwright test --grep "(?=.*@fast)(?=.*@slow)"
Remember to check console where script is ran:
@mxschmitt have look on PR with docs update https://github.com/microsoft/playwright/pull/24304
What's the proposed approach when you want to combine some rules from npm script and interactive command line? Example (suggested by @ffluk3):
{ "scripts": { "e2e": "playwright --grep-invert \"@wip\"" } }However, if I wanted to omit another tag on the fly, I wouldn't be able to run
npm run e2e -- --grep-invert @flaky. Is there a recommended way to approach this use case?
In my Windows terminal I'm able to get the OR grep to work by adding a space around the pipe:
npx playwright test -g "@fast | @slow"
Different shells require different escaping, we updated our documentation recently to reflect these changes: https://playwright.dev/docs/test-annotations#tag-tests
Please re-file if you have concrete filters which don't work. Please let us know the following:
- Which shell you are using
- How your test is named
- What your expectation is
Closing for now since we addressed it.