|
1 | 1 | package io.github.epam.angular.tests.elements.complex; |
2 | 2 |
|
3 | 3 | import io.github.epam.TestsInit; |
4 | | -import org.openqa.selenium.Dimension; |
5 | 4 | import org.testng.annotations.BeforeMethod; |
6 | | -import org.testng.annotations.Ignore; |
7 | 5 | import org.testng.annotations.Test; |
8 | 6 |
|
9 | 7 | import java.util.Arrays; |
10 | 8 | import java.util.List; |
| 9 | +import java.util.Random; |
11 | 10 | import java.util.stream.Collectors; |
12 | 11 |
|
13 | | -import static com.epam.jdi.light.driver.WebDriverFactory.getDriver; |
14 | | -import static io.github.com.StaticSite.angularPage; |
15 | | -import static io.github.com.pages.sections.PaginatorSection.*; |
16 | | -import static io.github.epam.site.steps.States.shouldBeLoggedIn; |
| 12 | +import static com.epam.jdi.light.angular.elements.enums.AngularColors.ACCENT; |
| 13 | +import static com.epam.jdi.light.angular.elements.enums.AngularColors.PRIMARY; |
| 14 | +import static com.epam.jdi.light.angular.elements.enums.AngularColors.WARN; |
| 15 | +import static com.jdiai.tools.Timer.waitCondition; |
| 16 | +import static io.github.com.StaticSite.paginatorPage; |
| 17 | +import static io.github.com.pages.PaginatorPage.listLengthInput; |
| 18 | +import static io.github.com.pages.PaginatorPage.pageSizeOptionsInput; |
| 19 | +import static io.github.com.pages.PaginatorPage.paginatorColorAccent; |
| 20 | +import static io.github.com.pages.PaginatorPage.paginatorColorPrimary; |
| 21 | +import static io.github.com.pages.PaginatorPage.paginatorColorWarn; |
| 22 | +import static io.github.com.pages.PaginatorPage.paginatorConfigurable; |
| 23 | +import static io.github.com.pages.PaginatorPage.paginatorDisabledOption; |
| 24 | +import static io.github.com.pages.PaginatorPage.paginatorFirstLastButtons; |
| 25 | +import static io.github.com.pages.PaginatorPage.paginatorHideSizeOption; |
| 26 | +import static java.lang.String.format; |
17 | 27 |
|
18 | | -// TODO Move to the new page |
19 | | -@Ignore |
20 | 28 | public class PaginatorTests extends TestsInit { |
21 | | - private static final List<Integer> PAGESIZEOPTIONS = Arrays.asList(1, 5, 10, 25, 100, 500); |
| 29 | + private static final List<Integer> PAGE_SIZE_OPTIONS = Arrays.asList(1, 5, 10, 25, 100, 500); |
22 | 30 | private static final String OPTIONS = |
23 | | - PAGESIZEOPTIONS |
| 31 | + PAGE_SIZE_OPTIONS |
24 | 32 | .stream() |
25 | 33 | .map(String::valueOf) |
26 | 34 | .collect(Collectors.joining(",")); |
27 | | - private static final int TOTAL = 50; |
| 35 | + private static final int STEP = 100; |
| 36 | + private static final int PAGE_SIZE = 10; |
| 37 | + private static final int LENGTH = STEP * PAGE_SIZE - new Random().nextInt(STEP); |
| 38 | + private static final String RANGE_PATTERN = "%d - %d / %d"; |
28 | 39 |
|
29 | 40 | @BeforeMethod |
30 | 41 | public void before() { |
31 | | - getDriver().manage().window().setSize(new Dimension(1920, 1080)); |
32 | | - |
33 | | - shouldBeLoggedIn(); |
34 | | - angularPage.shouldBeOpened(); |
35 | | - |
36 | | - listLength.setValue(String.valueOf(TOTAL)); |
37 | | - pageSizeOptions.setValue(OPTIONS); |
| 42 | + paginatorPage.open(); |
| 43 | + waitCondition(() -> paginatorPage.isOpened()); |
| 44 | + paginatorPage.checkOpened(); |
38 | 45 | } |
39 | 46 |
|
40 | | - @Test |
| 47 | + @Test(description = "The test checks item per page label") |
41 | 48 | public void labelPaginationTest() { |
42 | | - paginator.has().label("Items per page:"); |
| 49 | + paginatorConfigurable.has().itemPerPageLabel("Items per page:"); |
43 | 50 | } |
44 | 51 |
|
45 | | - @Test |
| 52 | + @Test(description = "The test checks length and pageIndex for paginator") |
46 | 53 | public void basicPaginatorTest() { |
47 | | - final int STEP = 10; |
48 | | - paginator.select(STEP); |
49 | | - |
50 | | - paginator.is().range(1, STEP, TOTAL); |
51 | | - paginator.is().previousDisabled(); |
52 | | - paginator.is().nextEnabled(); |
53 | | - paginator.next(); |
54 | | - |
55 | | - for (int i = STEP + 1; i < TOTAL - STEP + 1; i += STEP) { |
56 | | - paginator.is().range(i, i + STEP - 1, TOTAL); |
57 | | - paginator.is().previousEnabled(); |
58 | | - paginator.is().nextEnabled(); |
59 | | - paginator.next(); |
| 54 | + waitCondition(() -> listLengthInput.isVisible()); |
| 55 | + listLengthInput.setValue(String.valueOf(LENGTH)); |
| 56 | + paginatorConfigurable.select(STEP); |
| 57 | + |
| 58 | + //Go through each page sequentially: |
| 59 | + for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) { |
| 60 | + paginatorConfigurable.has().pageIndex(pageIndex) |
| 61 | + .and().has().length(LENGTH) |
| 62 | + .and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH)); |
| 63 | + paginatorConfigurable.nextPage(); |
60 | 64 | } |
61 | 65 |
|
62 | | - paginator.is().range(TOTAL - STEP + 1, TOTAL, TOTAL); |
63 | | - paginator.is().previousEnabled(); |
64 | | - paginator.is().nextDisabled(); |
65 | | - paginator.previous(); |
66 | | - |
67 | | - for (int i = TOTAL - 2 * STEP + 1; i > 1; i -= STEP) { |
68 | | - paginator.is().range(i, i + STEP - 1, TOTAL); |
69 | | - paginator.is().previousEnabled(); |
70 | | - paginator.is().nextEnabled(); |
71 | | - paginator.previous(); |
| 66 | + //Go through each page backwards |
| 67 | + for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) { |
| 68 | + paginatorConfigurable.has().pageIndex(pageIndex) |
| 69 | + .and().has().length(LENGTH) |
| 70 | + .and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH)); |
| 71 | + paginatorConfigurable.previousPage(); |
72 | 72 | } |
| 73 | + paginatorConfigurable.has().pageIndex(0) |
| 74 | + .and().has().length(LENGTH) |
| 75 | + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH)); |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + @Test(description = "The test checks first page and last page buttons labels for paginator") |
| 80 | + public void firstAndLastPageButtonPaginatorTest() { |
| 81 | + paginatorFirstLastButtons.has().showFirstLastButtons(true); |
| 82 | + paginatorFirstLastButtons.has().firstPageLabel("test firstPageLabel"); |
| 83 | + paginatorFirstLastButtons.has().lastPageLabel("test lastPageLabel"); |
| 84 | + |
| 85 | + paginatorFirstLastButtons.firstPageButton().is().disabled(); |
| 86 | + paginatorFirstLastButtons.lastPageButton().is().enabled(); |
| 87 | + |
| 88 | + paginatorFirstLastButtons.lastPageButton().click(); |
| 89 | + paginatorFirstLastButtons.firstPageButton().is().enabled(); |
| 90 | + paginatorFirstLastButtons.lastPageButton().is().disabled(); |
73 | 91 |
|
74 | | - paginator.is().range(1, STEP, TOTAL); |
75 | | - paginator.is().previousDisabled(); |
76 | | - paginator.is().nextEnabled(); |
| 92 | + paginatorConfigurable.has().showFirstLastButtons(false); |
77 | 93 | } |
78 | 94 |
|
79 | | - @Test |
| 95 | + @Test(description = "The test checks color theme of the paginators") |
| 96 | + public void colorPaginatorTest() { |
| 97 | + paginatorColorPrimary.has().color(PRIMARY); |
| 98 | + paginatorColorPrimary.has().colorOfBoarder(PRIMARY); |
| 99 | + paginatorColorPrimary.has().colorOfSelectedOption(PRIMARY); |
| 100 | + |
| 101 | + paginatorColorWarn.has().color(WARN); |
| 102 | + paginatorColorWarn.has().colorOfBoarder(WARN); |
| 103 | + paginatorColorWarn.has().colorOfSelectedOption(WARN); |
| 104 | + |
| 105 | + paginatorColorAccent.has().color(ACCENT); |
| 106 | + paginatorColorAccent.has().colorOfBoarder(ACCENT); |
| 107 | + paginatorColorAccent.has().colorOfSelectedOption(ACCENT); |
| 108 | + } |
| 109 | + |
| 110 | + @Test(description = "The test checks disabled paginator and disabled elements of the paginators") |
80 | 111 | public void navigationDisabledPaginatorTest() { |
81 | | - listLength.setValue("0"); |
| 112 | + paginatorDisabledOption.is().disabled(); |
82 | 113 |
|
83 | | - paginator.has().range(); |
84 | | - paginator.has().previousDisabled(); |
85 | | - paginator.has().nextDisabled(); |
| 114 | + paginatorDisabledOption.previousButton().is().disabled(); |
| 115 | + paginatorDisabledOption.nextButton().is().disabled(); |
| 116 | + paginatorDisabledOption.itemPerPageSelector().is().disabled(); |
86 | 117 |
|
87 | | - listLength.setValue("100"); |
88 | | - paginator.select(100); |
89 | | - paginator.has().previousDisabled(); |
90 | | - paginator.has().nextDisabled(); |
| 118 | + paginatorHideSizeOption.is().enabled(); |
| 119 | + paginatorColorWarn.is().enabled(); |
91 | 120 | } |
92 | 121 |
|
93 | | - @Test |
| 122 | + @Test(description = "The test checks Item per page selector is hidden/visible") |
| 123 | + public void hidePageSizePaginatorTest() { |
| 124 | + paginatorHideSizeOption.has().hiddenPageSize(true); |
| 125 | + } |
| 126 | + |
| 127 | + @Test(description = "The test checks page size dropdown options") |
94 | 128 | public void pageSizeOptionsPaginatorTest() { |
95 | | - paginator.has().itemsPerPageList(PAGESIZEOPTIONS); |
| 129 | + pageSizeOptionsInput.setValue(OPTIONS); |
| 130 | + listLengthInput.focus(); |
| 131 | + paginatorConfigurable.has().itemsPerPageList(PAGE_SIZE_OPTIONS); |
96 | 132 | } |
97 | 133 |
|
98 | | - @Test |
| 134 | + @Test(description = "The test checks range label for page size dropdown options") |
99 | 135 | public void itemPerPagePaginatorTest() { |
100 | | - for (Integer option : PAGESIZEOPTIONS) { |
101 | | - paginator.select(option); |
102 | | - paginator.has().itemsPerPageSelected(option); |
103 | | - paginator.has().range(1, Math.min(option, TOTAL), TOTAL); |
| 136 | + pageSizeOptionsInput.setValue(OPTIONS); |
| 137 | + listLengthInput.setValue(String.valueOf(LENGTH)); |
| 138 | + |
| 139 | + for (Integer option : PAGE_SIZE_OPTIONS) { |
| 140 | + paginatorConfigurable.select(option); |
| 141 | + paginatorConfigurable.has().itemsPerPageSelected(option) |
| 142 | + .and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH)); |
104 | 143 | } |
105 | 144 | } |
106 | 145 | } |
0 commit comments