BasePage.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.provectus.kafka.ui.pages;
  2. import com.codeborne.selenide.Condition;
  3. import com.codeborne.selenide.ElementsCollection;
  4. import com.codeborne.selenide.SelenideElement;
  5. import com.provectus.kafka.ui.utilities.WebUtils;
  6. import lombok.extern.slf4j.Slf4j;
  7. import java.time.Duration;
  8. import static com.codeborne.selenide.Selenide.$$x;
  9. import static com.codeborne.selenide.Selenide.$x;
  10. @Slf4j
  11. public abstract class BasePage extends WebUtils {
  12. protected SelenideElement loadingSpinner = $x("//div[@role='progressbar']");
  13. protected SelenideElement submitBtn = $x("//button[@type='submit']");
  14. protected SelenideElement tableGrid = $x("//table");
  15. protected SelenideElement dotMenuBtn = $x("//button[@aria-label='Dropdown Toggle']");
  16. protected SelenideElement alertHeader = $x("//div[@role='alert']//div[@role='heading']");
  17. protected SelenideElement alertMessage = $x("//div[@role='alert']//div[@role='contentinfo']");
  18. protected SelenideElement confirmationMdl = $x("//div[text()= 'Confirm the action']/..");
  19. protected SelenideElement confirmBtn = $x("//button[contains(text(),'Confirm')]");
  20. protected SelenideElement cancelBtn = $x("//button[contains(text(),'Cancel')]");
  21. protected ElementsCollection ddlOptions = $$x("//li[@value]");
  22. protected ElementsCollection gridItems = $$x("//tr[@class]");
  23. protected String summaryCellLocator = "//div[contains(text(),'%s')]";
  24. protected String tableElementNameLocator = "//tbody//a[contains(text(),'%s')]";
  25. protected String columnHeaderLocator = "//table//tr/th//div[text()='%s']";
  26. protected void waitUntilSpinnerDisappear() {
  27. log.debug("\nwaitUntilSpinnerDisappear");
  28. if (isVisible(loadingSpinner)) {
  29. loadingSpinner.shouldBe(Condition.disappear, Duration.ofSeconds(30));
  30. }
  31. }
  32. protected void clickSubmitBtn() {
  33. clickByJavaScript(submitBtn);
  34. }
  35. protected SelenideElement getTableElement(String elementName) {
  36. log.debug("\ngetTableElement: {}", elementName);
  37. return $x(String.format(tableElementNameLocator, elementName));
  38. }
  39. protected ElementsCollection getDdlOptions() {
  40. return ddlOptions;
  41. }
  42. protected String getAlertHeader() {
  43. log.debug("\ngetAlertHeader");
  44. String result = alertHeader.shouldBe(Condition.visible).getText();
  45. log.debug("-> {}", result);
  46. return result;
  47. }
  48. protected String getAlertMessage() {
  49. log.debug("\ngetAlertMessage");
  50. String result = alertMessage.shouldBe(Condition.visible).getText();
  51. log.debug("-> {}", result);
  52. return result;
  53. }
  54. protected boolean isAlertVisible(AlertHeader header) {
  55. log.debug("\nisAlertVisible: {}", header.toString());
  56. boolean result = getAlertHeader().equals(header.toString());
  57. log.debug("-> {}", result);
  58. return result;
  59. }
  60. protected boolean isAlertVisible(AlertHeader header, String message) {
  61. log.debug("\nisAlertVisible: {} {}", header, message);
  62. boolean result = isAlertVisible(header) && getAlertMessage().equals(message);
  63. log.debug("-> {}", result);
  64. return result;
  65. }
  66. protected void clickConfirmButton() {
  67. confirmBtn.shouldBe(Condition.enabled).click();
  68. confirmBtn.shouldBe(Condition.disappear);
  69. }
  70. protected void clickCancelButton() {
  71. cancelBtn.shouldBe(Condition.enabled).click();
  72. cancelBtn.shouldBe(Condition.disappear);
  73. }
  74. protected boolean isConfirmationModalVisible() {
  75. return isVisible(confirmationMdl);
  76. }
  77. public enum AlertHeader {
  78. SUCCESS("Success"),
  79. VALIDATION_ERROR("Validation Error"),
  80. BAD_REQUEST("400 Bad Request");
  81. private final String value;
  82. AlertHeader(String value) {
  83. this.value = value;
  84. }
  85. public String toString() {
  86. return value;
  87. }
  88. }
  89. }