AddResourceComponent.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Microsoft.Playwright;
  2. namespace Tests.E2e.PageObjectModels;
  3. public class AddResourceComponent(IPage page, string resourceType) {
  4. private readonly string _resourceType = resourceType.ToLower();
  5. // -------------------------------------------------
  6. // Root & Structure
  7. // -------------------------------------------------
  8. public ILocator Root
  9. => page.GetByTestId($"add-{_resourceType}-root");
  10. public ILocator Title
  11. => page.GetByTestId($"add-{_resourceType}-title");
  12. public ILocator Form
  13. => page.GetByTestId($"add-{_resourceType}-form");
  14. public ILocator Input
  15. => page.GetByTestId($"add-{_resourceType}-input");
  16. public ILocator Button
  17. => page.GetByTestId($"add-{_resourceType}-button");
  18. public ILocator Error
  19. => page.GetByTestId($"add-{_resourceType}-error");
  20. // -------------------------------------------------
  21. // Actions
  22. // -------------------------------------------------
  23. public async Task AddAsync(string name) {
  24. await Assertions.Expect(Root).ToBeVisibleAsync();
  25. // Never type into the prerendered page: those input events are lost before
  26. // the circuit attaches, and the submit then fails with an empty name.
  27. await Assertions.Expect(page.GetByTestId("circuit-probe"))
  28. .ToHaveAttributeAsync("data-circuit-ready", "true");
  29. await Input.FillAsync(name);
  30. await Button.ClickAsync();
  31. }
  32. public async Task AssertErrorAsync(string message) {
  33. await Assertions.Expect(Error)
  34. .ToHaveTextAsync(message);
  35. }
  36. public async Task AssertVisibleAsync() => await Assertions.Expect(Root).ToBeVisibleAsync();
  37. }