Skip to content

Commit

Permalink
#4926: Tests refactoring: Paginator element. JPaginator.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Jul 10, 2024
1 parent be4ca55 commit eee5937
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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.JPaginator;
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;
Expand All @@ -15,16 +16,16 @@ public class PaginatorPage extends NewAngularPage {
public static Input pageSizeOptionsInput;

@UI("//paginator-configurable-example//div[contains(text(),'List length:')]")
public static Text listLength;
public static Text listLengthMessage;
@UI("//paginator-configurable-example//div[contains(text(),'Page size:')]")
public static Text pageSize;
public static Text pageSizeMessage;
@UI("//paginator-configurable-example//div[contains(text(),'Page index:')]")
public static Text pageIndex;
public static Text pageIndexMessage;

@UI(".mat-mdc-tooltip")
public static Tooltip tooltip;

@UI("//paginator-configurable-example//mat-paginator")
@JPaginator(root = "//paginator-configurable-example//mat-paginator", rangeLabel = "^(\\d+)( . (\\d+))? .+ (\\d+)")
public static Paginator paginatorConfigurable;

@UI("//mat-paginator[contains(@id, 'paginator-show-first-last-buttons')]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void before() {
@Test(description = "The test checks item per page label")
public void labelPaginationTest() {
paginatorConfigurable.has().pageSizeLabel("Items per page:");
paginatorConfigurable.has().pageSizeLabelMatches(".*:");
}

@Test(description = "The test checks length and pageIndex for paginator")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public PaginatorAssert pageSizeLabel(final String label) {
return this;
}

@JDIAction(value = "Assert that '{name}' matches '{0}' label regEx", isAssert = true)
public PaginatorAssert pageSizeLabelMatches(final String regex) {
jdiAssert(element().itemPerPageLabel(), Matchers.matchesPattern(regex));
return this;
}

@JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true)
public PaginatorAssert itemsPerPageSelected(final int number) {
jdiAssert(element().selected(), Matchers.is(number));
Expand All @@ -26,8 +32,8 @@ public PaginatorAssert itemsPerPageSelected(final int number) {

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

}
Expand Down Expand Up @@ -110,7 +116,7 @@ public PaginatorAssert nextPageButtonDisabled() {

@JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true)
public PaginatorAssert itemPerPageSelectorDisabled() {
jdiAssert(element().ItemPerPageSelect.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
@@ -0,0 +1,15 @@
package com.epam.jdi.light.angular.elements.complex;

import com.epam.jdi.light.elements.pageobjects.annotations.locators.MarkupLocator;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD})
public @interface JPaginator {
@MarkupLocator String root() default "";
@MarkupLocator String rangeLabel() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
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.complex.ISetup;
import com.epam.jdi.light.elements.interfaces.base.HasColor;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.JDropdown;

import java.lang.reflect.Field;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.epam.jdi.light.elements.pageobjects.annotations.objects.FillFromAnnotationRules.fieldHasAnnotation;
import static java.lang.Integer.parseInt;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
* To see an example of Paginator web element please visit <a href="https://material.angular.io/components/paginator/overview">...</a>.
*/

public class Paginator extends UIBaseElement<PaginatorAssert> implements HasColor {
public class Paginator extends UIBaseElement<PaginatorAssert> implements HasColor, ISetup {
private static final String ITEM_PER_PAGE_LABEL_LOCATOR = ".mat-mdc-paginator-page-size-label";
private static final String ITEM_PER_PAGE_FIELD_LOCATOR = "mat-form-field";
private static final String RANGE_LABEL_LOCATOR = ".mat-mdc-paginator-range-label";
Expand All @@ -28,14 +32,9 @@ public class Paginator extends UIBaseElement<PaginatorAssert> implements HasColo
private static final String BOARDER_LOCATOR = ".mdc-notched-outline__leading";
private static final String PAGINATOR_PAGE_SIZE_SECTION_LOCATOR = ".mat-mdc-paginator-page-size";

@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")
public void setRangeLabelPattern(String regex) {
rangeLabelPattern = Pattern.compile(regex);
}
@JDropdown(root = "mat-form-field.mat-mdc-form-field-type-mat-select", value = "mat-select", list = "//ancestor::body//mat-option")
public PaginatorSelector itemPerPageSelect;

@Override
public PaginatorAssert is() {
Expand Down Expand Up @@ -86,12 +85,12 @@ public Button lastPageButton() {

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

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

@JDIAction("Get range for '{name}'")
Expand All @@ -115,31 +114,12 @@ public String color() {
if (core().hasAttribute("color")) {
return core().attr("color");
}
ItemPerPageSelect.expand();
itemPerPageSelect.expand();
final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color");
ItemPerPageSelect.close();
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 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() {
return core().attr("lastPageLabel");
Expand Down Expand Up @@ -182,4 +162,26 @@ private Matcher getMatcherForRange() {
}
return matcher;
}

protected boolean setupDone = false;

public Paginator setup(String root, String rangeLabel) {
if (isNotBlank(root)) {
base().setLocator(root);
}
if (isNotBlank(rangeLabel)) {
rangeLabelPattern = Pattern.compile(rangeLabel);
}
setupDone = true;
return this;
}

@Override
public void setup(Field field) {
if (!fieldHasAnnotation(field, JPaginator.class, Paginator.class)) {
return;
}
JPaginator j = field.getAnnotation(JPaginator.class);
setup(j.root(), j.rangeLabel());
}
}

0 comments on commit eee5937

Please sign in to comment.