From 344222c5a9a20278b3e7f140b3c360c56c88fc31 Mon Sep 17 00:00:00 2001 From: Ekaterina Semenova1 Date: Fri, 2 Feb 2024 17:12:15 +0400 Subject: [PATCH] #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 f28d14916b5..0a67ab04ab7 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 99f28398e31..8a171ecce5b 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 5a00e7129d3..63489cedd15 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 8194ceab72b..4fecc17df98 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(); }