diff --git a/src/BloomExe/WebView2Browser.cs b/src/BloomExe/WebView2Browser.cs
index b66b1f43f53b..fb23e879c29f 100644
--- a/src/BloomExe/WebView2Browser.cs
+++ b/src/BloomExe/WebView2Browser.cs
@@ -396,9 +396,13 @@ private async Task InitWebView()
{
additionalBrowserArgs += " --accept-lang=" + _uiLanguageOfThisRun;
}
- if (RemoteDebuggingPort.HasValue)
+ if (RemoteDebuggingPort.HasValue && !Program.RunningUnitTests)
{
// Expose a CDP endpoint so Playwright and other automation can attach to the real Bloom WebView2 surface.
+ // NOT in unit tests: nothing attaches to a test-run WebView2, and on a busy CI machine the port
+ // (BloomServer's http port + 2) can already be held by a real Bloom instance running beside the
+ // tests, in which case Chromium's fight over the port breaks WebView2 startup and fails the test
+ // (seen as flaky BookUploadAndDownloadTests upload failures on agents also running Bloom automation).
additionalBrowserArgs += $" --remote-debugging-port={RemoteDebuggingPort.Value} "; // allow external inspector connect
}
if (featuresToDisable.Count > 0)
diff --git a/src/BloomTests/ProgramTests.cs b/src/BloomTests/ProgramTests.cs
index 5a721d9ec66e..afea45f47f3a 100644
--- a/src/BloomTests/ProgramTests.cs
+++ b/src/BloomTests/ProgramTests.cs
@@ -6,6 +6,19 @@ namespace BloomTests
[TestFixture]
public class ProgramTests
{
+ ///
+ /// ParseStartupPortArguments stores its results in Program statics (StartupAutomation etc.)
+ /// which live for the rest of the test run. Re-parse empty args after each test to restore
+ /// the defaults; the method resets all of them on entry. Without this, the "--automation"
+ /// tests here left StartupAutomation=true for every later fixture, which (among other
+ /// things) made BloomServer print automation banners in unrelated tests' output.
+ ///
+ [TearDown]
+ public void TearDown()
+ {
+ Program.ParseStartupPortArguments(System.Array.Empty(), out _);
+ }
+
[Test]
public void ParseStartupPortArguments_RemovesPortsAndStoresExplicitValues()
{
diff --git a/src/BloomTests/ShellTests.cs b/src/BloomTests/ShellTests.cs
index ffb8d32a999d..ac6f63674560 100644
--- a/src/BloomTests/ShellTests.cs
+++ b/src/BloomTests/ShellTests.cs
@@ -7,6 +7,17 @@ namespace BloomTests
[TestFixture]
public class ShellTests
{
+ ///
+ /// ParseStartupPortArguments writes into Program statics that live for the rest of the
+ /// test run; re-parse empty args after each test to restore the defaults (the method
+ /// resets them all on entry). Same rationale as the ProgramTests TearDown.
+ ///
+ [TearDown]
+ public void TearDown()
+ {
+ Program.ParseStartupPortArguments(Array.Empty(), out _);
+ }
+
[Test]
public void ShouldShowPortSummaryInWindowTitle_TracksAutomationFlag()
{