Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/TUnit.Templates/content/TUnit.Playwright/Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public static void InstallPlaywright()
Environment.SetEnvironmentVariable("PWDEBUG", "1");
}

var exitCode = Microsoft.Playwright.Program.Main(["install"]);
// Tests use Chromium by default (PlaywrightTest.BrowserName). Add "firefox" or "webkit"
// here if you override BrowserName, so unused browsers are not downloaded.
var exitCode = Microsoft.Playwright.Program.Main(["install", "chromium"]);
if (exitCode != 0)
{
// On Linux, browsers also need system libraries: run `playwright install --with-deps` once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public static void InstallPlaywright()
Environment.SetEnvironmentVariable("PWDEBUG", "1");
}

var exitCode = Microsoft.Playwright.Program.Main(["install"]);
// Tests use Chromium by default (PlaywrightTest.BrowserName). Add "firefox" or "webkit"
// here if you override BrowserName, so unused browsers are not downloaded.
var exitCode = Microsoft.Playwright.Program.Main(["install", "chromium"]);
if (exitCode != 0)
{
// On Linux, browsers also need system libraries: run `playwright install --with-deps` once.
Expand Down
15 changes: 14 additions & 1 deletion tools/TUnit.Pipeline/Modules/InstallPlaywrightModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ protected override ModuleConfiguration Configure() => ModuleConfiguration.Create

protected override async Task<CommandResult?> ExecuteAsync(IModuleContext context, CancellationToken cancellationToken)
{
if (OperatingSystem.IsLinux())
{
// Cancelling a timed-out attempt kills bash but not the sudo'd apt-get
// that Playwright spawns, so the retry fails instantly on the dpkg lock.
// Make apt wait for the lock instead.
await context.Shell.Bash.Command(
new BashCommandOptions("echo 'DPkg::Lock::Timeout \"300\";' | sudo tee /etc/apt/apt.conf.d/99-tunit-lock-timeout"),
cancellationToken);
}

using var attemptCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
attemptCts.CancelAfter(PerAttemptTimeout);

// Only Chromium is used by the Playwright tests. Installing every browser
// pulls in the WebKit/Firefox GStreamer apt dependencies, which can take
// longer than the per-attempt timeout on its own.
return await context.Shell.Bash.Command(
new BashCommandOptions("npx playwright install --with-deps"),
new BashCommandOptions("npx playwright install --with-deps chromium"),
Comment thread
thomhurst marked this conversation as resolved.
Resolved
Comment thread
thomhurst marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
attemptCts.Token);
}
}
Loading