Skip to content

Commit

Permalink
#4926: Tests refactoring: Paginator element fix 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Jun 7, 2024
1 parent 5cf53f5 commit d01c38b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -46,37 +46,58 @@ 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")
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();

}

Expand All @@ -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);
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class PaginatorAssert extends UIAssert<PaginatorAssert, Paginator> {
@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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit d01c38b

Please sign in to comment.