How do I execute Python tests in a browser using Playwright in headed mode?


Running Python Tests in Headed Browsers with Playwright

To see your tests in action, you can run them in headed browsers using Playwright. This is particularly useful for debugging.


First, make sure you've installed Playwright and its Python dependencies. You can find the installation guide on the Playwright website.

Running Tests

Navigate to your test file directory in the terminal and run the following command:

npx playwright test --headed

This will run all your tests in a headed browser mode.

If you want to run specific tests or a single test file, use the following command:

npx playwright test <test-file-name> --headed

Replace <test-file-name> with the name of your specific test file or files.


Running tests in headed mode may slow down your testing process as it requires more resources from your computer than headless mode.

UI Mode

Playwright also offers UI Mode which provides additional features such as time travel debugging and watch mode. To use UI Mode, add the --ui flag after npx playwright test.

npx playwright test --ui

With Playwright's built-in commands and flags such as --headed and --ui, you can easily run Python-headed browser tests and have access to helpful debugging tools.

For more tips on efficient test writing with Playwright, check out this blog post.


Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Questions

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.