LabelsPom.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Microsoft.Playwright;
  2. namespace Tests.E2e.PageObjectModels;
  3. public class LabelsPom(IPage page) {
  4. public ILocator Root(string testIdPrefix)
  5. => page.GetByTestId($"{testIdPrefix}-resource-label-editor");
  6. public ILocator AddButton(string testIdPrefix)
  7. => Root(testIdPrefix).GetByTestId($"{testIdPrefix}-resource-label-editor-add");
  8. public ILocator Label(string testIdPrefix, string key)
  9. => Root(testIdPrefix).GetByTestId($"{testIdPrefix}-resource-label-editor-label-{key}");
  10. public ILocator LabelViewButton(string testIdPrefix, string key)
  11. => Root(testIdPrefix).GetByTestId($"{testIdPrefix}-resource-label-editor-label-{key}-view");
  12. public ILocator RemoveLabelButton(string testIdPrefix, string key)
  13. => Root(testIdPrefix).GetByTestId($"{testIdPrefix}-resource-label-editor-label-{key}-remove");
  14. public ILocator ModalKeyInput(string testIdPrefix)
  15. => page.GetByTestId($"{testIdPrefix}-resource-label-editor-key-value-modal-key-input");
  16. public ILocator ModalValueInput(string testIdPrefix)
  17. => page.GetByTestId($"{testIdPrefix}-resource-label-editor-key-value-modal-value-input");
  18. public ILocator ModalSubmit(string testIdPrefix)
  19. => page.GetByTestId($"{testIdPrefix}-resource-label-editor-key-value-modal-submit");
  20. public async Task AddLabelAsync(string testIdPrefix, string key, string value) {
  21. await AddButton(testIdPrefix).ClickAsync();
  22. await Assertions.Expect(ModalKeyInput(testIdPrefix)).ToBeVisibleAsync();
  23. await ModalKeyInput(testIdPrefix).FillAsync(key);
  24. await ModalValueInput(testIdPrefix).FillAsync(value);
  25. await ModalSubmit(testIdPrefix).ClickAsync();
  26. }
  27. public async Task EditLabelAsync(string testIdPrefix, string existingKey, string newKey, string newValue) {
  28. await LabelViewButton(testIdPrefix, existingKey).ClickAsync();
  29. await Assertions.Expect(ModalKeyInput(testIdPrefix)).ToBeVisibleAsync();
  30. await ModalKeyInput(testIdPrefix).FillAsync(newKey);
  31. await ModalValueInput(testIdPrefix).FillAsync(newValue);
  32. await ModalSubmit(testIdPrefix).ClickAsync();
  33. }
  34. public async Task RemoveLabelAsync(string testIdPrefix, string key) =>
  35. await RemoveLabelButton(testIdPrefix, key).ClickAsync();
  36. public async Task AssertLabelVisibleAsync(string testIdPrefix, string key) =>
  37. await Assertions.Expect(Label(testIdPrefix, key)).ToBeVisibleAsync();
  38. public async Task AssertLabelNotVisibleAsync(string testIdPrefix, string key) =>
  39. await Assertions.Expect(Label(testIdPrefix, key)).Not.ToBeVisibleAsync();
  40. public async Task AssertLabelDisplaysAsync(string testIdPrefix, string key, string expectedValue) {
  41. ILocator locator = Label(testIdPrefix, key);
  42. await Assertions.Expect(locator).ToBeVisibleAsync();
  43. await Assertions.Expect(locator).ToContainTextAsync($"{key}: {expectedValue}");
  44. }
  45. }