BasePage.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package com.provectus.kafka.ui.pages;
  2. import static com.codeborne.selenide.Selenide.$$x;
  3. import static com.codeborne.selenide.Selenide.$x;
  4. import com.codeborne.selenide.Condition;
  5. import com.codeborne.selenide.ElementsCollection;
  6. import com.codeborne.selenide.SelenideElement;
  7. import com.codeborne.selenide.WebDriverRunner;
  8. import com.provectus.kafka.ui.pages.panels.enums.MenuItem;
  9. import com.provectus.kafka.ui.utilities.WebUtils;
  10. import java.time.Duration;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.openqa.selenium.Keys;
  13. import org.openqa.selenium.interactions.Actions;
  14. @Slf4j
  15. public abstract class BasePage extends WebUtils {
  16. protected SelenideElement loadingSpinner = $x("//div[@role='progressbar']");
  17. protected SelenideElement submitBtn = $x("//button[@type='submit']");
  18. protected SelenideElement tableGrid = $x("//table");
  19. protected SelenideElement searchFld = $x("//input[@type='text'][contains(@id, ':r')]");
  20. protected SelenideElement dotMenuBtn = $x("//button[@aria-label='Dropdown Toggle']");
  21. protected SelenideElement alertHeader = $x("//div[@role='alert']//div[@role='heading']");
  22. protected SelenideElement alertMessage = $x("//div[@role='alert']//div[@role='contentinfo']");
  23. protected SelenideElement confirmationMdl = $x("//div[text()= 'Confirm the action']/..");
  24. protected SelenideElement confirmBtn = $x("//button[contains(text(),'Confirm')]");
  25. protected SelenideElement cancelBtn = $x("//button[contains(text(),'Cancel')]");
  26. protected SelenideElement backBtn = $x("//button[contains(text(),'Back')]");
  27. protected SelenideElement nextBtn = $x("//button[contains(text(),'Next')]");
  28. protected ElementsCollection ddlOptions = $$x("//li[@value]");
  29. protected ElementsCollection gridItems = $$x("//tr[@class]");
  30. protected String summaryCellLocator = "//div[contains(text(),'%s')]";
  31. protected String tableElementNameLocator = "//tbody//a[contains(text(),'%s')]";
  32. protected String columnHeaderLocator = "//table//tr/th//div[text()='%s']";
  33. protected String pageTitleFromHeader = "//h1[text()='%s']";
  34. protected String pagePathFromHeader = "//a[text()='%s']/../h1";
  35. protected boolean isSpinnerVisible(int... timeoutInSeconds) {
  36. return isVisible(loadingSpinner, timeoutInSeconds);
  37. }
  38. protected void waitUntilSpinnerDisappear(int... timeoutInSeconds) {
  39. log.debug("\nwaitUntilSpinnerDisappear");
  40. if (isSpinnerVisible(timeoutInSeconds)) {
  41. loadingSpinner.shouldBe(Condition.disappear, Duration.ofSeconds(60));
  42. }
  43. }
  44. protected void searchItem(String tag) {
  45. log.debug("\nsearchItem: {}", tag);
  46. sendKeysAfterClear(searchFld, tag);
  47. searchFld.pressEnter().shouldHave(Condition.value(tag));
  48. waitUntilSpinnerDisappear(1);
  49. }
  50. protected SelenideElement getPageTitleFromHeader(MenuItem menuItem) {
  51. return $x(String.format(pageTitleFromHeader, menuItem.getPageTitle()));
  52. }
  53. protected SelenideElement getPagePathFromHeader(MenuItem menuItem) {
  54. return $x(String.format(pagePathFromHeader, menuItem.getPageTitle()));
  55. }
  56. protected void clickSubmitBtn() {
  57. clickByJavaScript(submitBtn);
  58. }
  59. protected void setJsonInputValue(SelenideElement jsonInput, String jsonConfig) {
  60. sendKeysByActions(jsonInput, jsonConfig.replace(" ", ""));
  61. new Actions(WebDriverRunner.getWebDriver())
  62. .keyDown(Keys.SHIFT)
  63. .sendKeys(Keys.PAGE_DOWN)
  64. .keyUp(Keys.SHIFT)
  65. .sendKeys(Keys.DELETE)
  66. .perform();
  67. }
  68. protected SelenideElement getTableElement(String elementName) {
  69. log.debug("\ngetTableElement: {}", elementName);
  70. return $x(String.format(tableElementNameLocator, elementName));
  71. }
  72. protected ElementsCollection getDdlOptions() {
  73. return ddlOptions;
  74. }
  75. protected String getAlertHeader() {
  76. log.debug("\ngetAlertHeader");
  77. String result = alertHeader.shouldBe(Condition.visible).getText();
  78. log.debug("-> {}", result);
  79. return result;
  80. }
  81. protected String getAlertMessage() {
  82. log.debug("\ngetAlertMessage");
  83. String result = alertMessage.shouldBe(Condition.visible).getText();
  84. log.debug("-> {}", result);
  85. return result;
  86. }
  87. protected boolean isAlertVisible(AlertHeader header) {
  88. log.debug("\nisAlertVisible: {}", header.toString());
  89. boolean result = getAlertHeader().equals(header.toString());
  90. log.debug("-> {}", result);
  91. return result;
  92. }
  93. protected boolean isAlertVisible(AlertHeader header, String message) {
  94. log.debug("\nisAlertVisible: {} {}", header, message);
  95. boolean result = isAlertVisible(header) && getAlertMessage().equals(message);
  96. log.debug("-> {}", result);
  97. return result;
  98. }
  99. protected void clickConfirmButton() {
  100. confirmBtn.shouldBe(Condition.enabled).click();
  101. confirmBtn.shouldBe(Condition.disappear);
  102. }
  103. protected void clickCancelButton() {
  104. cancelBtn.shouldBe(Condition.enabled).click();
  105. cancelBtn.shouldBe(Condition.disappear);
  106. }
  107. protected boolean isConfirmationModalVisible() {
  108. return isVisible(confirmationMdl);
  109. }
  110. public enum AlertHeader {
  111. SUCCESS("Success"),
  112. VALIDATION_ERROR("Validation Error"),
  113. BAD_REQUEST("400 Bad Request");
  114. private final String value;
  115. AlertHeader(String value) {
  116. this.value = value;
  117. }
  118. public String toString() {
  119. return value;
  120. }
  121. }
  122. }