LabelsPom.cs 2.9 KB

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