AddResourceRaceTests.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Microsoft.Playwright;
  2. using Tests.E2e.Infra;
  3. using Tests.E2e.PageObjectModels;
  4. using Xunit.Abstractions;
  5. namespace Tests.E2e;
  6. /// <summary>
  7. /// Blazor Server prerenders every page before the circuit attaches, and anything
  8. /// typed into that static HTML never reaches the server-side model. A fast test —
  9. /// or a fast typist on a slow link — can therefore submit the add form and be told
  10. /// "name is required" despite having filled it in. The injected latency makes the
  11. /// attach window, which CI runners only sometimes lose, wide enough to lose every
  12. /// time; the page object must wait for the circuit before it types.
  13. /// </summary>
  14. public class AddResourceRaceTests(
  15. PlaywrightFixture fixture,
  16. ITestOutputHelper output) : E2ETestBase(fixture, output) {
  17. private readonly PlaywrightFixture _fixture = fixture;
  18. [Fact]
  19. public async Task Adding_A_Resource_Works_Before_The_Circuit_Has_Warmed_Up() {
  20. (IBrowserContext context, IPage page) = await CreatePageAsync();
  21. await BlazorLatency.AddAsync(page, TimeSpan.FromMilliseconds(300));
  22. var name = $"e2e-oth-{Guid.NewGuid():N}"[..16];
  23. try {
  24. await page.GotoAsync($"{_fixture.BaseUrl}/other/list");
  25. var list = new OtherListPom(page);
  26. await list.AddOtherAsync(name);
  27. }
  28. finally {
  29. await context.CloseAsync();
  30. }
  31. }
  32. }