Skip to main content

Running Tests

You can run a single test, a set of tests or all tests. Tests can be run on different browsers. By default tests are run in a headless manner meaning no browser window will be opened while running the tests and results will be seen in the terminal. If you prefer you can run your tests in headed mode by using the headless test run parameter.

  • Running all tests

    dotnet test
  • Running a single test file

    dotnet test --filter "MyClassName"
  • Run a set of test files

    dotnet test --filter "MyClassName1|MyClassName2"
  • Run the test with the title

    dotnet test --filter "Name~TestMethod1"
  • Running Tests on specific browsers

    BROWSER=webkit dotnet test
  • Running Tests on multiple browsers

    To run your test on multiple browsers or configurations you need to invoke the dotnet test command multiple times. There you can then either specify the BROWSER environment variable (like the previous) or pass the browser via the runsettings file:

    dotnet test --settings:chromium.runsettings
    dotnet test --settings:firefox.runsettings
    dotnet test --settings:webkit.runsettings
    <?xml version="1.0" encoding="utf-8"?>
    <RunSettings>
    <TestRunParameters>
    <Parameter name="browser" value="chromium" />
    <Parameter name="headless" value="false" />
    </TestRunParameters>
    </RunSettings>

For more information see selective unit tests in the Microsoft docs.

Debugging Tests

Since Playwright runs in .NET, you can debug it with your debugger of choice in e.g. Visual Studio Code or Visual Studio. Playwright comes with the Playwright Inspector which allows you to step through Playwright API calls, see their debug logs and explore selectors.

PWDEBUG=1 dotnet test
Playwright Inspector

Check out our debugging guide to learn more about the Playwright Inspector as well as debugging with Browser Developer tools.

What's Next