Skip to content

Commit

Permalink
#4926: Tests refactoring: Paginator element. Color refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Jun 26, 2024
1 parent 4ccc554 commit 93aee34
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,11 @@ public void firstAndLastPageButtonPaginatorTest() {

@Test(description = "The test checks color theme of the paginators")
public void colorPaginatorTest() {
paginatorColorPrimary.has().colorTheme(PRIMARY)
.and().has().borderColor(PRIMARY)
.and().has().selectedOptionColor(PRIMARY);

paginatorColorPrimary.has().colorTheme("primary")
.and().has().borderColor("rgb(103, 58, 183)")
.and().has().selectedOptionColor("rgba(103, 58, 183, 1)");

paginatorColorWarn.has().colorTheme(WARN)
.and().has().borderColor(WARN)
.and().has().selectedOptionColor(WARN);

paginatorColorAccent.has().colorTheme(ACCENT)
.and().has().borderColor(ACCENT)
.and().has().selectedOptionColor(ACCENT);
paginatorColorPrimary.has().color(PRIMARY);
paginatorColorPrimary.has().color("primary");
paginatorColorWarn.has().color(WARN);
paginatorColorAccent.has().color(ACCENT);
paginatorConfigurable.has().color("rgb(103, 58, 183)");
}

@Test(description = "The test checks disabled paginator and disabled elements of the paginators")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,86 @@

import com.epam.jdi.light.angular.elements.complex.Paginator;
import com.epam.jdi.light.angular.elements.enums.AngularColors;
import com.epam.jdi.light.asserts.generic.ColorAssert;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
import org.hamcrest.Matchers;

import java.util.List;

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
import static org.hamcrest.Matchers.equalTo;

public class PaginatorAssert extends UIAssert<PaginatorAssert, Paginator> {
public class PaginatorAssert extends UIAssert<PaginatorAssert, Paginator> implements ColorAssert<PaginatorAssert, Paginator> {
@JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true)
public PaginatorAssert pageSizeLabel(final String label) {
jdiAssert(element().itemPerPageLabel(), equalTo(label));
jdiAssert(element().itemPerPageLabel(), Matchers.is(label));
return this;
}

@JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true)
public PaginatorAssert itemsPerPageSelected(final int number) {
jdiAssert(element().selected(), equalTo(number));
jdiAssert(element().selected(), Matchers.is(number));
return this;
}

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

}

@JDIAction(value = "Assert that range is '{0}' for '{name}'", isAssert = true)
public PaginatorAssert rangeLabel(final String label) {
jdiAssert(element().range(), equalTo(label));
jdiAssert(element().range(), Matchers.equalTo(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()), equalTo(value));
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 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 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(), 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()), equalTo(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(), equalTo(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(), equalTo(label));
jdiAssert(element().firstPageLabel(), Matchers.equalTo(label));
return this;
}

@JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true)
public PaginatorAssert lastPageLabel(final String label) {
jdiAssert(element().lastPageLabel(), equalTo(label));
jdiAssert(element().lastPageLabel(), Matchers.equalTo(label));
return this;
}

Expand All @@ -105,13 +105,13 @@ public PaginatorAssert firstLastButtonsShown(boolean value) {
*/
@JDIAction(value = "Assert that '{name}' has current page index of {0}", isAssert = true)
public PaginatorAssert pageIndexCurrent(int pageIndex) {
jdiAssert(element().pageIndexCurrent(), equalTo(pageIndex));
jdiAssert(element().pageIndexCurrent(), Matchers.equalTo(pageIndex));
return this;
}

@JDIAction(value = "Assert that '{name}' has {0} total number of items that are being paginated", isAssert = true)
public PaginatorAssert totalNumberOfPaginatedItems(int length) {
jdiAssert(element().totalNumberOfPaginatedItems(), equalTo(length));
jdiAssert(element().totalNumberOfPaginatedItems(), Matchers.equalTo(length));
return this;
}

Expand Down Expand Up @@ -145,7 +145,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"), equalTo("true"),
jdiAssert(element().itemPerPageSelector().attr("aria-disabled"), Matchers.equalTo("true"),
"item per page selector should be DISABLED");
return this;
}
Expand All @@ -163,5 +163,18 @@ public PaginatorAssert lastPageButtonDisplayed(boolean value) {
value ? "last page button should be DISPLAYED" : "last page button should be HIDDEN");
return this;
}

@JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true)
public PaginatorAssert color(AngularColors expectedColor) {
jdiAssert(element().color(), Matchers.equalTo(expectedColor.getType()));
return this;
}

@Override
@JDIAction(value = "Assert that '{name}' color is '{0}'", isAssert = true)
public PaginatorAssert color(String expectedColor) {
jdiAssert(element().color(), Matchers.equalTo(expectedColor));
return this;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;

Expand All @@ -21,7 +22,7 @@
* 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> {
public class Paginator extends UIBaseElement<PaginatorAssert> implements HasColor {
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 @@ -35,7 +36,6 @@ public class Paginator extends UIBaseElement<PaginatorAssert> {
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";
private static final String COLOR_ATT = "color";

private Pattern rangeLabelPattern = Pattern.compile("^(\\d+)( . (\\d+))? .+ (\\d+)");

Expand Down Expand Up @@ -96,6 +96,10 @@ 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));
Expand Down Expand Up @@ -151,24 +155,22 @@ public void nextPage() {
nextButton().click();
}

@JDIAction("Get color theme for '{name}'")
public String colorTheme() {
return core().hasAttribute(COLOR_ATT) ? core().attr(COLOR_ATT) : "primary";
}

@JDIAction("Get color of selector`s boarder for '{name}'")
public String boarderColor() {
@Override
@JDIAction("Get '{name}' color")
public String color() {
if (core().hasAttribute("color")) {
return core().attr("color");
}
expandItemPerPageOptions();
final String cssValue = core().find(ITEM_PER_PAGE_FIELD_LOCATOR).find(BOARDER_LOCATOR).getCssValue("border-color");
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);
String cssValue = selectedOptionFromItemsPerPageList().find("span").getCssValue("COLOR_ATT");
collapseItemPerPageOptions();
return cssValue;
}
Expand Down

0 comments on commit 93aee34

Please sign in to comment.