From 3bfb8cd999cdcd376272a88431977b8ca32eee07 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Fri, 26 Jan 2024 21:22:22 +0400 Subject: [PATCH] #4926: Tests refactoring: Paginator element --- .../main/java/io/github/com/StaticSite.java | 4 + .../io/github/com/pages/PaginatorPage.java | 42 ++++ .../com/pages/sections/PaginatorSection.java | 17 -- .../elements/complex/PaginatorTests.java | 165 +++++++++------ .../angular/asserts/PaginatorAssert.java | 90 ++++++--- .../angular/elements/complex/Paginator.java | 189 ++++++++++++------ .../elements/complex/PaginatorSelector.java | 58 ++++++ .../angular/elements/enums/AngularColors.java | 6 +- 8 files changed, 408 insertions(+), 163 deletions(-) create mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java delete mode 100644 jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/PaginatorSection.java create mode 100644 jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java index 0c329d4132c..9227260937c 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java @@ -10,6 +10,7 @@ import io.github.com.pages.ButtonsPage; import io.github.com.pages.CheckBoxPage; import io.github.com.pages.DividerPage; +import io.github.com.pages.PaginatorPage; import io.github.com.pages.ProgressBarPage; import io.github.com.pages.ProgressSpinnerPage; import io.github.com.pages.RadioButtonPage; @@ -53,4 +54,7 @@ public class StaticSite { @Url("slide_toggle") public static SlideTogglePage slideTogglePage; + + @Url("paginator") + public static PaginatorPage paginatorPage; } 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 new file mode 100644 index 00000000000..9e6cc4169c4 --- /dev/null +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java @@ -0,0 +1,42 @@ +package io.github.com.pages; + +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.Paginator; +import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; +import com.epam.jdi.light.ui.html.elements.common.Text; + +public class PaginatorPage extends NewAngularPage { + @UI("#paginator-list-length-input") + public static Input listLengthInput; + @UI("#paginator-page-size-input") + public static Input pageSizeInput; + @UI("#paginator-page-size-options-input") + public static Input pageSizeOptionsInput; + + @UI("//paginator-configurable-example//div[contains(text(),'List length:')]") + public static Text listLength; + @UI("//paginator-configurable-example//div[contains(text(),'Page size:')]") + public static Text pageSize; + @UI("//paginator-configurable-example//div[contains(text(),'Page index:')]") + public static Text pageIndex; + + @UI(".mat-mdc-tooltip") + public static Tooltip tooltip; + + @UI("//paginator-configurable-example//mat-paginator") + public static Paginator paginatorConfigurable; + + @UI("//mat-paginator[contains(@id, 'paginator-show-first-last-buttons')]") + public static Paginator paginatorFirstLastButtons; + @UI("#paginator-color-themepalette-primary") + public static Paginator paginatorColorPrimary; + @UI("#paginator-color-themepalette-accent") + public static Paginator paginatorColorAccent; + @UI("#paginator-color-themepalette-warn") + public static Paginator paginatorColorWarn; + @UI("#paginator-disabled-option") + public static Paginator paginatorDisabledOption; + @UI("#paginator-hide-page-size-option") + public static Paginator paginatorHideSizeOption; +} diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/PaginatorSection.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/PaginatorSection.java deleted file mode 100644 index 77a0f83d71b..00000000000 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/PaginatorSection.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.com.pages.sections; - -import com.epam.jdi.light.angular.elements.complex.Paginator; -import com.epam.jdi.light.elements.composite.Section; -import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; -import com.epam.jdi.light.ui.html.elements.common.TextField; - -public class PaginatorSection extends Section { - @UI("#paginator-list-length-input") - public static TextField listLength; - - @UI("#paginator-page-size-options-input") - public static TextField pageSizeOptions; - - @UI("//paginator-configurable-example/mat-paginator") - public static Paginator paginator; -} 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 ffb28ced41b..56a9c51e70f 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 @@ -1,106 +1,145 @@ package io.github.epam.angular.tests.elements.complex; import io.github.epam.TestsInit; -import org.openqa.selenium.Dimension; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; import java.util.Arrays; import java.util.List; +import java.util.Random; import java.util.stream.Collectors; -import static com.epam.jdi.light.driver.WebDriverFactory.getDriver; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.sections.PaginatorSection.*; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static com.epam.jdi.light.angular.elements.enums.AngularColors.ACCENT; +import static com.epam.jdi.light.angular.elements.enums.AngularColors.PRIMARY; +import static com.epam.jdi.light.angular.elements.enums.AngularColors.WARN; +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.paginatorPage; +import static io.github.com.pages.PaginatorPage.listLengthInput; +import static io.github.com.pages.PaginatorPage.pageSizeOptionsInput; +import static io.github.com.pages.PaginatorPage.paginatorColorAccent; +import static io.github.com.pages.PaginatorPage.paginatorColorPrimary; +import static io.github.com.pages.PaginatorPage.paginatorColorWarn; +import static io.github.com.pages.PaginatorPage.paginatorConfigurable; +import static io.github.com.pages.PaginatorPage.paginatorDisabledOption; +import static io.github.com.pages.PaginatorPage.paginatorFirstLastButtons; +import static io.github.com.pages.PaginatorPage.paginatorHideSizeOption; +import static java.lang.String.format; -// TODO Move to the new page -@Ignore public class PaginatorTests extends TestsInit { - private static final List PAGESIZEOPTIONS = Arrays.asList(1, 5, 10, 25, 100, 500); + private static final List PAGE_SIZE_OPTIONS = Arrays.asList(1, 5, 10, 25, 100, 500); private static final String OPTIONS = - PAGESIZEOPTIONS + PAGE_SIZE_OPTIONS .stream() .map(String::valueOf) .collect(Collectors.joining(",")); - private static final int TOTAL = 50; + private static final int STEP = 100; + private static final int PAGE_SIZE = 10; + private static final int LENGTH = STEP * PAGE_SIZE - new Random().nextInt(STEP); + private static final String RANGE_PATTERN = "%d - %d / %d"; @BeforeMethod public void before() { - getDriver().manage().window().setSize(new Dimension(1920, 1080)); - - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); - - listLength.setValue(String.valueOf(TOTAL)); - pageSizeOptions.setValue(OPTIONS); + paginatorPage.open(); + waitCondition(() -> paginatorPage.isOpened()); + paginatorPage.checkOpened(); } - @Test + @Test(description = "The test checks item per page label") public void labelPaginationTest() { - paginator.has().label("Items per page:"); + paginatorConfigurable.has().itemPerPageLabel("Items per page:"); } - @Test + @Test(description = "The test checks length and pageIndex for paginator") public void basicPaginatorTest() { - final int STEP = 10; - paginator.select(STEP); - - paginator.is().range(1, STEP, TOTAL); - paginator.is().previousDisabled(); - paginator.is().nextEnabled(); - paginator.next(); - - for (int i = STEP + 1; i < TOTAL - STEP + 1; i += STEP) { - paginator.is().range(i, i + STEP - 1, TOTAL); - paginator.is().previousEnabled(); - paginator.is().nextEnabled(); - paginator.next(); + waitCondition(() -> listLengthInput.isVisible()); + listLengthInput.setValue(String.valueOf(LENGTH)); + paginatorConfigurable.select(STEP); + + //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)); + paginatorConfigurable.nextPage(); } - paginator.is().range(TOTAL - STEP + 1, TOTAL, TOTAL); - paginator.is().previousEnabled(); - paginator.is().nextDisabled(); - paginator.previous(); - - for (int i = TOTAL - 2 * STEP + 1; i > 1; i -= STEP) { - paginator.is().range(i, i + STEP - 1, TOTAL); - paginator.is().previousEnabled(); - paginator.is().nextEnabled(); - paginator.previous(); + //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)); + paginatorConfigurable.previousPage(); } + paginatorConfigurable.has().pageIndex(0) + .and().has().length(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.lastPageButton().click(); + paginatorFirstLastButtons.firstPageButton().is().enabled(); + paginatorFirstLastButtons.lastPageButton().is().disabled(); - paginator.is().range(1, STEP, TOTAL); - paginator.is().previousDisabled(); - paginator.is().nextEnabled(); + paginatorConfigurable.has().showFirstLastButtons(false); } - @Test + @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); + + paginatorColorWarn.has().color(WARN); + paginatorColorWarn.has().colorOfBoarder(WARN); + paginatorColorWarn.has().colorOfSelectedOption(WARN); + + paginatorColorAccent.has().color(ACCENT); + paginatorColorAccent.has().colorOfBoarder(ACCENT); + paginatorColorAccent.has().colorOfSelectedOption(ACCENT); + } + + @Test(description = "The test checks disabled paginator and disabled elements of the paginators") public void navigationDisabledPaginatorTest() { - listLength.setValue("0"); + paginatorDisabledOption.is().disabled(); - paginator.has().range(); - paginator.has().previousDisabled(); - paginator.has().nextDisabled(); + paginatorDisabledOption.previousButton().is().disabled(); + paginatorDisabledOption.nextButton().is().disabled(); + paginatorDisabledOption.itemPerPageSelector().is().disabled(); - listLength.setValue("100"); - paginator.select(100); - paginator.has().previousDisabled(); - paginator.has().nextDisabled(); + paginatorHideSizeOption.is().enabled(); + paginatorColorWarn.is().enabled(); } - @Test + @Test(description = "The test checks Item per page selector is hidden/visible") + public void hidePageSizePaginatorTest() { + paginatorHideSizeOption.has().hiddenPageSize(true); + } + + @Test(description = "The test checks page size dropdown options") public void pageSizeOptionsPaginatorTest() { - paginator.has().itemsPerPageList(PAGESIZEOPTIONS); + pageSizeOptionsInput.setValue(OPTIONS); + listLengthInput.focus(); + paginatorConfigurable.has().itemsPerPageList(PAGE_SIZE_OPTIONS); } - @Test + @Test(description = "The test checks range label for page size dropdown options") public void itemPerPagePaginatorTest() { - for (Integer option : PAGESIZEOPTIONS) { - paginator.select(option); - paginator.has().itemsPerPageSelected(option); - paginator.has().range(1, Math.min(option, TOTAL), TOTAL); + pageSizeOptionsInput.setValue(OPTIONS); + listLengthInput.setValue(String.valueOf(LENGTH)); + + for (Integer option : PAGE_SIZE_OPTIONS) { + paginatorConfigurable.select(option); + paginatorConfigurable.has().itemsPerPageSelected(option) + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH)); } } } 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 a5b7062a30f..a54beb561c1 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 @@ -1,6 +1,7 @@ package com.epam.jdi.light.angular.asserts; import com.epam.jdi.light.angular.elements.complex.Paginator; +import com.epam.jdi.light.angular.elements.enums.AngularColors; import com.epam.jdi.light.asserts.generic.UIAssert; import com.epam.jdi.light.common.JDIAction; import org.hamcrest.Matchers; @@ -12,48 +13,91 @@ public class PaginatorAssert extends UIAssert { @JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true) - public void label(String label) { - jdiAssert(element().label(), Matchers.is(label)); + public PaginatorAssert itemPerPageLabel(String label) { + jdiAssert(element().itemPerPageLabel(), Matchers.is(label)); + return this; } @JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true) - public void itemsPerPageSelected(final int number) { + public PaginatorAssert itemsPerPageSelected(final int number) { jdiAssert(element().selected(), Matchers.is(number)); + return this; } @JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true) - public void itemsPerPageList(final List options) { + public PaginatorAssert itemsPerPageList(final List options) { jdiAssert(element().options(), Matchers.is(options)); - } + return this; - @JDIAction(value = "Assert that range is '0' of '0' for '{name}'", isAssert = true) - public void range() { - jdiAssert(element().range(), Matchers.is("0 of 0")); } - @JDIAction(value = "Assert that range is '{0}' – '{1}' of '{2}' for '{name}'", isAssert = true) - public void range(final int from, final int to, final int total) { - String expected = format("%d – %d of %d", from, to, total); + @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)); + return this; + } + + @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) + public PaginatorAssert color(AngularColors value) { + jdiAssert(element().color(), Matchers.equalTo(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()); + jdiAssert(actualColor, 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()); + jdiAssert(actualColorInList, 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)); + return this; } - @JDIAction(value = "Assert that previous button enabled for '{name}'", isAssert = true) - public void previousEnabled() { - jdiAssert(element().isPreviousEnabled(), Matchers.is(true), "ERROR MESSAGE IS REQUIRED"); + @JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true) + public PaginatorAssert lastPageLabel(String label) { + jdiAssert(element().lastPageLabel(), Matchers.is(label)); + return this; } - @JDIAction(value = "Assert that previous button disabled for '{name}'", isAssert = true) - public void previousDisabled() { - jdiAssert(element().isPreviousEnabled(), Matchers.is(false), "ERROR MESSAGE IS REQUIRED"); + @JDIAction(value = "Assert that '{name}' has hidden page size", isAssert = true) + public PaginatorAssert hiddenPageSize(final boolean value) { + jdiAssert(element().hidePageSize(), Matchers.is(value), + value ? "page size should be hidden" : "page size should be visible"); + return this; } - @JDIAction(value = "Assert that next button enabled for '{name}'", isAssert = true) - public void nextEnabled() { - jdiAssert(element().isNextEnabled(), Matchers.is(true), "ERROR MESSAGE IS REQUIRED"); + @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), + value ? "first and last buttons should be shown" : "first and last buttons should be hidden" + ); + return this; } - @JDIAction(value = "Assert that next button disabled for '{name}'", isAssert = true) - public void nextDisabled() { - jdiAssert(element().isNextEnabled(), Matchers.is(false), "ERROR MESSAGE IS REQUIRED"); + /** + * @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)); + 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)); + 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 0f46592be4a..eb40e003db5 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 @@ -1,109 +1,180 @@ package com.epam.jdi.light.angular.elements.complex; import com.epam.jdi.light.angular.asserts.PaginatorAssert; -import com.epam.jdi.light.angular.elements.composite.MaterialSelectorContainer; +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; -import com.epam.jdi.light.elements.common.UIElement; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** - * To see an example of Paginator web element please visit https://material.angular.io/components/paginator/overview. + * To see an example of Paginator web element please visit .... */ public class Paginator extends UIBaseElement { + 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"; + private static final String FIRST_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-first"; + private static final String LAST_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-last"; + private static final String PREVIOUS_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-previous"; + private static final String NEXT_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-next"; + 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 static final Pattern PATTERN = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); - protected UIElement label; - protected String labelLocator = ".mat-paginator-page-size-label"; - - protected UIElement select; - protected String selectLocator = ".mat-select"; + public Paginator() { + itemPerPageSelector = new PaginatorSelector().setCore(PaginatorSelector.class, core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR)); + } - protected MaterialSelectorContainer container; + @Override + public PaginatorAssert is() { + return new PaginatorAssert().set(this); + } - protected UIElement range; - protected String rangeLocator = ".mat-paginator-range-label"; + @Override + public PaginatorAssert has() { + return is(); + } - protected UIElement previous; - protected String previousLocator = ".mat-paginator-navigation-previous"; + @JDIAction("Get label for '{name}'") + public String itemPerPageLabel() { + return core().find(ITEM_PER_PAGE_LABEL_LOCATOR).getText(); + } - protected UIElement next; - protected String nextLocator = ".mat-paginator-navigation-next"; + @Override + @JDIAction("Get if '{name}' is disabled") + public boolean isDisabled() { + return hasAttribute("disabled"); + } - public Paginator() { - label = new UIElement(); - label.setLocator(labelLocator); + @Override + @JDIAction("Get if '{name}' is enabled") + public boolean isEnabled() { + return !isDisabled(); + } - select = new UIElement(); - select.setLocator(selectLocator); + @JDIAction("Get previous page button for '{name}'") + public Button previousButton() { + return new Button().setCore(Button.class, core().find(PREVIOUS_PAGE_BUTTON_LOCATOR)); + } - container = new MaterialSelectorContainer(); + @JDIAction("Get next page button for '{name}'") + public Button nextButton() { + return new Button().setCore(Button.class, core().find(NEXT_PAGE_BUTTON_LOCATOR)); + } - range = new UIElement(); - range.setLocator(rangeLocator); + @JDIAction("Get first page button for '{name}'") + public Button firstPageButton() { + return new Button().setCore(Button.class, core().find(FIRST_PAGE_BUTTON_LOCATOR)); + } - previous = new UIElement(); - previous.setLocator(previousLocator); + @JDIAction("Get last page button for '{name}'") + public Button lastPageButton() { + return new Button().setCore(Button.class, core().find(LAST_PAGE_BUTTON_LOCATOR)); + } - next = new UIElement(); - next.setLocator(nextLocator); + @JDIAction("Get item per page selector for '{name}'") + public PaginatorSelector itemPerPageSelector() { + return itemPerPageSelector; } - @JDIAction("Get label for '{name}'") - public String label() { - return label.getText(); + @JDIAction("Get options for '{name}'") + public List options() { + return itemPerPageSelector.values().stream().map(Integer::parseInt).collect(Collectors.toList()); } @JDIAction("Select option for '{name}'") public void select(int number) { - select.click(); - container.select(String.valueOf(number)); + itemPerPageSelector.select(String.valueOf(number)); } @JDIAction("Get selected option for '{name}'") public int selected() { - return Integer.parseInt(select.getText()); - } - - @JDIAction("Get options for '{name}'") - public List options() { - select.click(); - return container - .values() - .stream() - .map(Integer::parseInt) - .collect(Collectors.toList()); + return Integer.parseInt(itemPerPageSelector.value()); } @JDIAction("Get range for '{name}'") public String range() { - return range.getText(); + return core().find(RANGE_LABEL_LOCATOR).getText(); } - @JDIAction("Is previous button enabled for '{name}'") - public boolean isPreviousEnabled() { - return previous.isEnabled(); + @JDIAction("Click previous for '{name}'") + public void previousPage() { + previousButton().click(); } - @JDIAction("Click previous for '{name}'") - public void previous() { - previous.click(); + @JDIAction("Click next for '{name}'") + public void nextPage() { + nextButton().click(); } - @JDIAction("Is next button enabled for '{name}'") - public boolean isNextEnabled() { - return next.isEnabled(); + @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("Click next for '{name}'") - public void next() { - next.click(); + @JDIAction("Get COLOR of selector`s boarder for '{name}'") + public String colorOfBoarder() { + itemPerPageSelector.expand(); + final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color"); + itemPerPageSelector.collapse(); + return cssValue; } - @Override - public PaginatorAssert is() { - return new PaginatorAssert().set(this); + @JDIAction("Get COLOR for selected value in the list of options for '{name}'") + public String colorInList() { + itemPerPageSelector.expand(); + String cssValue = itemPerPageSelector.selectedElement().getCssValue("color"); + itemPerPageSelector.collapse(); + return cssValue; + } + + @JDIAction("Get '{name}' firstPageLabel") + public String lastPageLabel() { + return core().attr("lastPageLabel"); + } + + @JDIAction("Get '{name}' firstPageLabel") + public String firstPageLabel() { + return core().attr("firstPageLabel"); + } + + @JDIAction("Get if '{name}' page size selector is hidden") + public boolean hidePageSize() { + 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; + } + + @JDIAction("Get '{name}' page index") + public int length() { + return Integer.parseInt(getMatcherForRange().group(4)); + } + + @JDIAction("Parse '{name}' range with pattern {PATTERN}") + private Matcher getMatcherForRange() { + Matcher matcher = PATTERN.matcher(range()); + if (!matcher.matches()) { + throw new IllegalStateException( + String.format("Pattern '%s' has no matches for string '%s'", PATTERN.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 new file mode 100644 index 00000000000..cca015182c5 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java @@ -0,0 +1,58 @@ +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; + +import static com.epam.jdi.light.logger.LogLevels.DEBUG; + +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}' selected value from selector") + public String value() { + return toggle().getText(); + } + + @Override + @JDIAction(value = "Is '{name}' expanded", level = DEBUG, timeout = 0) + public boolean isExpanded() { + return this.attr("aria-expanded").equals("true"); + } + + @JDIAction("Get '{name}' selected UIElement from the list") + public UIElement selectedElement() { + 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(); + } +} + diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/AngularColors.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/AngularColors.java index 1f8af4edd8c..98fe8f80091 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/AngularColors.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/AngularColors.java @@ -35,8 +35,12 @@ public static AngularColors fromStyle(String styleName) { } public static AngularColors fromColor(String color) { + final String finalColor = color.startsWith("rgb(") ? + color.replace("rgb(", "rgba(").replace(")", ", 1)") : + color; + return Arrays.stream(AngularColors.values()) - .filter(c -> c.color.equalsIgnoreCase(color)) + .filter(c -> c.color.equalsIgnoreCase(finalColor)) .findFirst() .orElse(AngularColors.UNDEFINED); }