Skip to content

Commit 1fc5b56

Browse files
author
Ekaterina Semenova1
committed
#4926: Tests refactoring: Paginator element fix 3 remove hierarchy
1 parent 8b6f43f commit 1fc5b56

4 files changed

Lines changed: 64 additions & 93 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void labelPaginationTest() {
5353
public void basicPaginatorTest() {
5454
waitCondition(() -> listLengthInput.isVisible());
5555
listLengthInput.setValue(String.valueOf(LENGTH));
56-
paginatorConfigurable.select(STEP);
56+
paginatorConfigurable.selectItemPerPageOption(STEP);
5757
//First page
5858
paginatorConfigurable.has().pageIndexCurrent(0)
5959
.and().has().totalNumberOfPaginatedItems(LENGTH)
@@ -160,7 +160,7 @@ public void itemPerPagePaginatorTest() {
160160
listLengthInput.setValue(String.valueOf(LENGTH));
161161

162162
for (Integer option : PAGE_SIZE_OPTIONS) {
163-
paginatorConfigurable.select(option);
163+
paginatorConfigurable.selectItemPerPageOption(option);
164164
final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH);
165165
paginatorConfigurable.has().itemsPerPageSelected(option)
166166
.and().has().rangeLabel(rangeLabel);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public PaginatorAssert nextPageButtonDisabled() {
144144

145145
@JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true)
146146
public PaginatorAssert itemPerPageSelectorDisabled() {
147-
jdiAssert(element().itemPerPageSelector().isDisabled(), Matchers.is(true),
147+
jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), Matchers.equalTo("true"),
148148
"item per page selector should be DISABLED");
149149
return this;
150150
}

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

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
import com.epam.jdi.light.angular.elements.common.Button;
55
import com.epam.jdi.light.common.JDIAction;
66
import com.epam.jdi.light.elements.base.UIBaseElement;
7+
import com.epam.jdi.light.elements.common.UIElement;
8+
import com.epam.jdi.light.elements.complex.WebList;
9+
import org.openqa.selenium.By;
10+
import org.openqa.selenium.Point;
711

812
import java.util.List;
13+
import java.util.NoSuchElementException;
914
import java.util.regex.Matcher;
1015
import java.util.regex.Pattern;
11-
import java.util.stream.Collectors;
1216

1317
import static java.lang.Integer.parseInt;
18+
import static java.util.stream.Collectors.toList;
1419

1520
/**
1621
* To see an example of Paginator web element please visit <a href="https://material.angular.io/components/paginator/overview">...</a>.
@@ -27,12 +32,12 @@ public class Paginator extends UIBaseElement<PaginatorAssert> {
2732
private static final String BOARDER_LOCATOR = ".mdc-notched-outline__leading";
2833
private static final String PAGINATOR_PAGE_SIZE_SECTION_LOCATOR = ".mat-mdc-paginator-page-size";
2934
private static final String ITEM_PER_PAGE_SELECTOR_LOCATOR = "mat-select";
30-
private final PaginatorSelector itemPerPageSelector;
31-
private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)");
35+
private static final String SELECT_PANEL_LOCATOR = "div.mat-mdc-select-panel";
36+
private static final String ITEM_PER_PAGE_OPTIONS_LOCATOR = "mat-option";
37+
private static final String ARIA_EXPANDED_ATTR = "aria-expanded";
38+
private static final String COLOR_ATT = "color";
3239

33-
public Paginator() {
34-
itemPerPageSelector = new PaginatorSelector().setCore(PaginatorSelector.class, core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR));
35-
}
40+
private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)");
3641

3742
@JDIAction("Set pattern for '{name}' range label")
3843
public void setRangeLabelPattern(String regex) {
@@ -87,23 +92,48 @@ public Button lastPageButton() {
8792
}
8893

8994
@JDIAction("Get item per page selector for '{name}'")
90-
public PaginatorSelector itemPerPageSelector() {
91-
return itemPerPageSelector;
95+
public UIElement itemPerPageSelector() {
96+
return core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR);
97+
}
98+
99+
@JDIAction("Get WebList of items per page options for '{name}'")
100+
private WebList itemsPerPageOptionsWebList() {
101+
return new WebList(By.cssSelector(ITEM_PER_PAGE_OPTIONS_LOCATOR));
92102
}
93103

94104
@JDIAction("Get options for '{name}'")
95105
public List<Integer> options() {
96-
return itemPerPageSelector.values().stream().map(Integer::parseInt).collect(Collectors.toList());
106+
expandItemPerPageOptions();
107+
final List<Integer> collect = itemsPerPageOptionsWebList().values().stream().map(Integer::parseInt).collect(toList());
108+
collapseItemPerPageOptions();
109+
return collect;
110+
}
111+
112+
@JDIAction("Expand options for '{name}'")
113+
private void expandItemPerPageOptions() {
114+
if (itemPerPageSelector().attr(ARIA_EXPANDED_ATTR).equals("false")) {
115+
itemPerPageSelector().click();
116+
}
117+
}
118+
119+
@JDIAction("Collapse items per page options for '{name}'")
120+
private void collapseItemPerPageOptions() {
121+
if (itemPerPageSelector().attr(ARIA_EXPANDED_ATTR).equals("true")) {
122+
UIElement uiElement = new UIElement(By.cssSelector(SELECT_PANEL_LOCATOR));
123+
Point pointOutsidePanel = new Point(uiElement.core().getRect().getWidth() + 2, uiElement.core().getRect().getHeight() + 2);
124+
uiElement.core().click(pointOutsidePanel.getX(), pointOutsidePanel.getY());
125+
}
97126
}
98127

99-
@JDIAction("Select option for '{name}'")
100-
public void select(int number) {
101-
itemPerPageSelector.select(String.valueOf(number));
128+
@JDIAction("Select items per page option '{0}' for '{name}'")
129+
public void selectItemPerPageOption(int number) {
130+
expandItemPerPageOptions();
131+
itemsPerPageOptionsWebList().select(String.valueOf(number));
102132
}
103133

104134
@JDIAction("Get selected option for '{name}'")
105135
public int selected() {
106-
return parseInt(itemPerPageSelector.toggleValue());
136+
return parseInt(itemPerPageSelector().getText());
107137
}
108138

109139
@JDIAction("Get range for '{name}'")
@@ -123,26 +153,37 @@ public void nextPage() {
123153

124154
@JDIAction("Get color theme for '{name}'")
125155
public String colorTheme() {
126-
final String colorAtt = "color";
127-
return core().hasAttribute(colorAtt) ? core().attr(colorAtt) : "primary";
156+
return core().hasAttribute(COLOR_ATT) ? core().attr(COLOR_ATT) : "primary";
128157
}
129158

130159
@JDIAction("Get color of selector`s boarder for '{name}'")
131160
public String boarderColor() {
132-
itemPerPageSelector.expand();
161+
expandItemPerPageOptions();
133162
final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color");
134-
itemPerPageSelector.collapse();
163+
collapseItemPerPageOptions();
135164
return cssValue;
136165
}
137166

167+
138168
@JDIAction("Get color for selected value in the list of options for '{name}'")
139169
public String selectedOptionColor() {
140-
itemPerPageSelector.expand();
141-
String cssValue = itemPerPageSelector.selectedOptionFromList().getCssValue("color");
142-
itemPerPageSelector.collapse();
170+
expandItemPerPageOptions();
171+
String cssValue = selectedOptionFromItemsPerPageList().find("span").getCssValue(COLOR_ATT);
172+
collapseItemPerPageOptions();
143173
return cssValue;
144174
}
145175

176+
@JDIAction("Get selected option from items per page list for '{name}'")
177+
private UIElement selectedOptionFromItemsPerPageList() {
178+
return itemsPerPageOptionsWebList().stream()
179+
.filter(el -> el
180+
.attr("aria-selected").equals("true"))
181+
.findFirst()
182+
.orElseThrow(
183+
() -> new NoSuchElementException("No element with attribute aria-selected = true")
184+
);
185+
}
186+
146187
@JDIAction("Get '{name}' firstPageLabel")
147188
public String lastPageLabel() {
148189
return core().attr("lastPageLabel");

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

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)