-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] watch mode for e2e tests #7035
Comments
As a workaround with Playwright 1.12+ I’m using the { "scripts": {
"test:e2e": "playwright test --config=tests/playwright.config.ts",
"test:e2e:watch": "chokidar 'tests/e2e/**/*.test.ts' -c 'npm run test:e2e -- --retries=0 {path}'",
}} Of course modify these scripts according to your needs. Coupled to |
This is going to be rebooted as a part of the debugging story. Closing with no replacement for now. |
This would be better :) |
I made a library playwright-watch
🙈🐵 Run Playwright in watch mode Usageuse exactly the same as Playwright, only in watch mode npx playwright-watch test
Or you can install locallyyarn add playwright-watch -D
#or
npm install playwright-watch --save-dev Add script to your package.json {
"test:watch": "playwright-watch test"
} or {
"test": "playwright test",
"test:watch": "playwright-watch exec yarn test"
} CLI Detailsrun 🙈 playwright-watch
🐵 Run Playwright in watch mode
Commands:
playwright-watch <commands..> Use the same as Playwright but under watch
(e.g. playwright-watch test) [default]
playwright-watch exec <commands..> Run commands when changes are detected
(e.g. playwright-watch exec yarn test)
Options:
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
-c, --config Configuration file of Playwright (default:
playwright.config.js), the `testMatch` prop will be watch path
(default: `.*(test|spec).(js|ts|mjs)`).
Examples:
playwright-watch test
playwright-watch test --config tests/playwright.config.js
playwright-watch exec yarn playwright test
playwright-watch exec yarn run test:e2e
playwright-watch exec echo changed Author |
Thanks for this tool @iamyoki as a workaround! @pavelfeldman would be great if adding a watch mode could still be considered to be added to Playwright regardless. I’m planning on using PW as a general test runner (mostly for non-web tests), so this functionality would be quite important for my use cases. 🙏 |
@pavelfeldman |
Yes please! |
until then, another workaround using nodemon --watch playwright/specs --exec \"playwright test -c playwright.config.ts\"", also works great when using with the inspector: nodemon --watch playwright/specs --exec \"PWDEBUG=1 playwright test -c playwright.config.ts\"", if using with typescript with custom tsconfig.json, I have set up a "pw:dev": "yarn pw:watch & nodemon --watch playwright/tests-out --exec \"yarn pw:test\"",
"pw:dev:debug": "yarn pw:watch & nodemon --watch playwright/tests-out --exec \"yarn pw:test:debug\"",
"pw:watch": "tsc --incremental -p playwright/specs/tsconfig.json --watch & tsc-alias -p playwright/specs/tsconfig.json -w",
"pw:test": "playwright test -c playwright.config.ts",
"pw:test:debug": "PWDEBUG=1 playwright test -c playwright.config.ts" |
Before I decided to create playwright-watch, I have tried this way, the only problem is that if the save is triggered multiple times in a short period of time, playwright will concurrently run multiple processes and cause memory overflow. |
you can always add a delay with changing files :) -> https://github.com/remy/nodemon#delaying-restarting |
We recently started using Playwright where I work & many peer teams are starting to move away from Cypress 1 common thing I hear from former Cypress users is if there is something similar to the Resources: |
Hey, adding a bit to the discussion here. About 3 years ago I build a large e2e test suite with Cypress and I was in love with it. After a long time battling with cypress I came to also hate some parts of it and started looking for alternatives and found playwright. This seems like a winner, but I just can't use it. It's impossible to be productive when writing new specs if I have to constantly type commands go back and forth between the test code and the test runner. I haven't read all of the documentation yet, but is there something I'm missing? I think watch mode should be one of the things that should just work out of the box. |
This is needed, tests should be able to |
@iamzapata I think you want this: https://github.com/microsoft/playwright-vscode |
A watch mode would be great, it's kind of the only deal-breaker between Playwright and Cypress in my opinion. Is it this issue that's referred to in the docs?: https://playwright.dev/docs/test-components#planned-work
|
Ran into this trying to create a VSCode debugger profile for our playwright tests. (I know about https://github.com/microsoft/playwright-vscode (from this thread), but I just wanted to be able to tweak an existing debugger profile because it's faster than learning a whole new tool.) I started by trying For context:
launch.json {
"version": "0.2.0",
"inputs": [
// Get the name of the package containing the file in the active tab.
{
"id": "getPackageName",
"type": "command",
"command": "shellCommand.execute",
"args": {
// Get the current file's absolute path, chop off everything up to and including the repo's `packages`
// directory, the split on `/` and take the first entry
"command": "echo '${file}' | sed s/'.*sentry-javascript\\/packages\\/'// | grep --extended-regexp --only-matching --max-count 1 '[^\\/]+' | head -1",
"cwd": "${workspaceFolder}",
// normally `input` commands bring up a selector for the user, but given that there should only be one
// choice here, this lets us skip the prompt
"useSingleResult": true
}
}
],
"configurations": [
// Run a specific test file in watch mode (must have file in currently active tab when hitting the play button).
// NOTE: If you try to run this and VSCode complains that the command `shellCommand.execute` can't be found, go
// install the recommended extension Tasks Shell Input.
{
"name": "Debug playwright tests (just open file)",
"type": "pwa-node",
"cwd": "${workspaceFolder}/packages/${input:getPackageName}",
"request": "launch",
"runtimeExecutable": "yarn",
"runtimeArgs": [
// `nodemon` is basically `node --watch`
"nodemon",
// be default it only watches JS files, so have it watch TS files instead
"--ext",
"ts",
"${workspaceFolder}/node_modules/playwright/node_modules/.bin/playwright",
"test",
"${file}"
],
"skipFiles": ["<node_internals>/**"],
"outFiles": ["${workspaceFolder}/**/*.js", "!**/node_modules/**"],
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
// show stdout and stderr output in the debug console
"outputCapture": "std"
}
]
} |
This adds a VSCode debugging profile for playwright tests, which works the same way the unit test debugging profile works - whatever file is open in the active editor will be the one tested, and the tests run in watch mode. Because playwright doesn't have a watch mode of its own[1], the profile uses the `nodemon` Node wrapper[2] to do the watching of files and restarting of tests whenever anything changes. [1] microsoft/playwright#7035 [2] https://github.com/remy/nodemon
It would be nice if meanwhile the |
Dayumn, wanted to migrate to Playwright from Cypress so much (in LOVE with natural js async behavior), but absence of watch mode like in Cypress really stops me. |
An awesome and super developer friendly solution to wrap playwright in a vitest runner (or jest, but it is soo 2022 ;) ). In this case managing, rerunning, debugging tests are much easier. Official example: https://github.com/vitest-dev/vitest/blob/main/examples/playwright/test/basic.test.ts |
Correct me if I'm wrong, but if we use |
@alexbjorlig You totally right, if you use different test runners, you get the third party test runner's benefits, but loose the playwright test runner underlying features. In terms of fixtures, we have to directly setup page fixtures, maybe in the |
It is still in the plans, right? |
Watch mode is a must have feature in my opinion. Have been excited about Playwright and had plans to switch from Cypress, but not without having a watch mode. |
Well, It is late for us, we switched to Playwright not knowing there was not watch mode. |
Would be patient, i think they will add it sooner or later!👀 |
Hey everyone! We’ve hacked together a visual watch mode for Playwright - it’ll run and pop open a debugger any time you hit save (similar to Cypress) - would love to hear what y’all think! https://www.npmjs.com/package/@deploysentinel/playwright-watch tl;dr docs:Install:
Run:
|
Nice for checking, thanks! |
The developer experience and touches on looknice! 💙 pw-debugger-sentintenel-demo.mp4 |
Please implement this feature :) I think I can work around it by starting it all on some unique predefined ports using some |
This is now fixed with the new UI mode in Playwright 1.32.
Please give UI mode a try and let us know (via filing new issues) if something doesn't work! |
That's fantastic but...is there a way to watch without the UI? There's reasons launch a full UI just to watch tests and get feedback might not be ideal. |
@RichiCoder1 would you mind filing a separate issue and explaning your use case there? This way we'll be able to gauge interest and asses uses cases. Thanks! |
Created #21960 for headless watch mode. Lmk if I can phrase it better! |
Just to mention, I do not use VS code (I use VIM) so if this feature is ever implemented please do not tightly couple it with VS code. |
I'm wondering if there's a way to make the playwright E2E watch both the tests and the source code, I know it might not be a priority since the usual SDLC even with TDD is to have unit tests running on watch mode while we develop, and E2E gets added later at the end just to tie it all together, or to cover dark bugs regression testing. It's just that part of the promise of the monorepo is to have dependency and colocation on other apps & libs in the monorepo, I was expecting the E2E to watch its dependencies just like apps & libs do theirs when serving or running tests. |
If you want to watch in headless mode, try the following command. ref: #21960 (comment) $ PWTEST_WATCH=1 npx playwright test |
I'd really appreciate a watch mode. My hands hurt from running my test over and over.
If you are looking for the watch mode that runs tests on save, I found assigning the shortcut to Run Test at Cursor very handy:
Playwright VS Code Extension is likely to mitigate your request
VS Code extension makes writing and debugging tests convenient, there is no need to go between code and terminal back and forth.
The text was updated successfully, but these errors were encountered: