Skip to content

Commit

Permalink
Merge pull request #5409 from jdi-testing/master
Browse files Browse the repository at this point in the history
sync master
  • Loading branch information
pnatashap authored Mar 26, 2024
2 parents 62761d2 + 4a0f36a commit b35b3cb
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 79 deletions.
4 changes: 2 additions & 2 deletions jdi-light-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.16.1</version>
<version>4.18.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.4</version>
<version>5.7.0</version>
<exclusions>
<exclusion>
<groupId>com.github.docker-java</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.epam.jdi.light.elements.interfaces.base;

import com.epam.jdi.light.common.JDIAction;

import java.net.MalformedURLException;
import java.net.URL;

import static com.epam.jdi.light.common.Exceptions.runtimeException;
import static com.jdiai.tools.LinqUtils.safeException;

public interface HasLink extends ICoreElement {
@JDIAction("Get if there is link inside the button")
default boolean hasLink() {
return core().hasAttribute("href");
}

@JDIAction("Get '{name}' reference")
default String ref() {
return core().attr("href");
}

@JDIAction("Get '{name}' reference as URL")
default URL url() {
try {
return new URL(ref());
} catch (MalformedURLException ex) {
throw runtimeException(safeException(ex));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

public class CookiesTests implements TestsInit {
@Test
@Test(enabled = false)
public void cookiesTest() {
Set<Cookie> savedCookies = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.interfaces.base.HasClick;
import com.epam.jdi.light.elements.interfaces.base.HasLink;
import com.epam.jdi.light.elements.interfaces.base.HasValue;
import com.epam.jdi.light.elements.interfaces.common.IsText;
import com.epam.jdi.light.ui.html.asserts.LinkAssert;
Expand All @@ -19,19 +20,8 @@
* Email: [email protected]; Skype: roman.iovlev
*/
public class Link extends UIBaseElement<LinkAssert>
implements HasValue, HasClick, IsText {
implements HasValue, HasClick, IsText, HasLink {
// region Actions

@JDIAction(value = "Get '{name}' reference", level = DEBUG)
public String ref() { return core().attr("href"); }

public URL url() {
try {
return new URL(ref());
} catch (MalformedURLException ex) {
throw runtimeException(safeException(ex));
}
}
@JDIAction(value = "Get '{name}' image alt", level = DEBUG)
public String alt() { return core().attr("alt"); }
// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ public class ChipsPage extends WebPage {
@UI("#lastDeleteInfo")
public static Text lastDeleteBasicInfo;

// @todo #5297 Fix locator, it is not stable
@UI("//h2[text()='Outlined Chips']/following-sibling::div/div/div[contains(@class, 'MuiChip-root')]")
public static List<Chip> outlinedChips;

// @todo #5297 Fix to css locator
@UI("//a[contains(@class, 'MuiChip-root')]")
@UI("a.MuiChip-root")
public static List<Chip> linkChips;

@UI("#lastOutlinedClickInfo")
Expand All @@ -32,7 +27,7 @@ public class ChipsPage extends WebPage {
@UI("#lastOutlinedDeleteInfo")
public static Text lastDeleteOutlinedInfo;

@UI("//h2[text()='Chip array']/following-sibling::div//div[contains(@class, 'MuiChip-root')]")
@UI("ul.MuiPaper-root div.MuiChip-root")
public static List<Chip> arrayChips;

@UI("#lastChipArrayClickInfo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.epam.jdi.light.material.elements.displaydata.Chip;
import io.github.epam.TestsInit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static io.github.com.StaticSite.chipsPage;
Expand All @@ -15,7 +15,7 @@ public class ChipTests extends TestsInit {

static final String BASIC_CLICK_TEXT = "You clicked on:";

@BeforeMethod
@BeforeClass
public void beforeTest() {
chipsPage.open();
chipsPage.isOpened();
Expand Down Expand Up @@ -61,7 +61,7 @@ public void linkTest() {
chip.show();
chip.is().displayed().and().link().and().clickable();
chip.label().has().text(text);
chip.has().href(href);
chip.has().ref(href);
chip.click();
chip.is().notVisible();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ChipAssert clickable() {
*/
@JDIAction(value = "Assert that '{name}' is a link", isAssert = true)
public ChipAssert link() {
jdiAssert(element().isLink(), Matchers.is(true), "Chip is not a link");
jdiAssert(element().hasLink(), Matchers.is(true), "Chip is not a link");
return this;
}

Expand All @@ -52,8 +52,8 @@ public ChipAssert link() {
* @return this {@link ChipAssert} instance
*/
@JDIAction(value = "Assert that '{name}' has href '{0}'", isAssert = true)
public ChipAssert href(String href) {
jdiAssert(element().href(), Matchers.is(href));
public ChipAssert ref(String href) {
jdiAssert(element().ref(), Matchers.is(href));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.epam.jdi.light.elements.common.Label;
import com.epam.jdi.light.elements.interfaces.base.HasClick;
import com.epam.jdi.light.elements.interfaces.base.HasLabel;
import com.epam.jdi.light.elements.interfaces.base.HasLink;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.material.asserts.displaydata.ChipAssert;
import com.epam.jdi.light.material.interfaces.CanBeDisabled;
Expand All @@ -19,7 +20,7 @@
* @see <a href="https://v4.mui.com/components/chips/">Chip MUI documentation</a>
* @see <a href="https://jdi-testing.github.io/jdi-light/material">MUI test page</a>
*/
public class Chip extends UIBaseElement<ChipAssert> implements HasClick, CanBeDisabled, HasLabel, HasColor {
public class Chip extends UIBaseElement<ChipAssert> implements HasClick, CanBeDisabled, HasLabel, HasColor, HasLink {

/**
* Label that represents the text over element.
Expand Down Expand Up @@ -57,9 +58,10 @@ public Label label() {
* @return href as {@link String}
* @throws RuntimeException if the element is not a link
*/
@Override
@JDIAction("Get '{name}' href")
public String href() {
if (isLink()) {
public String ref() {
if (hasLink()) {
return core().attr("href");
} else {
throw runtimeException("Element is not a link");
Expand Down Expand Up @@ -100,16 +102,6 @@ public boolean isDeletable() {
return core().hasClass("MuiChip-deletable") && deleteIcon.isDisplayed();
}

/**
* Checks if the chip is a link or not.
*
* @return {@code true} if the chip is a link, otherwise {@code false}
*/
@JDIAction("Check that '{name}' is a link")
public boolean isLink() {
return core().hasAttribute("href") && core().getTagName().equals("a");
}

@Override
public ChipAssert is() {
return new ChipAssert().set(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.epam.jdi.light.elements.common.UIElement;
import io.github.com.enums.Colors;
import io.github.epam.TestsInit;
import org.apache.commons.lang3.RandomUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -32,7 +33,7 @@ public void before() {
paginationPage.checkOpened();
}

@Test(description = "Test checks circle pagination components: size, values, theme, arial label")
@Test(description = "Test checks circle pagination components: size, values, theme")
public void circlePaginationTest() {
List<String> circlePages = asList("1", "2", "3", "4");
circlePagination.has().size(4);
Expand All @@ -49,10 +50,9 @@ public void circlePaginationTest() {
circlePagination.is().atEnd();
circlePagination.is().circle();
circlePagination.has().lightTheme();
circlePagination.has().currentPageAriaLabel();
circlePagination.has().nextAriaLabel();
circlePagination.has().previousAriaLabel();
circlePagination.has().pageAriaLabel();
circlePagination.has().currentPageAriaLabel("Current Page");
circlePagination.has().nextAriaLabel("Next page");
circlePagination.has().previousAriaLabel("Previous page");
}

@Test(description = "Test checks icons pagination components: size, values, icons")
Expand All @@ -62,12 +62,14 @@ public void iconsPaginationTest() {
iconsPagination.is().atStart();
iconsPagination.has().values(asList("1", "2", "3", "4"));

for (UIElement button : iconsPagination.list()) {
button.click();
iconsPagination.has().selected(button.getText());
iconsPagination.has().selected(Integer.parseInt(button.getText()));
iconsPagination.has().value(button.getText());
}
int btn = RandomUtils.nextInt(1, iconsPagination.list().size() + 1);
UIElement button = iconsPagination.get(btn);
button.click();
iconsPagination.has().selected(button.getText());
iconsPagination.has().selected(btn);
iconsPagination.has().value(button.getText());

iconsPagination.select("4");
iconsPagination.is().atEnd();
iconsPagination.is().notCircle();
iconsPagination.has().previousIcon("mdi-menu-left");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
public class PaginationAssert extends UISelectAssert<PaginationAssert, Pagination>
implements ThemeAssert<PaginationAssert, Pagination> {

// @todo #5048 Check this constants, looks like should be refactored
private static final String DEFAULT_CURRENT_PAGE_ARIA_LABEL = "Current Page";
private static final String DEFAULT_PREVIOUS_ARIA_LABEL = "Previous page";
private static final String DEFAULT_NEXT_ARIA_LABEL = "Next page";
private static final String DEFAULT_PAGE_ARIA_LABEL = "Goto Page";
private static final String ITEM_CLASS_SELECTED = "v-pagination__item--active";

@JDIAction(value = "Assert that '{name}' at the start", isAssert = true)
public PaginationAssert atStart() {
jdiAssert(element().isStart(), Matchers.is(true), "Pagination is not at start");
Expand All @@ -31,7 +24,6 @@ public PaginationAssert atEnd() {
return this;
}

// @todo #5048 Check the meaning of the method, refactor if needed
@JDIAction(value = "Assert that '{name}' is circle", isAssert = true)
public PaginationAssert circle() {
jdiAssert(element().isCircle(), Matchers.is(true), "Pagination is not circle");
Expand All @@ -45,23 +37,23 @@ public PaginationAssert notCircle() {
}

@JDIAction(value = "Assert that '{name}' aria-label has value '{0}'", isAssert = true)
public PaginationAssert currentPageAriaLabel() {
public PaginationAssert currentPageAriaLabel(String lbl) {
jdiAssert(element().activeButton().ariaLabel(),
Matchers.containsString(DEFAULT_CURRENT_PAGE_ARIA_LABEL));
Matchers.containsString(lbl));
return this;
}

@JDIAction(value = "Assert that '{name}' previous-aria-label has value '{0}'", isAssert = true)
public PaginationAssert previousAriaLabel() {
public PaginationAssert previousAriaLabel(String lbl) {
jdiAssert(element().leftNavigation().ariaLabel(),
Matchers.containsString(DEFAULT_PREVIOUS_ARIA_LABEL));
Matchers.containsString(lbl));
return this;
}

@JDIAction(value = "Assert that '{name}' next-aria-label has value '{0}'", isAssert = true)
public PaginationAssert nextAriaLabel() {
public PaginationAssert nextAriaLabel(String lbl) {
jdiAssert(element().rightNavigation().ariaLabel(),
Matchers.containsString(DEFAULT_NEXT_ARIA_LABEL));
Matchers.containsString(lbl));
return this;
}

Expand All @@ -79,18 +71,6 @@ public PaginationAssert previousIcon(String icon) {
return this;
}

// @todo #5048 remove area-label featured, as it is from accessability
@JDIAction(value = "Assert that '{name}' page-aria-label has value '{0}'", isAssert = true)
public PaginationAssert pageAriaLabel() {
element().list().foreach(button -> {
if (!button.hasClass(ITEM_CLASS_SELECTED)) {
jdiAssert(button.getAttribute("aria-label"),
Matchers.containsString(DEFAULT_PAGE_ARIA_LABEL));
}
});

return this;
}
@JDIAction(value = "Assert that '{name}' total visible has value '{0}'", isAssert = true)
public PaginationAssert totalVisible(Integer totalVisible) {
jdiAssert(element().totalVisible(), Matchers.is(totalVisible));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public UIElement moreButton() {

@JDIAction("Get '{name}' active button")
public VuetifyButton activeButton() {
return new VuetifyButton(core().find(".v-pagination__item--active"));
return new VuetifyButton(core().find("." + ITEM_CLASS_SELECTED));
}

@JDIAction("Get '{name}' total visible")
Expand Down

0 comments on commit b35b3cb

Please sign in to comment.