Skip to content

Commit

Permalink
#4926: Tests refactoring: Paginator element. PaginatorSelector.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Jul 2, 2024
1 parent 93aee34 commit be4ca55
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
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.Integer.parseInt;
import static java.lang.String.format;

public class PaginatorTests extends TestsInit {
private static final List<Integer> PAGE_SIZE_OPTIONS = Arrays.asList(1, 5, 10, 25, 100, 500);
private static final List<String> PAGE_SIZE_OPTIONS = Arrays.asList("1", "5", "10", "25", "100", "500");
private static final String OPTIONS =
PAGE_SIZE_OPTIONS
.stream()
Expand All @@ -52,7 +53,7 @@ public void labelPaginationTest() {
@Test(description = "The test checks length and pageIndex for paginator")
public void basicPaginatorTest() {
waitCondition(() -> listLengthInput.isVisible());
listLengthInput.setValue(String.valueOf(LENGTH));
listLengthInput.setValue( String.valueOf(LENGTH) );
paginatorConfigurable.selectItemPerPageOption(STEP);
//First page
paginatorConfigurable.has().pageIndexCurrent(0)
Expand Down Expand Up @@ -149,10 +150,10 @@ public void itemPerPagePaginatorTest() {
pageSizeOptionsInput.setValue(OPTIONS);
listLengthInput.setValue(String.valueOf(LENGTH));

for (Integer option : PAGE_SIZE_OPTIONS) {
paginatorConfigurable.selectItemPerPageOption(option);
final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH);
paginatorConfigurable.has().itemsPerPageSelected(option)
for (String option : PAGE_SIZE_OPTIONS) {
paginatorConfigurable.selectItemPerPageOption(parseInt(option));
final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(parseInt(option), LENGTH), LENGTH);
paginatorConfigurable.has().itemsPerPageSelected(parseInt(option))
.and().has().rangeLabel(rangeLabel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public PaginatorAssert itemsPerPageSelected(final int number) {
}

@JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true)
public PaginatorAssert itemsPerPageList(final List<Integer> options) {
jdiAssert(element().options(), Matchers.equalTo(options));
public PaginatorAssert itemsPerPageList(final List<String> options) {
element().ItemPerPageSelect.expand();
jdiAssert(element().ItemPerPageSelect.list().values(), Matchers.equalTo(options));
return this;

}
Expand All @@ -37,42 +38,6 @@ public PaginatorAssert rangeLabel(final String label) {
return this;
}

// @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
// public PaginatorAssert colorTheme(final AngularColors value) {
// jdiAssert(AngularColors.fromType(element().colorTheme()), Matchers.equalTo(value));
// return this;
// }

// @JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
// public PaginatorAssert colorTheme(final String value) {
// jdiAssert(element().colorTheme(), Matchers.equalToIgnoringCase(value));
// return this;
// }

// @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
// public PaginatorAssert borderColor(final AngularColors value) {
// jdiAssert(AngularColors.fromType(element().boarderColor()), Matchers.equalTo(value));
// return this;
// }

// @JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
// public PaginatorAssert borderColor(final String value) {
// jdiAssert(element().boarderColor(), Matchers.equalTo(value));
// return this;
// }

@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
public PaginatorAssert selectedOptionColor(final AngularColors value) {
jdiAssert((element().selectedOptionColor()), Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
public PaginatorAssert selectedOptionColor(final String value) {
jdiAssert(element().selectedOptionColor(), Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name} has firstPageLabel='{0}'", isAssert = true)
public PaginatorAssert firstPageLabel(final String label) {
jdiAssert(element().firstPageLabel(), Matchers.equalTo(label));
Expand Down Expand Up @@ -145,7 +110,7 @@ public PaginatorAssert nextPageButtonDisabled() {

@JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true)
public PaginatorAssert itemPerPageSelectorDisabled() {
jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), Matchers.equalTo("true"),
jdiAssert(element().ItemPerPageSelect.attr("aria-disabled"), Matchers.equalTo("true"),
"item per page selector should be DISABLED");
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
import com.epam.jdi.light.angular.elements.common.Button;
import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.common.UIElement;
import com.epam.jdi.light.elements.complex.WebList;
import com.epam.jdi.light.elements.interfaces.base.HasColor;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.JDropdown;

import java.util.List;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.Integer.parseInt;
import static java.util.stream.Collectors.toList;

/**
* To see an example of Paginator web element please visit <a href="https://material.angular.io/components/paginator/overview">...</a>.
Expand All @@ -29,14 +23,13 @@ public class Paginator extends UIBaseElement<PaginatorAssert> implements HasColo
private static final String FIRST_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-first";
private static final String LAST_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-last";
private static final String PREVIOUS_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-previous";

private static final String NEXT_PAGE_BUTTON_LOCATOR = "button.mat-mdc-paginator-navigation-next";
private static final String BOARDER_LOCATOR = ".mdc-notched-outline__leading";
private static final String PAGINATOR_PAGE_SIZE_SECTION_LOCATOR = ".mat-mdc-paginator-page-size";
private static final String ITEM_PER_PAGE_SELECTOR_LOCATOR = "mat-select";
private static final String SELECT_PANEL_LOCATOR = "div.mat-mdc-select-panel";
private static final String ITEM_PER_PAGE_OPTIONS_LOCATOR = "mat-option";
private static final String ARIA_EXPANDED_ATTR = "aria-expanded";

@JDropdown(root = "mat-form-field.mat-mdc-form-field-type-mat-select", value = "mat-select", list = "//ancestor::body//mat-option")
public PaginatorSelector ItemPerPageSelect;
private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)");

@JDIAction("Set pattern for '{name}' range label")
Expand Down Expand Up @@ -91,53 +84,14 @@ public Button lastPageButton() {
return new Button().setCore(Button.class, core().find(LAST_PAGE_BUTTON_LOCATOR));
}

@JDIAction("Get item per page selector for '{name}'")
public UIElement itemPerPageSelector() {
return core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR);
}

// @JDIAction("Get item per page selector for '{name}'")
// public UIElement materiialSelector() {
// return new Dropdown().setCore(core().find(ITEM_PER_PAGE_SELECTOR_LOCATOR));
// }
@JDIAction("Get WebList of items per page options for '{name}'")
private WebList itemsPerPageOptionsWebList() {
return new WebList(By.cssSelector(ITEM_PER_PAGE_OPTIONS_LOCATOR));
}

@JDIAction("Get options for '{name}'")
public List<Integer> options() {
expandItemPerPageOptions();
final List<Integer> collect = itemsPerPageOptionsWebList().values().stream().map(Integer::parseInt).collect(toList());
collapseItemPerPageOptions();
return collect;
}

@JDIAction("Expand options for '{name}'")
private void expandItemPerPageOptions() {
if (itemPerPageSelector().attr(ARIA_EXPANDED_ATTR).equals("false")) {
itemPerPageSelector().click();
}
}

@JDIAction("Collapse items per page options for '{name}'")
private void collapseItemPerPageOptions() {
if (itemPerPageSelector().attr(ARIA_EXPANDED_ATTR).equals("true")) {
UIElement uiElement = new UIElement(By.cssSelector(SELECT_PANEL_LOCATOR));
Point pointOutsidePanel = new Point(uiElement.core().getRect().getWidth() + 2, uiElement.core().getRect().getHeight() + 2);
uiElement.core().click(pointOutsidePanel.getX(), pointOutsidePanel.getY());
}
}

@JDIAction("Select items per page option '{0}' for '{name}'")
public void selectItemPerPageOption(int number) {
expandItemPerPageOptions();
itemsPerPageOptionsWebList().select(String.valueOf(number));
ItemPerPageSelect.select(" " + number + " ");
}

@JDIAction("Get selected option for '{name}'")
public int selected() {
return parseInt(itemPerPageSelector().getText());
return parseInt(ItemPerPageSelect.selected());
}

@JDIAction("Get range for '{name}'")
Expand All @@ -161,30 +115,30 @@ public String color() {
if (core().hasAttribute("color")) {
return core().attr("color");
}
expandItemPerPageOptions();
ItemPerPageSelect.expand();
final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color");
collapseItemPerPageOptions();
ItemPerPageSelect.close();
return cssValue;
}

@JDIAction("Get color for selected value in the list of options for '{name}'")
public String selectedOptionColor() {
expandItemPerPageOptions();
String cssValue = selectedOptionFromItemsPerPageList().find("span").getCssValue("COLOR_ATT");
collapseItemPerPageOptions();
return cssValue;
}
// @JDIAction("Get color for selected value in the list of options for '{name}'")
// public String selectedOptionColor() {
// expandItemPerPageOptions();
// String cssValue = selectedOptionFromItemsPerPageList().find("span").getCssValue("COLOR_ATT");
// collapseItemPerPageOptions();
// return cssValue;
// }

@JDIAction("Get selected option from items per page list for '{name}'")
private UIElement selectedOptionFromItemsPerPageList() {
return itemsPerPageOptionsWebList().stream()
.filter(el -> el
.attr("aria-selected").equals("true"))
.findFirst()
.orElseThrow(
() -> new NoSuchElementException("No element with attribute aria-selected = true")
);
}
// @JDIAction("Get selected option from items per page list for '{name}'")
// private UIElement selectedOptionFromItemsPerPageList() {
// return itemsPerPageOptionsWebList().stream()
// .filter(el -> el
// .attr("aria-selected").equals("true"))
// .findFirst()
// .orElseThrow(
// () -> new NoSuchElementException("No element with attribute aria-selected = true")
// );
// }

@JDIAction("Get '{name}' firstPageLabel")
public String lastPageLabel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.epam.jdi.light.angular.elements.complex;

import com.epam.jdi.light.elements.complex.dropdown.Dropdown;

import static org.openqa.selenium.Keys.ESCAPE;

public class PaginatorSelector extends Dropdown {
@Override
public void close() {
if (isExpanded()) {
press(ESCAPE);
}
}

@Override
public boolean isExpanded() {
return expander().attr("aria-expanded").equals("true");
}
}

0 comments on commit be4ca55

Please sign in to comment.