Rayrun

What are the different ways to run tests using Playwright?

Answer

Running Tests with Playwright

Running tests with Playwright is a breeze. You can run a single test, a set of tests, or all tests. By default, tests run in headless mode, meaning no browser window opens, and you see results in the terminal.

Running Tests from the Command Line

Here's how to run your tests from the command line:

  • Run all tests:
    npx playwright test
  • Run a single test file:
    npx playwright test landing-page.spec.ts
  • Run a set of test files:
    npx playwright test tests/todo-page/ tests/landing-page/
  • Run files with "landing" or "login" in the file name:
    npx playwright test landing login
  • Run a test with a specific title:
    npx playwright test -g "add a todo item"

Running Tests in UI Mode

If you want to see your tests running in UI mode for a better developer experience, use this command:

npx playwright test --ui

Debugging Your Tests

Playwright comes with its own inspector for stepping through API calls and exploring locators. You can debug your Playwright API calls using tools like console.log or directly in VS Code with its extension. If a test fails, VS Code shows error messages right in the editor.

For more on mastering Playwright test automation, check out this comprehensive cheat sheet.

References

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

TwitterGitHubLinkedIn
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.