From ab7732da04f952fe22dab8606cf01ba45ac1c756 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Fri, 26 Jan 2024 21:22:22 +0400 Subject: [PATCH 01/12] #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 | 71 +++++++ .../angular/elements/enums/AngularColors.java | 6 +- 8 files changed, 421 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 0c329d4132..9227260937 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 0000000000..9e6cc4169c --- /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 77a0f83d71..0000000000 --- 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 ffb28ced41..56a9c51e70 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 a5b7062a30..a54beb561c 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 0f46592be4..d0d97120c3 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 core().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 0000000000..b251b44800 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java @@ -0,0 +1,71 @@ +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 toggle().attr("aria-expanded").equals("true"); + } + + @JDIAction(value = "Is '{name}' collapsed", level = DEBUG, timeout = 0) + public boolean isCollapsed() { + return !isExpanded(); + } + + @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(); + } + + @Override + @JDIAction("Expand '{name}'") + public void expand() { + if (isCollapsed()) { + super.expand(); + } + } +} + 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 1f8af4edd8..0b8015b5b6 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); } From b3370dd7a2436753cf237973a6d362bf74ea03a6 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Wed, 31 Jan 2024 15:59:20 +0400 Subject: [PATCH 02/12] #4926: Tests refactoring: Paginator element fix 1 --- .../elements/complex/PaginatorTests.java | 71 +++++------ .../angular/asserts/PaginatorAssert.java | 113 +++++++++++++----- .../angular/elements/complex/Paginator.java | 66 +++++----- .../elements/complex/PaginatorSelector.java | 11 +- 4 files changed, 165 insertions(+), 96 deletions(-) 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")) From 8b6f43fe0cdf2cb80caa7f74310eda7f646b9b95 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Fri, 2 Feb 2024 17:12:15 +0400 Subject: [PATCH 03/12] #4926: Tests refactoring: Paginator element fix 2 --- .../elements/complex/PaginatorTests.java | 51 ++++++++++++------ .../angular/asserts/PaginatorAssert.java | 52 ++++++++++--------- .../angular/elements/complex/Paginator.java | 2 +- .../elements/complex/PaginatorSelector.java | 2 +- 4 files changed, 66 insertions(+), 41 deletions(-) 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 f28d14916b..0a67ab04ab 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,7 +1,7 @@ package io.github.epam.angular.tests.elements.complex; import io.github.epam.TestsInit; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.Arrays; @@ -37,7 +37,7 @@ public class PaginatorTests extends TestsInit { private static final int LENGTH = STEP * PAGE_SIZE - new Random().nextInt(STEP); private static final String RANGE_PATTERN = "%d - %d / %d"; - @BeforeMethod + @BeforeClass public void before() { paginatorPage.open(); waitCondition(() -> paginatorPage.isOpened()); @@ -46,7 +46,7 @@ public void before() { @Test(description = "The test checks item per page label") public void labelPaginationTest() { - paginatorConfigurable.has().itemPerPageLabel("Items per page:"); + paginatorConfigurable.has().pageSizeLabel("Items per page:"); } @Test(description = "The test checks length and pageIndex for paginator") @@ -54,29 +54,50 @@ public void basicPaginatorTest() { waitCondition(() -> listLengthInput.isVisible()); listLengthInput.setValue(String.valueOf(LENGTH)); paginatorConfigurable.select(STEP); + //First page + paginatorConfigurable.has().pageIndexCurrent(0) + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)) + .and().has().nextPageButtonEnabled() + .and().has().previousPageButtonDisabled(); + paginatorConfigurable.nextPage(); //Go through each page sequentially: - for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) { + for (int pageIndex = 1; pageIndex < PAGE_SIZE - 1; pageIndex++) { 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); + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(rangeLabel) + .and().has().nextPageButtonEnabled() + .and().has().previousPageButtonEnabled(); paginatorConfigurable.nextPage(); } + //Last page + paginatorConfigurable.has().pageIndexCurrent(PAGE_SIZE - 1) + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(format(RANGE_PATTERN, (PAGE_SIZE - 1) * STEP + 1, Math.min((PAGE_SIZE - 1) * STEP + STEP, LENGTH), LENGTH)) + .and().has().previousPageButtonEnabled() + .and().has().nextPageButtonDisabled(); + paginatorConfigurable.previousPage(); //Go through each page backwards - for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) { + for (int pageIndex = PAGE_SIZE - 2; pageIndex > 0; pageIndex--) { 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); + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(rangeLabel) + .and().has().nextPageButtonEnabled() + .and().has().previousPageButtonEnabled(); paginatorConfigurable.previousPage(); } + //First page paginatorConfigurable.has().pageIndexCurrent(0) - .and().has().totalNumberOfItems(LENGTH) - .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)); + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)) + .and().has().previousPageButtonDisabled() + .and().has().nextPageButtonEnabled(); } @@ -85,8 +106,8 @@ public void firstAndLastPageButtonPaginatorTest() { paginatorFirstLastButtons.has().firstLastButtonsShown(true) .and().has().firstPageLabel("test firstPageLabel") .and().has().lastPageLabel("test lastPageLabel") - .and().has().firstPageDisplayed(true) - .and().has().lastPageDisplayed(true); + .and().has().firstPageButtonDisplayed(true) + .and().has().lastPageButtonDisplayed(true); paginatorConfigurable.has().firstLastButtonsShown(false); } @@ -113,8 +134,8 @@ public void colorPaginatorTest() { @Test(description = "The test checks disabled paginator and disabled elements of the paginators") public void navigationDisabledPaginatorTest() { paginatorDisabledOption.is().disabled() - .and().has().previousDisabled() - .and().has().nextDisabled() + .and().has().previousPageButtonDisabled() + .and().has().nextPageButtonDisabled() .and().has().itemPerPageSelectorDisabled(); paginatorHideSizeOption.is().enabled(); 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 99f28398e3..8a171ecce5 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 @@ -12,7 +12,7 @@ public class PaginatorAssert extends UIAssert { @JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true) - public PaginatorAssert itemPerPageLabel(final String label) { + public PaginatorAssert pageSizeLabel(final String label) { jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label)); return this; } @@ -38,8 +38,7 @@ public PaginatorAssert rangeLabel(final String label) { @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) public PaginatorAssert colorTheme(final AngularColors value) { - final AngularColors color = AngularColors.fromName(element().colorTheme()); - jdiAssert(color, Matchers.equalTo(value)); + jdiAssert(AngularColors.fromName(element().colorTheme()), Matchers.equalTo(value)); return this; } @@ -51,8 +50,7 @@ public PaginatorAssert colorTheme(final String value) { @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true) public PaginatorAssert borderColor(final AngularColors value) { - AngularColors actualColor = AngularColors.fromColor(element().boarderColor()); - jdiAssert(actualColor, Matchers.equalTo(value)); + jdiAssert(AngularColors.fromColor(element().boarderColor()), Matchers.equalTo(value)); return this; } @@ -64,8 +62,7 @@ public PaginatorAssert borderColor(final String value) { @JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true) public PaginatorAssert selectedOptionColor(final AngularColors value) { - AngularColors actualColorInList = AngularColors.fromColor(element().selectedOptionColor()); - jdiAssert(actualColorInList, Matchers.equalTo(value)); + jdiAssert(AngularColors.fromColor(element().selectedOptionColor()), Matchers.equalTo(value)); return this; } @@ -97,7 +94,7 @@ public PaginatorAssert hiddenPageSize(boolean value) { @JDIAction(value = "Assert that '{name}' has shown first and last page buttons", isAssert = true) 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" + value ? "first and last buttons should be SHOWN" : "first and last buttons should be DISPLAYED" ); return this; } @@ -111,51 +108,58 @@ public PaginatorAssert pageIndexCurrent(int pageIndex) { return this; } - @JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true) - public PaginatorAssert totalNumberOfItems(int length) { - jdiAssert(element().totalNumberOfItems(), Matchers.equalTo(length)); + @JDIAction(value = "Assert that '{name}' has {0} total number of items that are being paginated", isAssert = true) + public PaginatorAssert totalNumberOfPaginatedItems(int length) { + jdiAssert(element().totalNumberOfPaginatedItems(), 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")); + public PaginatorAssert previousPageButtonEnabled() { + jdiAssert(element().previousButton().isEnabled(), Matchers.is(true), + "previous button should be 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")); + public PaginatorAssert previousPageButtonDisabled() { + jdiAssert(element().previousButton().isDisabled(), Matchers.is(true), + "previous button should be 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")); + public PaginatorAssert nextPageButtonEnabled() { + jdiAssert(element().nextButton().isEnabled(), Matchers.is(true), + "next button should be 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")); + public PaginatorAssert nextPageButtonDisabled() { + jdiAssert(element().nextButton().isDisabled(), Matchers.is(true), + "previous button should be 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")); + jdiAssert(element().itemPerPageSelector().isDisabled(), Matchers.is(true), + "item per page selector should be 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")); + public PaginatorAssert firstPageButtonDisplayed(boolean value) { + jdiAssert(element().firstPageButton().isDisplayed(), Matchers.is(value), + value ? "fist page button should be DISPLAYED" : "first page button should be 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")); + public PaginatorAssert lastPageButtonDisplayed(boolean value) { + jdiAssert(element().lastPageButton().isDisplayed(), Matchers.is(value), + value ? "last page button should be DISPLAYED" : "last page button should be 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 5a00e7129d..63489cedd1 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 @@ -168,7 +168,7 @@ public int pageIndexCurrent() { } @JDIAction("Get '{name}' total number of items that are being paginated") - public int totalNumberOfItems() { + public int totalNumberOfPaginatedItems() { return parseInt(getMatcherForRange().group(4)); } 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 8194ceab72..4fecc17df9 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 @@ -19,7 +19,7 @@ protected UIElement toggle() { return this.core(); } - @JDIAction("Get '{name}' selected value from selector") + @JDIAction("Get '{name}' toggle value") public String toggleValue() { return toggle().getText(); } From 1fc5b56ee8d081f22b5b95b044f6e4e74f7e3610 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Tue, 5 Mar 2024 21:02:50 +0400 Subject: [PATCH 04/12] #4926: Tests refactoring: Paginator element fix 3 remove hierarchy --- .../elements/complex/PaginatorTests.java | 4 +- .../angular/asserts/PaginatorAssert.java | 2 +- .../angular/elements/complex/Paginator.java | 81 ++++++++++++++----- .../elements/complex/PaginatorSelector.java | 70 ---------------- 4 files changed, 64 insertions(+), 93 deletions(-) delete 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/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(); - } - } -} - From b710d69550cb0678ea82772a12b1bcd9d47b43f8 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Fri, 26 Jan 2024 21:22:22 +0400 Subject: [PATCH 05/12] #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 | 71 +++++++ 7 files changed, 416 insertions(+), 162 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 0c329d4132..9227260937 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 0000000000..9e6cc4169c --- /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 77a0f83d71..0000000000 --- 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 ffb28ced41..56a9c51e70 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 a5b7062a30..a54beb561c 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 0f46592be4..d0d97120c3 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 core().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 0000000000..b251b44800 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java @@ -0,0 +1,71 @@ +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 toggle().attr("aria-expanded").equals("true"); + } + + @JDIAction(value = "Is '{name}' collapsed", level = DEBUG, timeout = 0) + public boolean isCollapsed() { + return !isExpanded(); + } + + @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(); + } + + @Override + @JDIAction("Expand '{name}'") + public void expand() { + if (isCollapsed()) { + super.expand(); + } + } +} + From 5cf53f50f3f8495375d9dfededee76ba0a605b24 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Wed, 31 Jan 2024 15:59:20 +0400 Subject: [PATCH 06/12] #4926: Tests refactoring: Paginator element fix 1 --- .../elements/complex/PaginatorTests.java | 71 +++++------ .../angular/asserts/PaginatorAssert.java | 113 +++++++++++++----- .../angular/elements/complex/Paginator.java | 66 +++++----- .../elements/complex/PaginatorSelector.java | 11 +- 4 files changed, 165 insertions(+), 96 deletions(-) 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")) From d01c38b39bd5be6f43f6fe0bd0f954ec486c834d Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Fri, 2 Feb 2024 17:12:15 +0400 Subject: [PATCH 07/12] #4926: Tests refactoring: Paginator element fix 2 --- .../elements/complex/PaginatorTests.java | 51 ++++++++++++------ .../angular/asserts/PaginatorAssert.java | 52 ++++++++++--------- .../angular/elements/complex/Paginator.java | 2 +- .../elements/complex/PaginatorSelector.java | 2 +- 4 files changed, 66 insertions(+), 41 deletions(-) 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 f28d14916b..0a67ab04ab 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,7 +1,7 @@ package io.github.epam.angular.tests.elements.complex; import io.github.epam.TestsInit; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.Arrays; @@ -37,7 +37,7 @@ public class PaginatorTests extends TestsInit { private static final int LENGTH = STEP * PAGE_SIZE - new Random().nextInt(STEP); private static final String RANGE_PATTERN = "%d - %d / %d"; - @BeforeMethod + @BeforeClass public void before() { paginatorPage.open(); waitCondition(() -> paginatorPage.isOpened()); @@ -46,7 +46,7 @@ public void before() { @Test(description = "The test checks item per page label") public void labelPaginationTest() { - paginatorConfigurable.has().itemPerPageLabel("Items per page:"); + paginatorConfigurable.has().pageSizeLabel("Items per page:"); } @Test(description = "The test checks length and pageIndex for paginator") @@ -54,29 +54,50 @@ public void basicPaginatorTest() { waitCondition(() -> listLengthInput.isVisible()); listLengthInput.setValue(String.valueOf(LENGTH)); paginatorConfigurable.select(STEP); + //First page + paginatorConfigurable.has().pageIndexCurrent(0) + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)) + .and().has().nextPageButtonEnabled() + .and().has().previousPageButtonDisabled(); + paginatorConfigurable.nextPage(); //Go through each page sequentially: - for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) { + for (int pageIndex = 1; pageIndex < PAGE_SIZE - 1; pageIndex++) { 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); + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(rangeLabel) + .and().has().nextPageButtonEnabled() + .and().has().previousPageButtonEnabled(); paginatorConfigurable.nextPage(); } + //Last page + paginatorConfigurable.has().pageIndexCurrent(PAGE_SIZE - 1) + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(format(RANGE_PATTERN, (PAGE_SIZE - 1) * STEP + 1, Math.min((PAGE_SIZE - 1) * STEP + STEP, LENGTH), LENGTH)) + .and().has().previousPageButtonEnabled() + .and().has().nextPageButtonDisabled(); + paginatorConfigurable.previousPage(); //Go through each page backwards - for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) { + for (int pageIndex = PAGE_SIZE - 2; pageIndex > 0; pageIndex--) { 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); + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(rangeLabel) + .and().has().nextPageButtonEnabled() + .and().has().previousPageButtonEnabled(); paginatorConfigurable.previousPage(); } + //First page paginatorConfigurable.has().pageIndexCurrent(0) - .and().has().totalNumberOfItems(LENGTH) - .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)); + .and().has().totalNumberOfPaginatedItems(LENGTH) + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)) + .and().has().previousPageButtonDisabled() + .and().has().nextPageButtonEnabled(); } @@ -85,8 +106,8 @@ public void firstAndLastPageButtonPaginatorTest() { paginatorFirstLastButtons.has().firstLastButtonsShown(true) .and().has().firstPageLabel("test firstPageLabel") .and().has().lastPageLabel("test lastPageLabel") - .and().has().firstPageDisplayed(true) - .and().has().lastPageDisplayed(true); + .and().has().firstPageButtonDisplayed(true) + .and().has().lastPageButtonDisplayed(true); paginatorConfigurable.has().firstLastButtonsShown(false); } @@ -113,8 +134,8 @@ public void colorPaginatorTest() { @Test(description = "The test checks disabled paginator and disabled elements of the paginators") public void navigationDisabledPaginatorTest() { paginatorDisabledOption.is().disabled() - .and().has().previousDisabled() - .and().has().nextDisabled() + .and().has().previousPageButtonDisabled() + .and().has().nextPageButtonDisabled() .and().has().itemPerPageSelectorDisabled(); paginatorHideSizeOption.is().enabled(); 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 99f28398e3..8a171ecce5 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 @@ -12,7 +12,7 @@ public class PaginatorAssert extends UIAssert { @JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true) - public PaginatorAssert itemPerPageLabel(final String label) { + public PaginatorAssert pageSizeLabel(final String label) { jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label)); return this; } @@ -38,8 +38,7 @@ public PaginatorAssert rangeLabel(final String label) { @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) public PaginatorAssert colorTheme(final AngularColors value) { - final AngularColors color = AngularColors.fromName(element().colorTheme()); - jdiAssert(color, Matchers.equalTo(value)); + jdiAssert(AngularColors.fromName(element().colorTheme()), Matchers.equalTo(value)); return this; } @@ -51,8 +50,7 @@ public PaginatorAssert colorTheme(final String value) { @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true) public PaginatorAssert borderColor(final AngularColors value) { - AngularColors actualColor = AngularColors.fromColor(element().boarderColor()); - jdiAssert(actualColor, Matchers.equalTo(value)); + jdiAssert(AngularColors.fromColor(element().boarderColor()), Matchers.equalTo(value)); return this; } @@ -64,8 +62,7 @@ public PaginatorAssert borderColor(final String value) { @JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true) public PaginatorAssert selectedOptionColor(final AngularColors value) { - AngularColors actualColorInList = AngularColors.fromColor(element().selectedOptionColor()); - jdiAssert(actualColorInList, Matchers.equalTo(value)); + jdiAssert(AngularColors.fromColor(element().selectedOptionColor()), Matchers.equalTo(value)); return this; } @@ -97,7 +94,7 @@ public PaginatorAssert hiddenPageSize(boolean value) { @JDIAction(value = "Assert that '{name}' has shown first and last page buttons", isAssert = true) 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" + value ? "first and last buttons should be SHOWN" : "first and last buttons should be DISPLAYED" ); return this; } @@ -111,51 +108,58 @@ public PaginatorAssert pageIndexCurrent(int pageIndex) { return this; } - @JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true) - public PaginatorAssert totalNumberOfItems(int length) { - jdiAssert(element().totalNumberOfItems(), Matchers.equalTo(length)); + @JDIAction(value = "Assert that '{name}' has {0} total number of items that are being paginated", isAssert = true) + public PaginatorAssert totalNumberOfPaginatedItems(int length) { + jdiAssert(element().totalNumberOfPaginatedItems(), 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")); + public PaginatorAssert previousPageButtonEnabled() { + jdiAssert(element().previousButton().isEnabled(), Matchers.is(true), + "previous button should be 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")); + public PaginatorAssert previousPageButtonDisabled() { + jdiAssert(element().previousButton().isDisabled(), Matchers.is(true), + "previous button should be 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")); + public PaginatorAssert nextPageButtonEnabled() { + jdiAssert(element().nextButton().isEnabled(), Matchers.is(true), + "next button should be 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")); + public PaginatorAssert nextPageButtonDisabled() { + jdiAssert(element().nextButton().isDisabled(), Matchers.is(true), + "previous button should be 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")); + jdiAssert(element().itemPerPageSelector().isDisabled(), Matchers.is(true), + "item per page selector should be 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")); + public PaginatorAssert firstPageButtonDisplayed(boolean value) { + jdiAssert(element().firstPageButton().isDisplayed(), Matchers.is(value), + value ? "fist page button should be DISPLAYED" : "first page button should be 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")); + public PaginatorAssert lastPageButtonDisplayed(boolean value) { + jdiAssert(element().lastPageButton().isDisplayed(), Matchers.is(value), + value ? "last page button should be DISPLAYED" : "last page button should be 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 5a00e7129d..63489cedd1 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 @@ -168,7 +168,7 @@ public int pageIndexCurrent() { } @JDIAction("Get '{name}' total number of items that are being paginated") - public int totalNumberOfItems() { + public int totalNumberOfPaginatedItems() { return parseInt(getMatcherForRange().group(4)); } 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 8194ceab72..4fecc17df9 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 @@ -19,7 +19,7 @@ protected UIElement toggle() { return this.core(); } - @JDIAction("Get '{name}' selected value from selector") + @JDIAction("Get '{name}' toggle value") public String toggleValue() { return toggle().getText(); } From 211bbdfa836426e290e9691837e1dbe315a5c522 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Tue, 5 Mar 2024 21:02:50 +0400 Subject: [PATCH 08/12] #4926: Tests refactoring: Paginator element fix 3 remove hierarchy --- .../elements/complex/PaginatorTests.java | 4 +- .../angular/asserts/PaginatorAssert.java | 2 +- .../angular/elements/complex/Paginator.java | 81 ++++++++++++++----- .../elements/complex/PaginatorSelector.java | 70 ---------------- 4 files changed, 64 insertions(+), 93 deletions(-) delete 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/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(); - } - } -} - From 772e85c37c518f19c24a364ac2bbd36f3f7903fa Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova Date: Thu, 13 Jun 2024 13:37:15 +0400 Subject: [PATCH 09/12] solve conflicts --- .../angular/asserts/PaginatorAssert.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) 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 4c49721fd8..c96f363e72 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,36 +9,37 @@ import java.util.List; import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; +import static org.hamcrest.Matchers.equalTo; public class PaginatorAssert extends UIAssert { @JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true) public PaginatorAssert pageSizeLabel(final String label) { - jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label)); + jdiAssert(element().itemPerPageLabel(), 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.equalTo(number)); + jdiAssert(element().selected(), equalTo(number)); return this; } @JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true) public PaginatorAssert itemsPerPageList(final List options) { - jdiAssert(element().options(), Matchers.equalTo(options)); + jdiAssert(element().options(), equalTo(options)); return this; } @JDIAction(value = "Assert that range is '{0}' for '{name}'", isAssert = true) public PaginatorAssert rangeLabel(final String label) { - jdiAssert(element().range(), Matchers.equalTo(label)); + jdiAssert(element().range(), equalTo(label)); return this; } @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) public PaginatorAssert colorTheme(final AngularColors value) { - jdiAssert(AngularColors.fromName(element().colorTheme()), Matchers.equalTo(value)); + jdiAssert(AngularColors.fromType(element().colorTheme()), equalTo(value)); return this; } @@ -50,37 +51,37 @@ public PaginatorAssert colorTheme(final String value) { @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true) public PaginatorAssert borderColor(final AngularColors value) { - jdiAssert(AngularColors.fromColor(element().boarderColor()), Matchers.equalTo(value)); + jdiAssert(AngularColors.fromType(element().boarderColor()), 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)); + jdiAssert(element().boarderColor(), equalTo(value)); return this; } @JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true) public PaginatorAssert selectedOptionColor(final AngularColors value) { - jdiAssert(AngularColors.fromColor(element().selectedOptionColor()), Matchers.equalTo(value)); + jdiAssert((element().selectedOptionColor()), 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)); + jdiAssert(element().selectedOptionColor(), equalTo(value)); return this; } @JDIAction(value = "Assert that '{name} has firstPageLabel='{0}'", isAssert = true) public PaginatorAssert firstPageLabel(final String label) { - jdiAssert(element().firstPageLabel(), Matchers.equalTo(label)); + jdiAssert(element().firstPageLabel(), equalTo(label)); return this; } @JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true) public PaginatorAssert lastPageLabel(final String label) { - jdiAssert(element().lastPageLabel(), Matchers.equalTo(label)); + jdiAssert(element().lastPageLabel(), equalTo(label)); return this; } @@ -104,13 +105,13 @@ public PaginatorAssert firstLastButtonsShown(boolean value) { */ @JDIAction(value = "Assert that '{name}' has current page index of {0}", isAssert = true) public PaginatorAssert pageIndexCurrent(int pageIndex) { - jdiAssert(element().pageIndexCurrent(), Matchers.equalTo(pageIndex)); + jdiAssert(element().pageIndexCurrent(), equalTo(pageIndex)); return this; } @JDIAction(value = "Assert that '{name}' has {0} total number of items that are being paginated", isAssert = true) public PaginatorAssert totalNumberOfPaginatedItems(int length) { - jdiAssert(element().totalNumberOfPaginatedItems(), Matchers.equalTo(length)); + jdiAssert(element().totalNumberOfPaginatedItems(), equalTo(length)); return this; } @@ -144,7 +145,7 @@ public PaginatorAssert nextPageButtonDisabled() { @JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true) public PaginatorAssert itemPerPageSelectorDisabled() { - jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), Matchers.equalTo("true"), + jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), equalTo("true"), "item per page selector should be DISABLED"); return this; } From 93aee344a62f73e0194331f3cb6228829a726a2a Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Wed, 26 Jun 2024 14:35:20 +0400 Subject: [PATCH 10/12] #4926: Tests refactoring: Paginator element. Color refactor --- .../elements/complex/PaginatorTests.java | 20 ++--- .../angular/asserts/PaginatorAssert.java | 79 +++++++++++-------- .../angular/elements/complex/Paginator.java | 24 +++--- 3 files changed, 64 insertions(+), 59 deletions(-) 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 af95e6c2e0..2f8833f7d0 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 @@ -114,21 +114,11 @@ public void firstAndLastPageButtonPaginatorTest() { @Test(description = "The test checks color theme of the paginators") public void colorPaginatorTest() { - 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().colorTheme(WARN) - .and().has().borderColor(WARN) - .and().has().selectedOptionColor(WARN); - - paginatorColorAccent.has().colorTheme(ACCENT) - .and().has().borderColor(ACCENT) - .and().has().selectedOptionColor(ACCENT); + paginatorColorPrimary.has().color(PRIMARY); + paginatorColorPrimary.has().color("primary"); + paginatorColorWarn.has().color(WARN); + paginatorColorAccent.has().color(ACCENT); + paginatorConfigurable.has().color("rgb(103, 58, 183)"); } @Test(description = "The test checks disabled paginator and disabled elements of the paginators") 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 c96f363e72..61b2fc5cff 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 @@ -2,6 +2,7 @@ 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.ColorAssert; import com.epam.jdi.light.asserts.generic.UIAssert; import com.epam.jdi.light.common.JDIAction; import org.hamcrest.Matchers; @@ -9,79 +10,78 @@ import java.util.List; import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert; -import static org.hamcrest.Matchers.equalTo; -public class PaginatorAssert extends UIAssert { +public class PaginatorAssert extends UIAssert implements ColorAssert { @JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true) public PaginatorAssert pageSizeLabel(final String label) { - jdiAssert(element().itemPerPageLabel(), equalTo(label)); + jdiAssert(element().itemPerPageLabel(), Matchers.is(label)); return this; } @JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true) public PaginatorAssert itemsPerPageSelected(final int number) { - jdiAssert(element().selected(), equalTo(number)); + jdiAssert(element().selected(), Matchers.is(number)); return this; } @JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true) public PaginatorAssert itemsPerPageList(final List options) { - jdiAssert(element().options(), equalTo(options)); + jdiAssert(element().options(), Matchers.equalTo(options)); return this; } @JDIAction(value = "Assert that range is '{0}' for '{name}'", isAssert = true) public PaginatorAssert rangeLabel(final String label) { - jdiAssert(element().range(), equalTo(label)); + jdiAssert(element().range(), Matchers.equalTo(label)); return this; } - @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) - public PaginatorAssert colorTheme(final AngularColors value) { - jdiAssert(AngularColors.fromType(element().colorTheme()), equalTo(value)); - return this; - } +// @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) +// public PaginatorAssert colorTheme(final AngularColors value) { +// jdiAssert(AngularColors.fromType(element().colorTheme()), 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 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 borderColor(final AngularColors value) { - jdiAssert(AngularColors.fromType(element().boarderColor()), Matchers.equalTo(value)); - return this; - } +// @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true) +// public PaginatorAssert borderColor(final AngularColors value) { +// jdiAssert(AngularColors.fromType(element().boarderColor()), 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(), 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 selectedOptionColor(final AngularColors value) { - jdiAssert((element().selectedOptionColor()), equalTo(value)); + jdiAssert((element().selectedOptionColor()), 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(), equalTo(value)); + jdiAssert(element().selectedOptionColor(), Matchers.equalTo(value)); return this; } @JDIAction(value = "Assert that '{name} has firstPageLabel='{0}'", isAssert = true) public PaginatorAssert firstPageLabel(final String label) { - jdiAssert(element().firstPageLabel(), equalTo(label)); + jdiAssert(element().firstPageLabel(), Matchers.equalTo(label)); return this; } @JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true) public PaginatorAssert lastPageLabel(final String label) { - jdiAssert(element().lastPageLabel(), equalTo(label)); + jdiAssert(element().lastPageLabel(), Matchers.equalTo(label)); return this; } @@ -105,13 +105,13 @@ public PaginatorAssert firstLastButtonsShown(boolean value) { */ @JDIAction(value = "Assert that '{name}' has current page index of {0}", isAssert = true) public PaginatorAssert pageIndexCurrent(int pageIndex) { - jdiAssert(element().pageIndexCurrent(), equalTo(pageIndex)); + jdiAssert(element().pageIndexCurrent(), Matchers.equalTo(pageIndex)); return this; } @JDIAction(value = "Assert that '{name}' has {0} total number of items that are being paginated", isAssert = true) public PaginatorAssert totalNumberOfPaginatedItems(int length) { - jdiAssert(element().totalNumberOfPaginatedItems(), equalTo(length)); + jdiAssert(element().totalNumberOfPaginatedItems(), Matchers.equalTo(length)); return this; } @@ -145,7 +145,7 @@ public PaginatorAssert nextPageButtonDisabled() { @JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true) public PaginatorAssert itemPerPageSelectorDisabled() { - jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), equalTo("true"), + jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), Matchers.equalTo("true"), "item per page selector should be DISABLED"); return this; } @@ -163,5 +163,18 @@ public PaginatorAssert lastPageButtonDisplayed(boolean value) { value ? "last page button should be DISPLAYED" : "last page button should be HIDDEN"); return this; } + + @JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true) + public PaginatorAssert color(AngularColors expectedColor) { + jdiAssert(element().color(), Matchers.equalTo(expectedColor.getType())); + return this; + } + + @Override + @JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true) + public PaginatorAssert color(String expectedColor) { + jdiAssert(element().color(), Matchers.equalTo(expectedColor)); + 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 d3b3d5a3c9..c35ac5d185 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 @@ -6,6 +6,7 @@ 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 com.epam.jdi.light.elements.interfaces.base.HasColor; import org.openqa.selenium.By; import org.openqa.selenium.Point; @@ -21,7 +22,7 @@ * To see an example of Paginator web element please visit .... */ -public class Paginator extends UIBaseElement { +public class Paginator extends UIBaseElement implements HasColor { 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"; @@ -35,7 +36,6 @@ public class Paginator extends UIBaseElement { 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"; private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)"); @@ -96,6 +96,10 @@ public UIElement itemPerPageSelector() { return core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR); } + // @JDIAction("Get item per page selector for '{name}'") +// public UIElement materiialSelector() { +// return new Dropdown().setCore(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)); @@ -151,24 +155,22 @@ public void nextPage() { nextButton().click(); } - @JDIAction("Get color theme for '{name}'") - public String colorTheme() { - return core().hasAttribute(COLOR_ATT) ? core().attr(COLOR_ATT) : "primary"; - } - - @JDIAction("Get color of selector`s boarder for '{name}'") - public String boarderColor() { + @Override + @JDIAction("Get '{name}' color") + public String color() { + if (core().hasAttribute("color")) { + return core().attr("color"); + } expandItemPerPageOptions(); final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color"); collapseItemPerPageOptions(); 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); + String cssValue = selectedOptionFromItemsPerPageList().find("span").getCssValue("COLOR_ATT"); collapseItemPerPageOptions(); return cssValue; } From be4ca55fad6ff114190207b4c1241477f5613a73 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Tue, 2 Jul 2024 17:33:28 +0400 Subject: [PATCH 11/12] #4926: Tests refactoring: Paginator element. PaginatorSelector.java --- .../elements/complex/PaginatorTests.java | 13 +-- .../angular/asserts/PaginatorAssert.java | 43 +-------- .../angular/elements/complex/Paginator.java | 96 +++++-------------- .../elements/complex/PaginatorSelector.java | 19 ++++ 4 files changed, 55 insertions(+), 116 deletions(-) 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/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 2f8833f7d0..122752da37 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 @@ -23,10 +23,11 @@ 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.Integer.parseInt; import static java.lang.String.format; public class PaginatorTests extends TestsInit { - private static final List PAGE_SIZE_OPTIONS = 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 = PAGE_SIZE_OPTIONS .stream() @@ -52,7 +53,7 @@ public void labelPaginationTest() { @Test(description = "The test checks length and pageIndex for paginator") public void basicPaginatorTest() { waitCondition(() -> listLengthInput.isVisible()); - listLengthInput.setValue(String.valueOf(LENGTH)); + listLengthInput.setValue( String.valueOf(LENGTH) ); paginatorConfigurable.selectItemPerPageOption(STEP); //First page paginatorConfigurable.has().pageIndexCurrent(0) @@ -149,10 +150,10 @@ public void itemPerPagePaginatorTest() { pageSizeOptionsInput.setValue(OPTIONS); listLengthInput.setValue(String.valueOf(LENGTH)); - for (Integer option : PAGE_SIZE_OPTIONS) { - paginatorConfigurable.selectItemPerPageOption(option); - final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH); - paginatorConfigurable.has().itemsPerPageSelected(option) + for (String option : PAGE_SIZE_OPTIONS) { + paginatorConfigurable.selectItemPerPageOption(parseInt(option)); + final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(parseInt(option), LENGTH), LENGTH); + paginatorConfigurable.has().itemsPerPageSelected(parseInt(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 61b2fc5cff..6d4cd824c0 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 @@ -25,8 +25,9 @@ public PaginatorAssert itemsPerPageSelected(final int number) { } @JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true) - public PaginatorAssert itemsPerPageList(final List options) { - jdiAssert(element().options(), Matchers.equalTo(options)); + public PaginatorAssert itemsPerPageList(final List options) { + element().ItemPerPageSelect.expand(); + jdiAssert(element().ItemPerPageSelect.list().values(), Matchers.equalTo(options)); return this; } @@ -37,42 +38,6 @@ public PaginatorAssert rangeLabel(final String label) { return this; } -// @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true) -// public PaginatorAssert colorTheme(final AngularColors value) { -// jdiAssert(AngularColors.fromType(element().colorTheme()), 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 borderColor(final AngularColors value) { -// jdiAssert(AngularColors.fromType(element().boarderColor()), 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 selectedOptionColor(final AngularColors value) { - jdiAssert((element().selectedOptionColor()), 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(final String label) { jdiAssert(element().firstPageLabel(), Matchers.equalTo(label)); @@ -145,7 +110,7 @@ public PaginatorAssert nextPageButtonDisabled() { @JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true) public PaginatorAssert itemPerPageSelectorDisabled() { - jdiAssert(element().itemPerPageSelector().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/Paginator.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Paginator.java index c35ac5d185..325557c755 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,13 @@ 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 com.epam.jdi.light.elements.interfaces.base.HasColor; -import org.openqa.selenium.By; -import org.openqa.selenium.Point; +import com.epam.jdi.light.elements.pageobjects.annotations.locators.JDropdown; -import java.util.List; -import java.util.NoSuchElementException; import java.util.regex.Matcher; import java.util.regex.Pattern; import static java.lang.Integer.parseInt; -import static java.util.stream.Collectors.toList; /** * To see an example of Paginator web element please visit .... @@ -29,14 +23,13 @@ public class Paginator extends UIBaseElement implements HasColo 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 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"; + @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") @@ -91,53 +84,14 @@ public Button lastPageButton() { return new Button().setCore(Button.class, core().find(LAST_PAGE_BUTTON_LOCATOR)); } - @JDIAction("Get item per page selector for '{name}'") - public UIElement itemPerPageSelector() { - return core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR); - } - - // @JDIAction("Get item per page selector for '{name}'") -// public UIElement materiialSelector() { -// return new Dropdown().setCore(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() { - 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 items per page option '{0}' for '{name}'") public void selectItemPerPageOption(int number) { - expandItemPerPageOptions(); - itemsPerPageOptionsWebList().select(String.valueOf(number)); + ItemPerPageSelect.select(" " + number + " "); } @JDIAction("Get selected option for '{name}'") public int selected() { - return parseInt(itemPerPageSelector().getText()); + return parseInt(ItemPerPageSelect.selected()); } @JDIAction("Get range for '{name}'") @@ -161,30 +115,30 @@ public String color() { if (core().hasAttribute("color")) { return core().attr("color"); } - expandItemPerPageOptions(); + ItemPerPageSelect.expand(); final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color"); - collapseItemPerPageOptions(); + 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 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 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() { 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 0000000000..9a986d3a28 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java @@ -0,0 +1,19 @@ +package com.epam.jdi.light.angular.elements.complex; + +import com.epam.jdi.light.elements.complex.dropdown.Dropdown; + +import static org.openqa.selenium.Keys.ESCAPE; + +public class PaginatorSelector extends Dropdown { + @Override + public void close() { + if (isExpanded()) { + press(ESCAPE); + } + } + + @Override + public boolean isExpanded() { + return expander().attr("aria-expanded").equals("true"); + } +} From eee5937d14c723eff2c97061107143ab42389d98 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Wed, 10 Jul 2024 15:32:32 +0400 Subject: [PATCH 12/12] #4926: Tests refactoring: Paginator element. JPaginator.java --- .../io/github/com/pages/PaginatorPage.java | 9 +-- .../elements/complex/PaginatorTests.java | 1 + .../angular/asserts/PaginatorAssert.java | 12 +++- .../angular/elements/complex/JPaginator.java | 15 +++++ .../angular/elements/complex/Paginator.java | 64 ++++++++++--------- 5 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/JPaginator.java 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()); + } }