Skip to content

Commit

Permalink
#4926: Tests refactoring: Paginator element
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Jan 26, 2024
1 parent 68d720a commit 3bfb8cd
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,4 +54,7 @@ public class StaticSite {

@Url("slide_toggle")
public static SlideTogglePage slideTogglePage;

@Url("paginator")
public static PaginatorPage paginatorPage;
}
Original file line number Diff line number Diff line change
@@ -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;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Integer> PAGESIZEOPTIONS = Arrays.asList(1, 5, 10, 25, 100, 500);
private static final List<Integer> 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));
}
}
}
Loading

0 comments on commit 3bfb8cd

Please sign in to comment.