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 56a9c51e70..f28d14916b 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 @@ -57,63 +57,65 @@ public void basicPaginatorTest() { //Go through each page sequentially: for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) { - paginatorConfigurable.has().pageIndex(pageIndex) - .and().has().length(LENGTH) - .and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH)); + final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH); + + paginatorConfigurable.has().pageIndexCurrent(pageIndex) + .and().has().totalNumberOfItems(LENGTH) + .and().has().rangeLabel(rangeLabel); paginatorConfigurable.nextPage(); } //Go through each page backwards for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) { - paginatorConfigurable.has().pageIndex(pageIndex) - .and().has().length(LENGTH) - .and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH)); + final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH); + + paginatorConfigurable.has().pageIndexCurrent(pageIndex) + .and().has().totalNumberOfItems(LENGTH) + .and().has().rangeLabel(rangeLabel); paginatorConfigurable.previousPage(); } - paginatorConfigurable.has().pageIndex(0) - .and().has().length(LENGTH) + paginatorConfigurable.has().pageIndexCurrent(0) + .and().has().totalNumberOfItems(LENGTH) .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)); } @Test(description = "The test checks first page and last page buttons labels for paginator") public void firstAndLastPageButtonPaginatorTest() { - paginatorFirstLastButtons.has().showFirstLastButtons(true); - paginatorFirstLastButtons.has().firstPageLabel("test firstPageLabel"); - paginatorFirstLastButtons.has().lastPageLabel("test lastPageLabel"); - - paginatorFirstLastButtons.firstPageButton().is().disabled(); - paginatorFirstLastButtons.lastPageButton().is().enabled(); + paginatorFirstLastButtons.has().firstLastButtonsShown(true) + .and().has().firstPageLabel("test firstPageLabel") + .and().has().lastPageLabel("test lastPageLabel") + .and().has().firstPageDisplayed(true) + .and().has().lastPageDisplayed(true); - paginatorFirstLastButtons.lastPageButton().click(); - paginatorFirstLastButtons.firstPageButton().is().enabled(); - paginatorFirstLastButtons.lastPageButton().is().disabled(); - - paginatorConfigurable.has().showFirstLastButtons(false); + paginatorConfigurable.has().firstLastButtonsShown(false); } @Test(description = "The test checks color theme of the paginators") public void colorPaginatorTest() { - paginatorColorPrimary.has().color(PRIMARY); - paginatorColorPrimary.has().colorOfBoarder(PRIMARY); - paginatorColorPrimary.has().colorOfSelectedOption(PRIMARY); + paginatorColorPrimary.has().colorTheme(PRIMARY) + .and().has().borderColor(PRIMARY) + .and().has().selectedOptionColor(PRIMARY); + + paginatorColorPrimary.has().colorTheme("primary") + .and().has().borderColor("rgb(103, 58, 183)") + .and().has().selectedOptionColor("rgba(103, 58, 183, 1)"); - paginatorColorWarn.has().color(WARN); - paginatorColorWarn.has().colorOfBoarder(WARN); - paginatorColorWarn.has().colorOfSelectedOption(WARN); + paginatorColorWarn.has().colorTheme(WARN) + .and().has().borderColor(WARN) + .and().has().selectedOptionColor(WARN); - paginatorColorAccent.has().color(ACCENT); - paginatorColorAccent.has().colorOfBoarder(ACCENT); - paginatorColorAccent.has().colorOfSelectedOption(ACCENT); + paginatorColorAccent.has().colorTheme(ACCENT) + .and().has().borderColor(ACCENT) + .and().has().selectedOptionColor(ACCENT); } @Test(description = "The test checks disabled paginator and disabled elements of the paginators") public void navigationDisabledPaginatorTest() { - paginatorDisabledOption.is().disabled(); - - paginatorDisabledOption.previousButton().is().disabled(); - paginatorDisabledOption.nextButton().is().disabled(); - paginatorDisabledOption.itemPerPageSelector().is().disabled(); + paginatorDisabledOption.is().disabled() + .and().has().previousDisabled() + .and().has().nextDisabled() + .and().has().itemPerPageSelectorDisabled(); paginatorHideSizeOption.is().enabled(); paginatorColorWarn.is().enabled(); @@ -138,8 +140,9 @@ public void itemPerPagePaginatorTest() { for (Integer option : PAGE_SIZE_OPTIONS) { paginatorConfigurable.select(option); + final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH); paginatorConfigurable.has().itemsPerPageSelected(option) - .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH)); + .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 a54beb561c..99f28398e3 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 @@ -9,77 +9,94 @@ import java.util.List; import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; -import static com.jdiai.tools.StringUtils.format; public class PaginatorAssert extends UIAssert { @JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true) - public PaginatorAssert itemPerPageLabel(String label) { - jdiAssert(element().itemPerPageLabel(), Matchers.is(label)); + public PaginatorAssert itemPerPageLabel(final String label) { + jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label)); return this; } @JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true) public PaginatorAssert itemsPerPageSelected(final int number) { - jdiAssert(element().selected(), Matchers.is(number)); + jdiAssert(element().selected(), Matchers.equalTo(number)); return this; } @JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true) public PaginatorAssert itemsPerPageList(final List options) { - jdiAssert(element().options(), Matchers.is(options)); + jdiAssert(element().options(), Matchers.equalTo(options)); return this; } @JDIAction(value = "Assert that range is '{0}' for '{name}'", isAssert = true) - public PaginatorAssert rangeLabel(String label) { - String expected = format(label); - jdiAssert(element().range(), Matchers.is(expected)); + public PaginatorAssert rangeLabel(final String label) { + jdiAssert(element().range(), Matchers.equalTo(label)); return this; } @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) - public PaginatorAssert color(AngularColors value) { - jdiAssert(element().color(), Matchers.equalTo(value)); + public PaginatorAssert colorTheme(final AngularColors value) { + final AngularColors color = AngularColors.fromName(element().colorTheme()); + jdiAssert(color, Matchers.equalTo(value)); + return this; + } + + @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) + public PaginatorAssert colorTheme(final String value) { + jdiAssert(element().colorTheme(), Matchers.equalToIgnoringCase(value)); return this; } @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true) - public PaginatorAssert colorOfBoarder(AngularColors value) { - AngularColors actualColor = AngularColors.fromColor(element().colorOfBoarder()); + public PaginatorAssert borderColor(final AngularColors value) { + AngularColors actualColor = AngularColors.fromColor(element().boarderColor()); jdiAssert(actualColor, Matchers.equalTo(value)); return this; } + @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true) + public PaginatorAssert borderColor(final String value) { + jdiAssert(element().boarderColor(), Matchers.equalTo(value)); + return this; + } + @JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true) - public PaginatorAssert colorOfSelectedOption(AngularColors value) { - AngularColors actualColorInList = AngularColors.fromColor(element().colorInList()); + public PaginatorAssert selectedOptionColor(final AngularColors value) { + AngularColors actualColorInList = AngularColors.fromColor(element().selectedOptionColor()); jdiAssert(actualColorInList, Matchers.equalTo(value)); return this; } + @JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true) + public PaginatorAssert selectedOptionColor(final String value) { + jdiAssert(element().selectedOptionColor(), Matchers.equalTo(value)); + return this; + } + @JDIAction(value = "Assert that '{name} has firstPageLabel='{0}'", isAssert = true) - public PaginatorAssert firstPageLabel(String label) { - jdiAssert(element().firstPageLabel(), Matchers.is(label)); + public PaginatorAssert firstPageLabel(final String label) { + jdiAssert(element().firstPageLabel(), Matchers.equalTo(label)); return this; } @JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true) - public PaginatorAssert lastPageLabel(String label) { - jdiAssert(element().lastPageLabel(), Matchers.is(label)); + public PaginatorAssert lastPageLabel(final String label) { + jdiAssert(element().lastPageLabel(), Matchers.equalTo(label)); return this; } @JDIAction(value = "Assert that '{name}' has hidden page size", isAssert = true) - public PaginatorAssert hiddenPageSize(final boolean value) { - jdiAssert(element().hidePageSize(), Matchers.is(value), + public PaginatorAssert hiddenPageSize(boolean value) { + jdiAssert(element().isPageSizeHidden(), Matchers.is(value), value ? "page size should be hidden" : "page size should be visible"); return this; } @JDIAction(value = "Assert that '{name}' has shown first and last page buttons", isAssert = true) - public PaginatorAssert showFirstLastButtons(boolean value) { - jdiAssert(element().showFirstLastButtons(), Matchers.is(value), + public PaginatorAssert firstLastButtonsShown(boolean value) { + jdiAssert(element().isFirstLastButtonsShown(), Matchers.is(value), value ? "first and last buttons should be shown" : "first and last buttons should be hidden" ); return this; @@ -88,15 +105,57 @@ public PaginatorAssert showFirstLastButtons(boolean value) { /** * @param pageIndex starts from 0 */ - @JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true) - public PaginatorAssert pageIndex(int pageIndex) { - jdiAssert(element().pageIndex(), Matchers.is(pageIndex)); + @JDIAction(value = "Assert that '{name}' has current page index of {0}", isAssert = true) + public PaginatorAssert pageIndexCurrent(int pageIndex) { + jdiAssert(element().pageIndexCurrent(), Matchers.equalTo(pageIndex)); return this; } @JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true) - public PaginatorAssert length(int length) { - jdiAssert(element().length(), Matchers.is(length)); + public PaginatorAssert totalNumberOfItems(int length) { + jdiAssert(element().totalNumberOfItems(), Matchers.equalTo(length)); + return this; + } + + @JDIAction(value = "Assert that previous button enabled for '{name}'", isAssert = true) + public PaginatorAssert previousEnabled() { + jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled")); + return this; + } + + @JDIAction(value = "Assert that previous button disabled for '{name}'", isAssert = true) + public PaginatorAssert previousDisabled() { + jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled")); + return this; + } + + @JDIAction(value = "Assert that next button enabled for '{name}'", isAssert = true) + public PaginatorAssert nextEnabled() { + jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled")); + return this; + } + + @JDIAction(value = "Assert that next button disabled for '{name}'", isAssert = true) + public PaginatorAssert nextDisabled() { + jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled")); + return this; + } + + @JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true) + public PaginatorAssert itemPerPageSelectorDisabled() { + jdiAssert(element().itemPerPageSelector().isDisabled() ? "disabled" : "enabled", Matchers.equalTo("disabled")); + return this; + } + + @JDIAction(value = "Assert that first page button displayed={0} for '{name}'", isAssert = true) + public PaginatorAssert firstPageDisplayed(boolean value) { + jdiAssert(element().firstPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden")); + return this; + } + + @JDIAction(value = "Assert that last page button displayed={0} for '{name}'", isAssert = true) + public PaginatorAssert lastPageDisplayed(boolean value) { + jdiAssert(element().lastPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden")); 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 d0d97120c3..5a00e7129d 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 @@ -2,7 +2,6 @@ import com.epam.jdi.light.angular.asserts.PaginatorAssert; import com.epam.jdi.light.angular.elements.common.Button; -import com.epam.jdi.light.angular.elements.enums.AngularColors; import com.epam.jdi.light.common.JDIAction; import com.epam.jdi.light.elements.base.UIBaseElement; @@ -11,6 +10,8 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import static java.lang.Integer.parseInt; + /** * To see an example of Paginator web element please visit .... */ @@ -27,12 +28,17 @@ public class Paginator extends UIBaseElement { 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 static final Pattern PATTERN = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); + private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); public Paginator() { itemPerPageSelector = new PaginatorSelector().setCore(PaginatorSelector.class, core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR)); } + @JDIAction("Set pattern for '{name}' range label") + public void setRangeLabelPattern(String regex) { + rangeLabelPattern = Pattern.compile(regex); + } + @Override public PaginatorAssert is() { return new PaginatorAssert().set(this); @@ -97,7 +103,7 @@ public void select(int number) { @JDIAction("Get selected option for '{name}'") public int selected() { - return Integer.parseInt(itemPerPageSelector.value()); + return parseInt(itemPerPageSelector.toggleValue()); } @JDIAction("Get range for '{name}'") @@ -115,24 +121,24 @@ public void nextPage() { nextButton().click(); } - @JDIAction("Get COLOR theme for '{name}'") - public AngularColors color() { - final AngularColors color = AngularColors.fromName(core().attr("color")); - return color.equals(AngularColors.UNDEFINED) ? AngularColors.PRIMARY : color; + @JDIAction("Get color theme for '{name}'") + public String colorTheme() { + final String colorAtt = "color"; + return core().hasAttribute(colorAtt) ? core().attr(colorAtt) : "primary"; } - @JDIAction("Get COLOR of selector`s boarder for '{name}'") - public String colorOfBoarder() { + @JDIAction("Get color of selector`s boarder for '{name}'") + public String boarderColor() { itemPerPageSelector.expand(); final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color"); itemPerPageSelector.collapse(); return cssValue; } - @JDIAction("Get COLOR for selected value in the list of options for '{name}'") - public String colorInList() { + @JDIAction("Get color for selected value in the list of options for '{name}'") + public String selectedOptionColor() { itemPerPageSelector.expand(); - String cssValue = itemPerPageSelector.selectedElement().getCssValue("color"); + String cssValue = itemPerPageSelector.selectedOptionFromList().getCssValue("color"); itemPerPageSelector.collapse(); return cssValue; } @@ -148,33 +154,35 @@ public String firstPageLabel() { } @JDIAction("Get if '{name}' page size selector is hidden") - public boolean hidePageSize() { + public boolean isPageSizeHidden() { return core().find(PAGINATOR_PAGE_SIZE_SECTION_LOCATOR).isHidden(); } - @JDIAction("Get '{name}' page index") - public int pageIndex() { - final int first = Integer.parseInt(getMatcherForRange().group(1)); - return first != 0 ? (first - 1) / selected() : 0; + /** + * @return The zero-based page index of the displayed list of items + */ + @JDIAction("Get '{name}' current page index") + public int pageIndexCurrent() { + final int first = parseInt(getMatcherForRange().group(1)); + return (first - 1) / selected(); } - @JDIAction("Get '{name}' page index") - public int length() { - return Integer.parseInt(getMatcherForRange().group(4)); + @JDIAction("Get '{name}' total number of items that are being paginated") + public int totalNumberOfItems() { + return parseInt(getMatcherForRange().group(4)); } - @JDIAction("Parse '{name}' range with pattern {PATTERN}") + @JDIAction("Get if '{name}' has first and last page buttons shown") + public boolean isFirstLastButtonsShown() { + return lastPageButton().isDisplayed() && firstPageButton().isDisplayed(); + } + + @JDIAction("Parse '{name}' range with pattern '{rangeLabelPattern}'") private Matcher getMatcherForRange() { - Matcher matcher = PATTERN.matcher(range()); + Matcher matcher = rangeLabelPattern.matcher(range()); if (!matcher.matches()) { - throw new IllegalStateException( - String.format("Pattern '%s' has no matches for string '%s'", PATTERN.pattern(), range())); + throw new IllegalStateException(String.format("Pattern '%s' has no matches for string '%s'", rangeLabelPattern.pattern(), range())); } return matcher; } - - @JDIAction("Get if '{name}' has first and last page buttons shown") - public boolean showFirstLastButtons() { - return lastPageButton().isDisplayed() && firstPageButton().isDisplayed(); - } } 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 index b251b44800..8194ceab72 100644 --- 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 @@ -6,8 +6,6 @@ import java.util.NoSuchElementException; -import static com.epam.jdi.light.logger.LogLevels.DEBUG; - public class PaginatorSelector extends MaterialSelector { public PaginatorSelector() { @@ -22,23 +20,24 @@ protected UIElement toggle() { } @JDIAction("Get '{name}' selected value from selector") - public String value() { + public String toggleValue() { return toggle().getText(); } @Override - @JDIAction(value = "Is '{name}' expanded", level = DEBUG, timeout = 0) + @JDIAction(value = "Is '{name}' expanded") public boolean isExpanded() { return toggle().attr("aria-expanded").equals("true"); } - @JDIAction(value = "Is '{name}' collapsed", level = DEBUG, timeout = 0) + @Override + @JDIAction(value = "Is '{name}' collapsed") public boolean isCollapsed() { return !isExpanded(); } @JDIAction("Get '{name}' selected UIElement from the list") - public UIElement selectedElement() { + public UIElement selectedOptionFromList() { return cdkOverlayContainer.list().stream() .filter(el -> el.find(By.xpath("..")) .attr("aria-selected").equals("true"))