diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java index 9e6cc4169c..f98c941b35 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java @@ -2,6 +2,7 @@ import com.epam.jdi.light.angular.elements.common.Input; import com.epam.jdi.light.angular.elements.common.Tooltip; +import com.epam.jdi.light.angular.elements.complex.JPaginator; import com.epam.jdi.light.angular.elements.complex.Paginator; import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; import com.epam.jdi.light.ui.html.elements.common.Text; @@ -15,16 +16,16 @@ public class PaginatorPage extends NewAngularPage { public static Input pageSizeOptionsInput; @UI("//paginator-configurable-example//div[contains(text(),'List length:')]") - public static Text listLength; + public static Text listLengthMessage; @UI("//paginator-configurable-example//div[contains(text(),'Page size:')]") - public static Text pageSize; + public static Text pageSizeMessage; @UI("//paginator-configurable-example//div[contains(text(),'Page index:')]") - public static Text pageIndex; + public static Text pageIndexMessage; @UI(".mat-mdc-tooltip") public static Tooltip tooltip; - @UI("//paginator-configurable-example//mat-paginator") + @JPaginator(root = "//paginator-configurable-example//mat-paginator", rangeLabel = "^(\\d+)( . (\\d+))? .+ (\\d+)") public static Paginator paginatorConfigurable; @UI("//mat-paginator[contains(@id, 'paginator-show-first-last-buttons')]") 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 122752da37..069b780fcd 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 @@ -48,6 +48,7 @@ public void before() { @Test(description = "The test checks item per page label") public void labelPaginationTest() { paginatorConfigurable.has().pageSizeLabel("Items per page:"); + paginatorConfigurable.has().pageSizeLabelMatches(".*:"); } @Test(description = "The test checks length and pageIndex for paginator") 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 6d4cd824c0..1f39c1ad09 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 @@ -18,6 +18,12 @@ public PaginatorAssert pageSizeLabel(final String label) { return this; } + @JDIAction(value = "Assert that '{name}' matches '{0}' label regEx", isAssert = true) + public PaginatorAssert pageSizeLabelMatches(final String regex) { + jdiAssert(element().itemPerPageLabel(), Matchers.matchesPattern(regex)); + 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)); @@ -26,8 +32,8 @@ public PaginatorAssert itemsPerPageSelected(final int number) { @JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true) public PaginatorAssert itemsPerPageList(final List options) { - element().ItemPerPageSelect.expand(); - jdiAssert(element().ItemPerPageSelect.list().values(), Matchers.equalTo(options)); + element().itemPerPageSelect.expand(); + jdiAssert(element().itemPerPageSelect.list().values(), Matchers.equalTo(options)); return this; } @@ -110,7 +116,7 @@ public PaginatorAssert nextPageButtonDisabled() { @JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true) public PaginatorAssert itemPerPageSelectorDisabled() { - jdiAssert(element().ItemPerPageSelect.attr("aria-disabled"), Matchers.equalTo("true"), + jdiAssert(element().itemPerPageSelect.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/JPaginator.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/JPaginator.java new file mode 100644 index 0000000000..952a65f006 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/JPaginator.java @@ -0,0 +1,15 @@ +package com.epam.jdi.light.angular.elements.complex; + +import com.epam.jdi.light.elements.pageobjects.annotations.locators.MarkupLocator; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.FIELD}) +public @interface JPaginator { + @MarkupLocator String root() default ""; + @MarkupLocator String rangeLabel() default ""; +} 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 325557c755..92610033cc 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,19 +4,23 @@ 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.complex.ISetup; import com.epam.jdi.light.elements.interfaces.base.HasColor; import com.epam.jdi.light.elements.pageobjects.annotations.locators.JDropdown; +import java.lang.reflect.Field; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.epam.jdi.light.elements.pageobjects.annotations.objects.FillFromAnnotationRules.fieldHasAnnotation; import static java.lang.Integer.parseInt; +import static org.apache.commons.lang3.StringUtils.isNotBlank; /** * To see an example of Paginator web element please visit .... */ -public class Paginator extends UIBaseElement implements HasColor { +public class Paginator extends UIBaseElement implements HasColor, ISetup { private static final String ITEM_PER_PAGE_LABEL_LOCATOR = ".mat-mdc-paginator-page-size-label"; private static final String ITEM_PER_PAGE_FIELD_LOCATOR = "mat-form-field"; private static final String RANGE_LABEL_LOCATOR = ".mat-mdc-paginator-range-label"; @@ -28,14 +32,9 @@ public class Paginator extends UIBaseElement implements HasColo private static final String BOARDER_LOCATOR = ".mdc-notched-outline__leading"; private static final String PAGINATOR_PAGE_SIZE_SECTION_LOCATOR = ".mat-mdc-paginator-page-size"; - @JDropdown(root = "mat-form-field.mat-mdc-form-field-type-mat-select", value = "mat-select", list = "//ancestor::body//mat-option") - public PaginatorSelector ItemPerPageSelect; private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); - - @JDIAction("Set pattern for '{name}' range label") - public void setRangeLabelPattern(String regex) { - rangeLabelPattern = Pattern.compile(regex); - } + @JDropdown(root = "mat-form-field.mat-mdc-form-field-type-mat-select", value = "mat-select", list = "//ancestor::body//mat-option") + public PaginatorSelector itemPerPageSelect; @Override public PaginatorAssert is() { @@ -86,12 +85,12 @@ public Button lastPageButton() { @JDIAction("Select items per page option '{0}' for '{name}'") public void selectItemPerPageOption(int number) { - ItemPerPageSelect.select(" " + number + " "); + itemPerPageSelect.select(" " + number + " "); } @JDIAction("Get selected option for '{name}'") public int selected() { - return parseInt(ItemPerPageSelect.selected()); + return parseInt(itemPerPageSelect.selected()); } @JDIAction("Get range for '{name}'") @@ -115,31 +114,12 @@ public String color() { if (core().hasAttribute("color")) { return core().attr("color"); } - ItemPerPageSelect.expand(); + itemPerPageSelect.expand(); final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color"); - ItemPerPageSelect.close(); + itemPerPageSelect.close(); return cssValue; } -// @JDIAction("Get color for selected value in the list of options for '{name}'") -// public String selectedOptionColor() { -// 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"); @@ -182,4 +162,26 @@ private Matcher getMatcherForRange() { } return matcher; } + + protected boolean setupDone = false; + + public Paginator setup(String root, String rangeLabel) { + if (isNotBlank(root)) { + base().setLocator(root); + } + if (isNotBlank(rangeLabel)) { + rangeLabelPattern = Pattern.compile(rangeLabel); + } + setupDone = true; + return this; + } + + @Override + public void setup(Field field) { + if (!fieldHasAnnotation(field, JPaginator.class, Paginator.class)) { + return; + } + JPaginator j = field.getAnnotation(JPaginator.class); + setup(j.root(), j.rangeLabel()); + } }