-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4926: Tests refactoring: Paginator element
- Loading branch information
1 parent
6564bcc
commit d13f71d
Showing
8 changed files
with
421 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
jdi-light-angular-tests/src/main/java/io/github/com/pages/PaginatorPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
17 changes: 0 additions & 17 deletions
17
jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/PaginatorSection.java
This file was deleted.
Oops, something went wrong.
165 changes: 102 additions & 63 deletions
165
...lar-tests/src/test/java/io/github/epam/angular/tests/elements/complex/PaginatorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.