DesktopTests.cs 1.9 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 DesktopTests(
  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_Desktop() {
  13. (IBrowserContext context, IPage page) = await CreatePageAsync();
  14. var resourceName = $"e2e-ap-{Guid.NewGuid():N}"[..16];
  15. try {
  16. // Go home
  17. await page.GotoAsync(_fixture.BaseUrl);
  18. _output.WriteLine($"URL after Goto: {page.Url}");
  19. var layout = new MainLayoutPom(page);
  20. await layout.AssertLoadedAsync();
  21. await layout.GotoHardwareAsync();
  22. var hardwarePage = new HardwareTreePom(page);
  23. await hardwarePage.AssertLoadedAsync();
  24. await hardwarePage.GotoDesktopsListAsync();
  25. var listPage = new DesktopsListPom(page);
  26. await listPage.AssertLoadedAsync();
  27. await listPage.AddDesktopAsync(resourceName);
  28. await listPage.AssertDesktopExists(resourceName);
  29. await listPage.DeleteDesktopAsync(resourceName);
  30. await listPage.AssertDesktopDoesNotExist(resourceName);
  31. await context.CloseAsync();
  32. }
  33. catch (Exception) {
  34. _output.WriteLine("TEST FAILED — Capturing diagnostics");
  35. _output.WriteLine($"Current URL: {page.Url}");
  36. var html = await page.ContentAsync();
  37. _output.WriteLine("==== DOM SNAPSHOT START ====");
  38. _output.WriteLine(html);
  39. _output.WriteLine("==== DOM SNAPSHOT END ====");
  40. throw;
  41. }
  42. finally {
  43. await context.CloseAsync();
  44. }
  45. }
  46. }