Skip to content

TUnit.Playwright: support a run-level headed switch (HEADED / BROWSER env or CLI option) #7285

Closed

Description

@thomhurst

Problem

TUnit.Playwright has no run-level switch for headed browsers. BrowserFixture.GetLaunchOptions() and BrowserTest use TUnitPlaywrightSettings.Default.DefaultBrowserTypeLaunchOptions ?? new BrowserTypeLaunchOptions() (BrowserFixture.cs:21-22, BrowserTest.cs:8), and nothing in the package reads an environment variable or command-line option for headed mode or browser choice.

So switching between headless CI and a visible local debug session means a code change, or a hand-written policy in every suite. Teams usually end up with something like Headless = !Debugger.IsAttached in a global settings hook. That silently ignores any documented environment switch and launches headless when a developer runs from a terminal.

The Microsoft Playwright .NET test adapters (NUnit and MSTest) honor HEADED=1 and BROWSER=<name> for this reason, so the same dotnet test invocation can run headed locally and headless in CI. Playwright itself also honors PWDEBUG=1, but only when the launch options leave Headless unset.

Proposed change

  • Read HEADED (and optionally BROWSER) as the default when the user has not set Headless or overridden BrowserName, matching the Microsoft adapters.
  • Alternatively, or in addition, add a TUnit command-line option such as --playwright-headed.
  • Document the precedence: explicit BrowserTypeLaunchOptions.Headless wins, then the switch, then Playwright's default.
  • Document that setting Headless explicitly overrides PWDEBUG=1.

Expected behaviour

HEADED=1 dotnet run --project Tests opens visible browsers for every BrowserTest, PageTest, BrowserFixture and PageFixture consumer with no code change. CI without the variable stays headless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: cleanup, minor enhancement, or rare edge caseenhancementNew feature or requestin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions