diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/PaginatorTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/PaginatorTests.java index 0a67ab04ab..af95e6c2e0 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/PaginatorTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/PaginatorTests.java @@ -53,7 +53,7 @@ public void labelPaginationTest() { public void basicPaginatorTest() { waitCondition(() -> listLengthInput.isVisible()); listLengthInput.setValue(String.valueOf(LENGTH)); - paginatorConfigurable.select(STEP); + paginatorConfigurable.selectItemPerPageOption(STEP); //First page paginatorConfigurable.has().pageIndexCurrent(0) .and().has().totalNumberOfPaginatedItems(LENGTH) @@ -160,7 +160,7 @@ public void itemPerPagePaginatorTest() { listLengthInput.setValue(String.valueOf(LENGTH)); for (Integer option : PAGE_SIZE_OPTIONS) { - paginatorConfigurable.select(option); + paginatorConfigurable.selectItemPerPageOption(option); final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH); paginatorConfigurable.has().itemsPerPageSelected(option) .and().has().rangeLabel(rangeLabel); diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PaginatorAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PaginatorAssert.java index 8a171ecce5..4c49721fd8 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PaginatorAssert.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PaginatorAssert.java @@ -144,7 +144,7 @@ public PaginatorAssert nextPageButtonDisabled() { @JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true) public PaginatorAssert itemPerPageSelectorDisabled() { - jdiAssert(element().itemPerPageSelector().isDisabled(), Matchers.is(true), + jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), Matchers.equalTo("true"), "item per page selector should be DISABLED"); return this; } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Paginator.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Paginator.java index 63489cedd1..d3b3d5a3c9 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Paginator.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Paginator.java @@ -4,13 +4,18 @@ import com.epam.jdi.light.angular.elements.common.Button; import com.epam.jdi.light.common.JDIAction; import com.epam.jdi.light.elements.base.UIBaseElement; +import com.epam.jdi.light.elements.common.UIElement; +import com.epam.jdi.light.elements.complex.WebList; +import org.openqa.selenium.By; +import org.openqa.selenium.Point; import java.util.List; +import java.util.NoSuchElementException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import static java.lang.Integer.parseInt; +import static java.util.stream.Collectors.toList; /** * To see an example of Paginator web element please visit .... @@ -27,12 +32,12 @@ public class Paginator extends UIBaseElement { private static final String BOARDER_LOCATOR = ".mdc-notched-outline__leading"; private static final String PAGINATOR_PAGE_SIZE_SECTION_LOCATOR = ".mat-mdc-paginator-page-size"; private static final String ITEM_PER_PAGE_SELECTOR_LOCATOR = "mat-select"; - private final PaginatorSelector itemPerPageSelector; - private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); + private static final String SELECT_PANEL_LOCATOR = "div.mat-mdc-select-panel"; + private static final String ITEM_PER_PAGE_OPTIONS_LOCATOR = "mat-option"; + private static final String ARIA_EXPANDED_ATTR = "aria-expanded"; + private static final String COLOR_ATT = "color"; - public Paginator() { - itemPerPageSelector = new PaginatorSelector().setCore(PaginatorSelector.class, core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR)); - } + private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); @JDIAction("Set pattern for '{name}' range label") public void setRangeLabelPattern(String regex) { @@ -87,23 +92,48 @@ public Button lastPageButton() { } @JDIAction("Get item per page selector for '{name}'") - public PaginatorSelector itemPerPageSelector() { - return itemPerPageSelector; + public UIElement itemPerPageSelector() { + return core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR); + } + + @JDIAction("Get WebList of items per page options for '{name}'") + private WebList itemsPerPageOptionsWebList() { + return new WebList(By.cssSelector(ITEM_PER_PAGE_OPTIONS_LOCATOR)); } @JDIAction("Get options for '{name}'") public List options() { - return itemPerPageSelector.values().stream().map(Integer::parseInt).collect(Collectors.toList()); + expandItemPerPageOptions(); + final List collect = itemsPerPageOptionsWebList().values().stream().map(Integer::parseInt).collect(toList()); + collapseItemPerPageOptions(); + return collect; + } + + @JDIAction("Expand options for '{name}'") + private void expandItemPerPageOptions() { + if (itemPerPageSelector().attr(ARIA_EXPANDED_ATTR).equals("false")) { + itemPerPageSelector().click(); + } + } + + @JDIAction("Collapse items per page options for '{name}'") + private void collapseItemPerPageOptions() { + if (itemPerPageSelector().attr(ARIA_EXPANDED_ATTR).equals("true")) { + UIElement uiElement = new UIElement(By.cssSelector(SELECT_PANEL_LOCATOR)); + Point pointOutsidePanel = new Point(uiElement.core().getRect().getWidth() + 2, uiElement.core().getRect().getHeight() + 2); + uiElement.core().click(pointOutsidePanel.getX(), pointOutsidePanel.getY()); + } } - @JDIAction("Select option for '{name}'") - public void select(int number) { - itemPerPageSelector.select(String.valueOf(number)); + @JDIAction("Select items per page option '{0}' for '{name}'") + public void selectItemPerPageOption(int number) { + expandItemPerPageOptions(); + itemsPerPageOptionsWebList().select(String.valueOf(number)); } @JDIAction("Get selected option for '{name}'") public int selected() { - return parseInt(itemPerPageSelector.toggleValue()); + return parseInt(itemPerPageSelector().getText()); } @JDIAction("Get range for '{name}'") @@ -123,26 +153,37 @@ public void nextPage() { @JDIAction("Get color theme for '{name}'") public String colorTheme() { - final String colorAtt = "color"; - return core().hasAttribute(colorAtt) ? core().attr(colorAtt) : "primary"; + return core().hasAttribute(COLOR_ATT) ? core().attr(COLOR_ATT) : "primary"; } @JDIAction("Get color of selector`s boarder for '{name}'") public String boarderColor() { - itemPerPageSelector.expand(); + expandItemPerPageOptions(); final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color"); - itemPerPageSelector.collapse(); + collapseItemPerPageOptions(); return cssValue; } + @JDIAction("Get color for selected value in the list of options for '{name}'") public String selectedOptionColor() { - itemPerPageSelector.expand(); - String cssValue = itemPerPageSelector.selectedOptionFromList().getCssValue("color"); - itemPerPageSelector.collapse(); + expandItemPerPageOptions(); + String cssValue = selectedOptionFromItemsPerPageList().find("span").getCssValue(COLOR_ATT); + collapseItemPerPageOptions(); return cssValue; } + @JDIAction("Get selected option from items per page list for '{name}'") + private UIElement selectedOptionFromItemsPerPageList() { + return itemsPerPageOptionsWebList().stream() + .filter(el -> el + .attr("aria-selected").equals("true")) + .findFirst() + .orElseThrow( + () -> new NoSuchElementException("No element with attribute aria-selected = true") + ); + } + @JDIAction("Get '{name}' firstPageLabel") public String lastPageLabel() { return core().attr("lastPageLabel"); diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java deleted file mode 100644 index 4fecc17df9..0000000000 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.epam.jdi.light.angular.elements.complex; - -import com.epam.jdi.light.common.JDIAction; -import com.epam.jdi.light.elements.common.UIElement; -import org.openqa.selenium.By; - -import java.util.NoSuchElementException; - -public class PaginatorSelector extends MaterialSelector { - - public PaginatorSelector() { - super(); - cdkOverlayContainer.backdropSelectPanel = "div.mat-mdc-select-panel"; - } - - @Override - @JDIAction("Get 'name' toggle") - protected UIElement toggle() { - return this.core(); - } - - @JDIAction("Get '{name}' toggle value") - public String toggleValue() { - return toggle().getText(); - } - - @Override - @JDIAction(value = "Is '{name}' expanded") - public boolean isExpanded() { - return toggle().attr("aria-expanded").equals("true"); - } - - @Override - @JDIAction(value = "Is '{name}' collapsed") - public boolean isCollapsed() { - return !isExpanded(); - } - - @JDIAction("Get '{name}' selected UIElement from the list") - public UIElement selectedOptionFromList() { - return cdkOverlayContainer.list().stream() - .filter(el -> el.find(By.xpath("..")) - .attr("aria-selected").equals("true")) - .findFirst() - .orElseThrow( - () -> new NoSuchElementException("No element with attribute aria-selected = true") - ); - } - - @Override - @JDIAction(value = "Check that '{name}' is enabled", timeout = 0) - public boolean isEnabled() { - return toggle().isEnabled() && toggle().attr("aria-disabled").equals("false"); - } - - @Override - @JDIAction(value = "Check that '{name}' is disabled", timeout = 0) - public boolean isDisabled() { - return !isEnabled(); - } - - @Override - @JDIAction("Expand '{name}'") - public void expand() { - if (isCollapsed()) { - super.expand(); - } - } -} -