diff --git a/_tests/UdapEd.E2E/UdapEdPage.cs b/_tests/UdapEd.E2E/UdapEdPage.cs index 306ffa6..ce426e7 100644 --- a/_tests/UdapEd.E2E/UdapEdPage.cs +++ b/_tests/UdapEd.E2E/UdapEdPage.cs @@ -98,13 +98,32 @@ public async Task ExpandAsync(ILocator panel) /// Ticks a MudCheckBox input unless it is already checked. MudCheckBox shows the new state when Blazor re-renders /// after the click; Playwright's CheckAsync looks right after clicking and fails when that render is slow (the page /// busy saving app state, say). So: click, then wait for the box to show as checked. + /// A click can also be lost outright on a slow machine (the CI runner): the box is mid re-render, or its panel is + /// still expanding, when the forced click lands. Nothing would retry it, so the box stayed unchecked and the test + /// failed. So: if the box has not shown as checked a few seconds after a click, click again, until a deadline. /// public async Task CheckAsync(ILocator checkBoxInput) { - if (!await checkBoxInput.IsCheckedAsync()) + var deadline = DateTime.UtcNow.AddSeconds(20); + while (DateTime.UtcNow < deadline) { + if (await checkBoxInput.IsCheckedAsync()) + { + return; + } + await checkBoxInput.ClickAsync(new LocatorClickOptions { Force = true }); + try + { + await Assertions.Expect(checkBoxInput).ToBeCheckedAsync(new LocatorAssertionsToBeCheckedOptions { Timeout = 3_000 }); + return; + } + catch (PlaywrightException) + { + // The click was lost or the render is slow; look again before clicking, so a late render isn't undone. + } } + await Assertions.Expect(checkBoxInput).ToBeCheckedAsync(); }