[Bug]: Race condition on macBook Pro M3: test runs too fast for UI render
Version
1.55.0
Steps to reproduce
I don't have any specific repro steps, since this seems to be a race condition, also only with very specific hardware (MacBook Pro M3 in my case).
But I can describe the behavior I encounter:
I have a test which adds an entry to a Syncfusion grid and afterwards tests, if the row can be deleted correctly.
Everything works, except the very last step (the assertion if the entry is gone). This is my test method:
[Fact]
public async Task Remove_a_one_time_job_works()
{
var emailAddress = "[email protected]";
var firstName = "Lisa";
var lastName = "Musterfrau";
await ScheduleMediaRequestAsync(emailAddress, firstName, lastName);
await Page.WaitForSelectorAsync("#grid-scheduled-jobs", new PageWaitForSelectorOptions
{
Timeout = 2000
});
var locator = Page.Locator("#grid-scheduled-jobs")
.Filter(new LocatorFilterOptions
{
HasText = $"Share a media link for {firstName} {lastName}"
})
.Locator("#grid-scheduled-jobs_content_table tbody > tr > td");
await locator.First.WaitForAsync(new LocatorWaitForOptions
{
Timeout = 2000
});
var jobName = await locator.Nth(0).InnerTextAsync();
await Page.Locator($"#delete-{jobName}").ClickAsync();
// on macOS (or more specific on M3) it runs so fast, that the rendering
// of the grid is slower than the click action, so adding this small delay
// fixes this
await Task.Delay(8); // <-- without this line the test fails
(await Page.Locator("#grid-scheduled-jobs").Filter(new LocatorFilterOptions
{
HasText = jobName
}).CountAsync()).Should().Be(expected: 0);
Expected behavior
Yeah.. the test should pass even without that 8ms delay.
Actual behavior
The test failed, but shouldn't.
Additional context
No response
Environment
- Operating System: macOS Tahoe 26.0.1
- CPU: aarch64 (M3 Pro)
- Browser: WebKit
- .NET Version (TFM): net9.0
- Other info:
I assume you are using Blazor. You might want to look into Hydration errors. https://playwright.dev/dotnet/docs/navigations#hydration
With Blazor specifically you have to wait until either InteractiveServer or InteractiveWebassembly are actually ready. By default .Net 8+ Blazor uses Auto render mode, with prerendering, meaning you get a statically rendered page first, Playwright sees the content is there and starts to run, but Blazor has not hydrated yet to be actually usable.
Furthermore you should use Assertions.Expect(locator).ToHaveCountAsync(0) instead of counting it. Calling CountAsync runs immediately, and does not do any of the Playwright auto magic assertions of waiting for elements to have a certain state.