How do I run a single test case in headed mode using Playwright?


Running a Single Test in Headed Mode

To run a single test in headed mode with @playwright/test, you can use the command line and the .only annotation. Running tests in headed mode is useful for debugging purposes.

First, add the .only annotation to the specific test case you want to run:

test.only('should display the correct title', async ({ page }) => {
  await page.goto('https://ray.run/');
  const title = await page.title();

Next, run the test file in headed mode using the following command:

npx playwright test your-test-file.spec.ts --headed

Replace your-test-file.spec.ts with the name of your test file.

If you want to specify a browser, use the --browser option followed by "chromium", "firefox", or "webkit":

npx playwright test your-test-file.spec.ts --headed --browser=chromium

This command will open Chromium with the specified test, allowing you to debug more easily.

By using the .only annotation and the --headed option, you can run a single test case in headed mode with @playwright/test.

Thank you!
Was this helpful?
Still have questions?

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

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.