I use VS Code as my text editor/IDE for writing Playwright tests. I can use use VS Code for debugging since it offers full debugging functionality like breakpoints and being able to see variables etc.
To enable this, there’s a couple of things you do:
- I created a
debugtask in my
"debug": "npx playwright test --headed --timeout=0"which means I can use
npm run debugto execute a test without a timeout and showing the browser – by either adding a
.onlyto a specific test, or telling it a file, eg.
npm run debug ./scenarios/test1.spec.ts
- Add a breakpoint in your code using the red dot in the left margin
- You can then use the
npm run debugcommand which starts a debugging session where you can step through and see variables etc.
Happy Debugging & Happy New Year! 🥳