Playwright CLI Commands You Should Know

 Playwright is a powerful open-source testing framework for end-to-end web testing. While it offers a rich API for scripting tests, its Command Line Interface (CLI) is equally essential for quickly generating, running, and debugging tests. Whether you're just getting started or automating your workflows, mastering key Playwright CLI commands can greatly boost your productivity.

npx playwright install

This command installs the required browsers (Chromium, Firefox, WebKit) for Playwright testing.

npx playwright install

Useful when setting up a new project or CI pipeline.

npx playwright codegen [url]

Launches the Codegen tool, which opens a browser, records your actions, and generates the corresponding test code.

npx playwright codegen https://example.com

A great way to quickly bootstrap test scripts without writing code manually.

npx playwright test

Runs all the tests in your project (by default, located in the tests/ directory).

npx playwright test

Add --headed to run tests with the browser UI visible:

npx playwright test --headed

npx playwright test [filename]

Run a specific test file instead of all tests.

npx playwright test tests/login.spec.ts

You can also run a single test inside a file using -g:

npx playwright test -g "should log in with valid credentials"

npx playwright show-report

After running tests, view the HTML report in your browser.

npx playwright show-report

Great for reviewing test results, screenshots, and error traces.

npx playwright install-deps

Installs necessary dependencies for running browsers on Linux systems (especially helpful for CI servers).

npx playwright install-deps

npx playwright screenshot [url] [image-name]

Takes a screenshot of a specific webpage.

npx playwright screenshot https://example.com example.png

npx playwright open

Launches the browser with Playwright's inspector. Useful for debugging and visually stepping through tests.

npx playwright open

Conclusion

Playwright's CLI is more than just a convenience—it’s a powerful toolkit for rapid test development, debugging, and reporting. By incorporating these commands into your workflow, you can streamline your test automation process and make your testing more efficient and scalable. Whether you're writing new tests or running a CI job, these commands are must-knows for any Playwright user.

Learn Playwright Training in Hyderabad

Read More:

Playwright vs Cypress: Key Differences

Page Object Model in Playwright

How to Handle Dropdowns and Checkboxes

Parallel Testing with Playwright

Visit our IHub Talent Training Institute

Get Direction


Comments

Popular posts from this blog

Tosca Installation and Environment Setup

Automated Regression Testing with Selenium

How Playwright Supports Multiple Browsers