SystemTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Microsoft.Playwright;
  2. using Tests.E2e.Infra;
  3. using Tests.E2e.PageObjectModels;
  4. using Xunit.Abstractions;
  5. namespace Tests.E2e;
  6. public class SystemTests(
  7. PlaywrightFixture fixture,
  8. ITestOutputHelper output) : E2ETestBase(fixture, output) {
  9. private readonly PlaywrightFixture _fixture = fixture;
  10. private readonly ITestOutputHelper _output = output;
  11. [Fact]
  12. public async Task User_Can_Add_And_Delete_System() {
  13. (IBrowserContext context, IPage page) = await CreatePageAsync();
  14. try {
  15. // Go home
  16. await page.GotoAsync(_fixture.BaseUrl);
  17. _output.WriteLine($"URL after Goto: {page.Url}");
  18. var layout = new MainLayoutPom(page);
  19. await layout.AssertLoadedAsync();
  20. await layout.GotoSystemsAsync();
  21. var systems = new SystemsListPom(page);
  22. var systemName = $"e2e-system-{Guid.NewGuid():N}"[..12];
  23. await systems.AddSystemAsync(systemName);
  24. await systems.AssertSystemExists(systemName);
  25. await systems.DeleteSystemAsync(systemName);
  26. await systems.AssertSystemDoesNotExist(systemName);
  27. await context.CloseAsync();
  28. }
  29. catch (Exception) {
  30. _output.WriteLine("TEST FAILED — Capturing diagnostics");
  31. _output.WriteLine($"Current URL: {page.Url}");
  32. var html = await page.ContentAsync();
  33. _output.WriteLine("==== DOM SNAPSHOT START ====");
  34. _output.WriteLine(html);
  35. _output.WriteLine("==== DOM SNAPSHOT END ====");
  36. throw;
  37. }
  38. finally {
  39. await context.CloseAsync();
  40. }
  41. }
  42. }