AnsibleInventoryTests.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 AnsibleInventoryTests(
  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_Generate_Ansible_Inventory() {
  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. // Navigate directly to inventory page
  21. await page.GotoAsync($"{_fixture.BaseUrl}/ansible/inventory");
  22. var inventoryPage = new AnsibleInventoryPagePom(page);
  23. await inventoryPage.AssertVisibleAsync();
  24. // Configure options
  25. await inventoryPage.SetGroupByTagsAsync("prod,staging");
  26. await inventoryPage.SetGroupByLabelsAsync("env");
  27. await inventoryPage.SetGlobalVarsAsync("""
  28. ansible_user=ansible
  29. ansible_python_interpreter=/usr/bin/python3
  30. """);
  31. // Generate inventory
  32. await inventoryPage.GenerateAsync();
  33. // Assert output contains expected sections
  34. await inventoryPage.AssertInventoryContainsAsync("[all:vars]");
  35. await inventoryPage.AssertInventoryContainsAsync("ansible_user=ansible");
  36. // Ensure no warnings shown
  37. await inventoryPage.AssertNoWarningsAsync();
  38. await context.CloseAsync();
  39. }
  40. catch (Exception) {
  41. _output.WriteLine("TEST FAILED — Capturing diagnostics");
  42. _output.WriteLine($"Current URL: {page.Url}");
  43. var html = await page.ContentAsync();
  44. _output.WriteLine("==== DOM SNAPSHOT START ====");
  45. _output.WriteLine(html);
  46. _output.WriteLine("==== DOM SNAPSHOT END ====");
  47. throw;
  48. }
  49. finally {
  50. await context.CloseAsync();
  51. }
  52. }
  53. }