Skip to content

Commit d55cc1d

Browse files
committed
#4926: Tests refactoring: Paginator element fix 2
1 parent 25bca88 commit d55cc1d

File tree

4 files changed

+66
-41
lines changed

4 files changed

+66
-41
lines changed

jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/PaginatorTests.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.epam.angular.tests.elements.complex;
22

33
import io.github.epam.TestsInit;
4-
import org.testng.annotations.BeforeMethod;
4+
import org.testng.annotations.BeforeClass;
55
import org.testng.annotations.Test;
66

77
import java.util.Arrays;
@@ -37,7 +37,7 @@ public class PaginatorTests extends TestsInit {
3737
private static final int LENGTH = STEP * PAGE_SIZE - new Random().nextInt(STEP);
3838
private static final String RANGE_PATTERN = "%d - %d / %d";
3939

40-
@BeforeMethod
40+
@BeforeClass
4141
public void before() {
4242
paginatorPage.open();
4343
waitCondition(() -> paginatorPage.isOpened());
@@ -46,37 +46,58 @@ public void before() {
4646

4747
@Test(description = "The test checks item per page label")
4848
public void labelPaginationTest() {
49-
paginatorConfigurable.has().itemPerPageLabel("Items per page:");
49+
paginatorConfigurable.has().pageSizeLabel("Items per page:");
5050
}
5151

5252
@Test(description = "The test checks length and pageIndex for paginator")
5353
public void basicPaginatorTest() {
5454
waitCondition(() -> listLengthInput.isVisible());
5555
listLengthInput.setValue(String.valueOf(LENGTH));
5656
paginatorConfigurable.select(STEP);
57+
//First page
58+
paginatorConfigurable.has().pageIndexCurrent(0)
59+
.and().has().totalNumberOfPaginatedItems(LENGTH)
60+
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH))
61+
.and().has().nextPageButtonEnabled()
62+
.and().has().previousPageButtonDisabled();
63+
paginatorConfigurable.nextPage();
5764

5865
//Go through each page sequentially:
59-
for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) {
66+
for (int pageIndex = 1; pageIndex < PAGE_SIZE - 1; pageIndex++) {
6067
final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH);
6168

6269
paginatorConfigurable.has().pageIndexCurrent(pageIndex)
63-
.and().has().totalNumberOfItems(LENGTH)
64-
.and().has().rangeLabel(rangeLabel);
70+
.and().has().totalNumberOfPaginatedItems(LENGTH)
71+
.and().has().rangeLabel(rangeLabel)
72+
.and().has().nextPageButtonEnabled()
73+
.and().has().previousPageButtonEnabled();
6574
paginatorConfigurable.nextPage();
6675
}
76+
//Last page
77+
paginatorConfigurable.has().pageIndexCurrent(PAGE_SIZE - 1)
78+
.and().has().totalNumberOfPaginatedItems(LENGTH)
79+
.and().has().rangeLabel(format(RANGE_PATTERN, (PAGE_SIZE - 1) * STEP + 1, Math.min((PAGE_SIZE - 1) * STEP + STEP, LENGTH), LENGTH))
80+
.and().has().previousPageButtonEnabled()
81+
.and().has().nextPageButtonDisabled();
82+
paginatorConfigurable.previousPage();
6783

6884
//Go through each page backwards
69-
for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) {
85+
for (int pageIndex = PAGE_SIZE - 2; pageIndex > 0; pageIndex--) {
7086
final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH);
7187

7288
paginatorConfigurable.has().pageIndexCurrent(pageIndex)
73-
.and().has().totalNumberOfItems(LENGTH)
74-
.and().has().rangeLabel(rangeLabel);
89+
.and().has().totalNumberOfPaginatedItems(LENGTH)
90+
.and().has().rangeLabel(rangeLabel)
91+
.and().has().nextPageButtonEnabled()
92+
.and().has().previousPageButtonEnabled();
7593
paginatorConfigurable.previousPage();
7694
}
95+
//First page
7796
paginatorConfigurable.has().pageIndexCurrent(0)
78-
.and().has().totalNumberOfItems(LENGTH)
79-
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH));
97+
.and().has().totalNumberOfPaginatedItems(LENGTH)
98+
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH))
99+
.and().has().previousPageButtonDisabled()
100+
.and().has().nextPageButtonEnabled();
80101

81102
}
82103

@@ -85,8 +106,8 @@ public void firstAndLastPageButtonPaginatorTest() {
85106
paginatorFirstLastButtons.has().firstLastButtonsShown(true)
86107
.and().has().firstPageLabel("test firstPageLabel")
87108
.and().has().lastPageLabel("test lastPageLabel")
88-
.and().has().firstPageDisplayed(true)
89-
.and().has().lastPageDisplayed(true);
109+
.and().has().firstPageButtonDisplayed(true)
110+
.and().has().lastPageButtonDisplayed(true);
90111

91112
paginatorConfigurable.has().firstLastButtonsShown(false);
92113
}
@@ -113,8 +134,8 @@ public void colorPaginatorTest() {
113134
@Test(description = "The test checks disabled paginator and disabled elements of the paginators")
114135
public void navigationDisabledPaginatorTest() {
115136
paginatorDisabledOption.is().disabled()
116-
.and().has().previousDisabled()
117-
.and().has().nextDisabled()
137+
.and().has().previousPageButtonDisabled()
138+
.and().has().nextPageButtonDisabled()
118139
.and().has().itemPerPageSelectorDisabled();
119140

120141
paginatorHideSizeOption.is().enabled();

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PaginatorAssert.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class PaginatorAssert extends UIAssert<PaginatorAssert, Paginator> {
1414
@JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true)
15-
public PaginatorAssert itemPerPageLabel(final String label) {
15+
public PaginatorAssert pageSizeLabel(final String label) {
1616
jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label));
1717
return this;
1818
}
@@ -38,8 +38,7 @@ public PaginatorAssert rangeLabel(final String label) {
3838

3939
@JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
4040
public PaginatorAssert colorTheme(final AngularColors value) {
41-
final AngularColors color = AngularColors.fromName(element().colorTheme());
42-
jdiAssert(color, Matchers.equalTo(value));
41+
jdiAssert(AngularColors.fromName(element().colorTheme()), Matchers.equalTo(value));
4342
return this;
4443
}
4544

@@ -51,8 +50,7 @@ public PaginatorAssert colorTheme(final String value) {
5150

5251
@JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
5352
public PaginatorAssert borderColor(final AngularColors value) {
54-
AngularColors actualColor = AngularColors.fromColor(element().boarderColor());
55-
jdiAssert(actualColor, Matchers.equalTo(value));
53+
jdiAssert(AngularColors.fromColor(element().boarderColor()), Matchers.equalTo(value));
5654
return this;
5755
}
5856

@@ -64,8 +62,7 @@ public PaginatorAssert borderColor(final String value) {
6462

6563
@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
6664
public PaginatorAssert selectedOptionColor(final AngularColors value) {
67-
AngularColors actualColorInList = AngularColors.fromColor(element().selectedOptionColor());
68-
jdiAssert(actualColorInList, Matchers.equalTo(value));
65+
jdiAssert(AngularColors.fromColor(element().selectedOptionColor()), Matchers.equalTo(value));
6966
return this;
7067
}
7168

@@ -97,7 +94,7 @@ public PaginatorAssert hiddenPageSize(boolean value) {
9794
@JDIAction(value = "Assert that '{name}' has shown first and last page buttons", isAssert = true)
9895
public PaginatorAssert firstLastButtonsShown(boolean value) {
9996
jdiAssert(element().isFirstLastButtonsShown(), Matchers.is(value),
100-
value ? "first and last buttons should be shown" : "first and last buttons should be hidden"
97+
value ? "first and last buttons should be SHOWN" : "first and last buttons should be DISPLAYED"
10198
);
10299
return this;
103100
}
@@ -111,51 +108,58 @@ public PaginatorAssert pageIndexCurrent(int pageIndex) {
111108
return this;
112109
}
113110

114-
@JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true)
115-
public PaginatorAssert totalNumberOfItems(int length) {
116-
jdiAssert(element().totalNumberOfItems(), Matchers.equalTo(length));
111+
@JDIAction(value = "Assert that '{name}' has {0} total number of items that are being paginated", isAssert = true)
112+
public PaginatorAssert totalNumberOfPaginatedItems(int length) {
113+
jdiAssert(element().totalNumberOfPaginatedItems(), Matchers.equalTo(length));
117114
return this;
118115
}
119116

120117
@JDIAction(value = "Assert that previous button enabled for '{name}'", isAssert = true)
121-
public PaginatorAssert previousEnabled() {
122-
jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled"));
118+
public PaginatorAssert previousPageButtonEnabled() {
119+
jdiAssert(element().previousButton().isEnabled(), Matchers.is(true),
120+
"previous button should be ENABLED");
123121
return this;
124122
}
125123

126124
@JDIAction(value = "Assert that previous button disabled for '{name}'", isAssert = true)
127-
public PaginatorAssert previousDisabled() {
128-
jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled"));
125+
public PaginatorAssert previousPageButtonDisabled() {
126+
jdiAssert(element().previousButton().isDisabled(), Matchers.is(true),
127+
"previous button should be DISABLED");
129128
return this;
130129
}
131130

132131
@JDIAction(value = "Assert that next button enabled for '{name}'", isAssert = true)
133-
public PaginatorAssert nextEnabled() {
134-
jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled"));
132+
public PaginatorAssert nextPageButtonEnabled() {
133+
jdiAssert(element().nextButton().isEnabled(), Matchers.is(true),
134+
"next button should be ENABLED");
135135
return this;
136136
}
137137

138138
@JDIAction(value = "Assert that next button disabled for '{name}'", isAssert = true)
139-
public PaginatorAssert nextDisabled() {
140-
jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled"));
139+
public PaginatorAssert nextPageButtonDisabled() {
140+
jdiAssert(element().nextButton().isDisabled(), Matchers.is(true),
141+
"previous button should be DISABLED");
141142
return this;
142143
}
143144

144145
@JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true)
145146
public PaginatorAssert itemPerPageSelectorDisabled() {
146-
jdiAssert(element().itemPerPageSelector().isDisabled() ? "disabled" : "enabled", Matchers.equalTo("disabled"));
147+
jdiAssert(element().itemPerPageSelector().isDisabled(), Matchers.is(true),
148+
"item per page selector should be DISABLED");
147149
return this;
148150
}
149151

150152
@JDIAction(value = "Assert that first page button displayed={0} for '{name}'", isAssert = true)
151-
public PaginatorAssert firstPageDisplayed(boolean value) {
152-
jdiAssert(element().firstPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden"));
153+
public PaginatorAssert firstPageButtonDisplayed(boolean value) {
154+
jdiAssert(element().firstPageButton().isDisplayed(), Matchers.is(value),
155+
value ? "fist page button should be DISPLAYED" : "first page button should be HIDDEN");
153156
return this;
154157
}
155158

156159
@JDIAction(value = "Assert that last page button displayed={0} for '{name}'", isAssert = true)
157-
public PaginatorAssert lastPageDisplayed(boolean value) {
158-
jdiAssert(element().lastPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden"));
160+
public PaginatorAssert lastPageButtonDisplayed(boolean value) {
161+
jdiAssert(element().lastPageButton().isDisplayed(), Matchers.is(value),
162+
value ? "last page button should be DISPLAYED" : "last page button should be HIDDEN");
159163
return this;
160164
}
161165
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Paginator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public int pageIndexCurrent() {
168168
}
169169

170170
@JDIAction("Get '{name}' total number of items that are being paginated")
171-
public int totalNumberOfItems() {
171+
public int totalNumberOfPaginatedItems() {
172172
return parseInt(getMatcherForRange().group(4));
173173
}
174174

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/PaginatorSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected UIElement toggle() {
1919
return this.core();
2020
}
2121

22-
@JDIAction("Get '{name}' selected value from selector")
22+
@JDIAction("Get '{name}' toggle value")
2323
public String toggleValue() {
2424
return toggle().getText();
2525
}

0 commit comments

Comments
 (0)