What changed, and why it matters
This commit only changes test code. It fixes a flaky automated UI test by replacing two generic page-load waits with a helper that waits for a specific logged-in URL, and corrects the logic for deciding whether Playwright browser tests run in headless mode. There is no change to production code and no security relevance.
No security action needed. Treat as routine test-maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies two files under BTCPayServer.Tests. ImpersonationTests.cs replaces two consecutive WaitForLoadStateAsync calls with s.WaitLoggedIn(), which is a more deterministic wait. PlaywrightTester.cs flips the Headless boolean expression from string.IsNullOrEmpty(headless) || bool.Parse(headless) to !string.IsNullOrEmpty(headless) && bool.Parse(headless), and updates WaitLoggedIn() to wait for /stores/create when StoreId is null or /stores/{StoreId} otherwise. No application logic is changed.
Changed components
BTCPayServer.Tests/ImpersonationTests.csBTCPayServer.Tests/PlaywrightTester.csInspect captured patch +6 / −4
diff --git a/BTCPayServer.Tests/ImpersonationTests.cs b/BTCPayServer.Tests/ImpersonationTests.cs
index ce43b8a..5298e76 100644
--- a/BTCPayServer.Tests/ImpersonationTests.cs
+++ b/BTCPayServer.Tests/ImpersonationTests.cs
@@ -36,9 +36,8 @@ public class ImpersonationTests(ITestOutputHelper helper) : UnitTestBase(helper)
await s.Page.EvaluateAsync("document.querySelector('#login-password-fieldset').disabled = true");
await s.Page.EvaluateAsync($"document.getElementById('LoginCode').value = '{code}'");
await s.Page.EvaluateAsync("document.getElementById(\"LoginCodeButton\").click();");
- await s.Page.WaitForLoadStateAsync();
- await s.Page.WaitForLoadStateAsync();
+ await s.WaitLoggedIn();
await s.CreateNewStore();
await s.GoToHome();
await s.Page.WaitForLoadStateAsync();
diff --git a/BTCPayServer.Tests/PlaywrightTester.cs b/BTCPayServer.Tests/PlaywrightTester.cs
index 1bfd117..0b3ca0f 100644
--- a/BTCPayServer.Tests/PlaywrightTester.cs
+++ b/BTCPayServer.Tests/PlaywrightTester.cs
@@ -54,7 +54,7 @@ namespace BTCPayServer.Tests
var headless = conf["PLAYWRIGHT_HEADLESS"];
Browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
- Headless = string.IsNullOrEmpty(headless) || bool.Parse(headless),
+ Headless = !string.IsNullOrEmpty(headless) && bool.Parse(headless),
ExecutablePath = conf["PLAYWRIGHT_EXECUTABLE"],
SlowMo = 0, // 50 if you want to slow down
Args = ["--disable-frame-rate-limit"] // Fix slowness on linux (https://github.com/microsoft/playwright/issues/34625#issuecomment-2822015672)
@@ -1007,7 +1007,10 @@ namespace BTCPayServer.Tests
public async Task WaitLoggedIn()
{
- await Page.WaitForURLAsync(ServerUri.AbsoluteUri + $"stores/{StoreId}");
+ if (StoreId is null)
+ await Page.WaitForURLAsync(ServerUri.AbsoluteUri + $"stores/create");
+ else
+ await Page.WaitForURLAsync(ServerUri.AbsoluteUri + $"stores/{StoreId}");
}
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.