BasePage.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.provectus.kafka.ui.pages;
  2. import static com.codeborne.selenide.Selenide.$x;
  3. import com.codeborne.selenide.Condition;
  4. import com.codeborne.selenide.SelenideElement;
  5. import com.provectus.kafka.ui.utilities.WebUtils;
  6. import lombok.extern.slf4j.Slf4j;
  7. @Slf4j
  8. public abstract class BasePage extends WebUtils {
  9. protected SelenideElement loadingSpinner = $x("//*[contains(text(),'Loading')]");
  10. protected SelenideElement submitBtn = $x("//button[@type='submit']");
  11. protected SelenideElement tableGrid = $x("//table");
  12. protected SelenideElement dotMenuBtn = $x("//button[@aria-label='Dropdown Toggle']");
  13. protected SelenideElement alertHeader = $x("//div[@role='alert']//div[@role='heading']");
  14. protected SelenideElement alertMessage = $x("//div[@role='alert']//div[@role='contentinfo']");
  15. protected String summaryCellLocator = "//div[contains(text(),'%s')]";
  16. protected String tableElementNameLocator = "//tbody//a[contains(text(),'%s')]";
  17. protected String columnHeaderLocator = "//table//tr/th/div[text()='%s']";
  18. protected void waitUntilSpinnerDisappear() {
  19. log.debug("\nwaitUntilSpinnerDisappear");
  20. loadingSpinner.shouldBe(Condition.disappear);
  21. }
  22. protected void clickSubmitBtn() {
  23. clickByJavaScript(submitBtn);
  24. }
  25. protected SelenideElement getTableElement(String elementName) {
  26. log.debug("\ngetTableElement: {}", elementName);
  27. return $x(String.format(tableElementNameLocator, elementName));
  28. }
  29. protected String getAlertHeader() {
  30. log.debug("\ngetAlertHeader");
  31. String result = alertHeader.shouldBe(Condition.visible).getText();
  32. log.debug("-> {}", result);
  33. return result;
  34. }
  35. protected String getAlertMessage() {
  36. log.debug("\ngetAlertMessage");
  37. String result = alertMessage.shouldBe(Condition.visible).getText();
  38. log.debug("-> {}", result);
  39. return result;
  40. }
  41. protected boolean isAlertVisible(AlertHeader header) {
  42. log.debug("\nisAlertVisible: {}", header.toString());
  43. boolean result = getAlertHeader().equals(header.toString());
  44. log.debug("-> {}", result);
  45. return result;
  46. }
  47. protected boolean isAlertVisible(AlertHeader header, String message) {
  48. log.debug("\nisAlertVisible: {} {}", header, message);
  49. boolean result = isAlertVisible(header) && getAlertMessage().equals(message);
  50. log.debug("-> {}", result);
  51. return result;
  52. }
  53. public enum AlertHeader {
  54. SUCCESS("Success"),
  55. VALIDATION_ERROR("Validation Error"),
  56. BAD_REQUEST("400 Bad Request");
  57. private final String value;
  58. AlertHeader(String value) {
  59. this.value = value;
  60. }
  61. public String toString() {
  62. return value;
  63. }
  64. }
  65. }