diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java index 0c329d4132..7870c37d20 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/StaticSite.java @@ -5,15 +5,16 @@ import io.github.com.pages.AngularPage; import io.github.com.pages.AutocompletePage; import io.github.com.pages.BadgePage; -import io.github.com.pages.InputPage; import io.github.com.pages.ButtonTogglePage; import io.github.com.pages.ButtonsPage; import io.github.com.pages.CheckBoxPage; import io.github.com.pages.DividerPage; +import io.github.com.pages.InputPage; import io.github.com.pages.ProgressBarPage; import io.github.com.pages.ProgressSpinnerPage; import io.github.com.pages.RadioButtonPage; import io.github.com.pages.SlideTogglePage; +import io.github.com.pages.SnackBarPage; @JSite("https://jdi-testing.github.io/jdi-light/angular-page/#/") public class StaticSite { @@ -37,10 +38,10 @@ public class StaticSite { public static BadgePage badgePage; @Url("buttons_toggle") - public static ButtonTogglePage buttonTogglePage; + public static ButtonTogglePage buttonTogglePage; @Url("divider") - public static DividerPage dividerPage; + public static DividerPage dividerPage; @Url("autocompletes") public static AutocompletePage autocompletePage; @@ -53,4 +54,7 @@ public class StaticSite { @Url("slide_toggle") public static SlideTogglePage slideTogglePage; + + @Url("snack_bar") + public static SnackBarPage snackBarPage; } diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java index 776bc1c465..690b23fdd7 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/AngularPage.java @@ -7,7 +7,6 @@ import com.epam.jdi.light.ui.html.elements.common.Icon; import io.github.com.pages.sections.GridListSection; import io.github.com.pages.sections.ListSection; -import io.github.com.pages.sections.SnackbarSection; import io.github.com.pages.sections.TabGroupSection; import io.github.com.pages.sections.TableSection; @@ -22,7 +21,6 @@ public class AngularPage extends WebPage { public static Dialog dialog; public static ListSection listSection; public static GridListSection gridListSection; - public static SnackbarSection snackbarSection; public static TabGroupSection tabsSection; public static TableSection tableSection; } diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/SnackbarSection.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java similarity index 84% rename from jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/SnackbarSection.java rename to jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java index 6583b5e363..a743f30d60 100644 --- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/sections/SnackbarSection.java +++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java @@ -1,12 +1,11 @@ -package io.github.com.pages.sections; +package io.github.com.pages; import com.epam.jdi.light.angular.elements.complex.Snackbar; -import com.epam.jdi.light.elements.composite.Section; import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI; import com.epam.jdi.light.ui.html.elements.common.Button; import com.epam.jdi.light.ui.html.elements.common.TextField; -public class SnackbarSection extends Section { +public class SnackBarPage extends AngularPage { @UI("#snack-bar-message-input") public TextField messageInput; diff --git a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SnackbarTests.java b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SnackbarTests.java index 5fa5fcd158..51ec1397c6 100644 --- a/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SnackbarTests.java +++ b/jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/SnackbarTests.java @@ -2,55 +2,54 @@ import com.jdiai.tools.func.JAction; import io.github.epam.TestsInit; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import static io.github.com.StaticSite.angularPage; -import static io.github.com.pages.AngularPage.snackbarSection; -import static io.github.epam.site.steps.States.shouldBeLoggedIn; +import static com.jdiai.tools.Timer.waitCondition; +import static io.github.com.StaticSite.snackBarPage; + -// TODO Move to the new page -@Ignore public class SnackbarTests extends TestsInit { private static final String MESSAGE = "Test Message"; private static final String ACTION = "Test Action"; - @BeforeMethod + @BeforeClass public void before() { - shouldBeLoggedIn(); - angularPage.shouldBeOpened(); + snackBarPage.open(); + waitCondition(() -> snackBarPage.isOpened()); + snackBarPage.checkOpened(); } @Test public void checkBasicSnackbarTest() { - snackbarSection.messageInput.setValue(MESSAGE); - snackbarSection.actionInput.setValue(ACTION); - snackbarSection.openButton.click(); + snackBarPage.messageInput.setValue(MESSAGE); + snackBarPage.actionInput.setValue(ACTION); + snackBarPage.openButton.click(); - snackbarSection.basicSnackbar.is().displayed(); - snackbarSection.basicSnackbar.has().message(MESSAGE); - snackbarSection.basicSnackbar.has().action(ACTION); + snackBarPage.basicSnackbar.is().displayed(); + snackBarPage.basicSnackbar.has().message(MESSAGE); + snackBarPage.basicSnackbar.actionIcon().has().text(ACTION); } @Test public void checkSnackbarClickActionDismissTest() { - snackbarSection.messageInput.setValue(MESSAGE); - snackbarSection.actionInput.setValue(ACTION); - snackbarSection.openButton.click(); + snackBarPage.messageInput.setValue(MESSAGE); + snackBarPage.actionInput.setValue(ACTION); + snackBarPage.openButton.click(); - snackbarSection.basicSnackbar.clickAction(); - snackbarSection.basicSnackbar.is().disappear(); + snackBarPage.basicSnackbar.actionIcon().click(); + snackBarPage.basicSnackbar.is().disappear(); } @Test public void checkSnackbarWithNoActionTest() { - snackbarSection.messageInput.setValue(MESSAGE); - snackbarSection.actionInput.setValue(""); - snackbarSection.openButton.click(); + snackBarPage.messageInput.setValue(MESSAGE); + snackBarPage.actionInput.setValue(""); + snackBarPage.openButton.click(); - snackbarSection.basicSnackbar.has().action(); + snackBarPage.basicSnackbar.has().shown(); + snackBarPage.basicSnackbar.actionIcon().has().notAppear(); } @Test @@ -58,13 +57,10 @@ public void checkSnackbarDurationTest() { final int DURATION = 5; JAction action = () -> { - snackbarSection.customSnackbar.base().timer().wait(() -> snackbarSection.customSnackbar.isDisplayed()); - snackbarSection.customSnackbar.base().timer().wait(() -> snackbarSection.customSnackbar.isHidden()); + snackBarPage.customSnackbar.base().timer().wait(() -> snackBarPage.customSnackbar.isDisplayed()); + snackBarPage.customSnackbar.base().timer().wait(() -> snackBarPage.customSnackbar.isHidden()); }; - - snackbarSection.durationInput.setValue(String.valueOf(DURATION)); - snackbarSection.customSnackbarOpenButton.click(); - - //duration(DURATION, 1000, action); + snackBarPage.durationInput.setValue(String.valueOf(DURATION)); + snackBarPage.customSnackbarOpenButton.click(); } -} +} \ No newline at end of file diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SnackbarAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SnackbarAssert.java index 2f2d0da173..9e641d0ed3 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SnackbarAssert.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/SnackbarAssert.java @@ -11,19 +11,21 @@ public class SnackbarAssert extends UIAssert { @JDIAction(value = "Assert that '{name}' has message '{0}'", isAssert = true) public SnackbarAssert message(String expected) { - jdiAssert(element().getMessageText(), Matchers.is(expected)); + jdiAssert(element().messageText(), Matchers.containsString(expected)); return this; } - @JDIAction(value = "Assert that '{name}' has no action", isAssert = true) - public SnackbarAssert action() { - jdiAssert(element().isActionDisplayed(), Matchers.is(false), "ERROR MESSAGE IS REQUIRED"); + @JDIAction(value = "Assert that '{name}' has action icon", isAssert = true) + public SnackbarAssert hasAction() { + jdiAssert(element().actionIcon() + .isExist(), Matchers.is(true), "Action doesn't exist in snackbar"); return this; } - @JDIAction(value = "Assert that '{name}' has action {0}", isAssert = true) - public SnackbarAssert action(String expected) { - jdiAssert(element().getActionText(), Matchers.is(expected)); + @JDIAction(value = "Assert that '{name}' has no action icon", isAssert = true) + public SnackbarAssert hasNoAction() { + jdiAssert(element().actionIcon() + .isNotExist(), Matchers.is(true), "Action exists in snackbar"); return this; } } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Snackbar.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Snackbar.java index c72973dfb0..570d4623fe 100644 --- a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Snackbar.java +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/Snackbar.java @@ -1,6 +1,8 @@ package com.epam.jdi.light.angular.elements.complex; import com.epam.jdi.light.angular.asserts.SnackbarAssert; +import com.epam.jdi.light.angular.elements.enums.Position; +import com.epam.jdi.light.angular.elements.interfaces.HasPosition; import com.epam.jdi.light.common.JDIAction; import com.epam.jdi.light.elements.base.UIBaseElement; import com.epam.jdi.light.elements.common.UIElement; @@ -9,36 +11,59 @@ * To see an example of Snackbar web element please visit https://material.angular.io/components/snack-bar/overview. */ -public class Snackbar extends UIBaseElement { - protected UIElement message; - protected String messageLocator = "./span"; - +public class Snackbar extends UIBaseElement implements HasPosition { + @Deprecated + private UIElement message; + @Deprecated protected UIElement action; - protected String actionLocator = ".//button"; + private String messageLocator = ".mat-mdc-snack-bar-label .mdc-snackbar__label"; + private String actionLocator = ".//button"; + @Deprecated public Snackbar() { message = new UIElement(); - message.core().setLocator(messageLocator); + message.core() + .setLocator(messageLocator); action = new UIElement(); - action.core().setLocator(actionLocator); + action.core() + .setLocator(actionLocator); } + @Deprecated @JDIAction("Get '{name}' message") public String getMessageText() { return message.getValue(); } + @Deprecated @JDIAction("Get '{name}' action") public String getActionText() { return action.getValue(); } + @JDIAction("Get '{name}' message") + public String messageText() { + return message.getValue(); + } + + @JDIAction("Get '{name}' action") + public String actionText() { + return action.getValue(); + } + + @Deprecated @JDIAction("Click '{name}' action") public void clickAction() { action.click(); } + @JDIAction("Click '{name}' action") + public UIElement actionIcon() { + return this.action; + } + + @Deprecated @JDIAction("Is '{name}' action displayed") public boolean isActionDisplayed() { return action.isDisplayed(); @@ -48,4 +73,19 @@ public boolean isActionDisplayed() { public SnackbarAssert is() { return new SnackbarAssert().set(this); } + + @Override + public Position position() { + return null; + } + + @Override + public Position getPositionFromClass(final UIElement element, final String className) { + return HasPosition.super.getPositionFromClass(element, className); + } + + @Override + public Position getPositionFromAttribute(final String attributeValue) { + return HasPosition.super.getPositionFromAttribute(attributeValue); + } } diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/Position.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/Position.java new file mode 100644 index 0000000000..b8d392a5cd --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/enums/Position.java @@ -0,0 +1,82 @@ +package com.epam.jdi.light.angular.elements.enums; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + +import static com.epam.jdi.light.common.Exceptions.runtimeException; + +/** + * Contains named constants representing element positions. + * Each constant includes information about its string representation. + */ +public enum Position { + TOP("top"), + BOTTOM("bottom"), + LEFT("left"), + RIGHT("right"), + END("end"), + START("start"), + TOP_RIGHT("topRight"), + TOP_LEFT("topLeft"), + TOP_CENTER("topCenter"), + BOTTOM_CENTER("bottomCenter"), + BOTTOM_RIGHT("bottomRight"), + BOTTOM_LEFT("bottomLeft"), + STATIC("Static"); + + private final String value; + + Position(String value) { + this.value = value.toLowerCase(); + } + + /** + * Gets {@link Position} full named constant from the given string. + * + * @param text String value for position + * @return position as {@link Position} + * @throws RuntimeException if no appropriate constant found for given value + */ + public static Position fromFullString(String text) { + if (StringUtils.isBlank(text)) { + throw runtimeException(String.format("%s: input string can't be empty", Position.class.getName())); + } + return Arrays.stream(Position.values()) + .filter(p -> StringUtils.containsAnyIgnoreCase(text, p.toString())) + .max(Comparator.comparing(p -> p.toString().length())) + .orElseThrow(() -> runtimeException(String.format("No appropriate %s constant found for value '%s'", Position.class.getName(), text))); + } + + public static Position fromClasses(List classes, String stylePrefix, String stylePostfix) { + if (classes == null || classes.isEmpty() || StringUtils.isBlank(stylePrefix)) { + throw runtimeException(String.format("%s: input string can't be empty", + Position.class.getName())); + } + String positionClass = classes.stream() + .filter(c -> StringUtils.containsAnyIgnoreCase(c, stylePrefix)) + .map(c -> c.replaceFirst(stylePrefix, "").replace(stylePostfix, "")) + .findFirst().orElse(""); + if (StringUtils.isBlank(positionClass)) { + throw runtimeException(String.format("%s: input string can't be empty", + Position.class.getName())); + } + return Arrays.stream(Position.values()) + .filter(p -> StringUtils.equalsIgnoreCase(positionClass, p.toString())) + .findAny() + .orElseThrow(() -> runtimeException(String.format("No appropriate %s constant found for value '%s'", + Position.class.getName(), positionClass))); + } + + /** + * Gets string representation of element position in CamelCase (e.g. "bottom", "bottomLeft"). + * + * @return element position as {@link String} + */ + @Override + public String toString() { + return value; + } +} diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/HasPosition.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/HasPosition.java new file mode 100644 index 0000000000..0467334822 --- /dev/null +++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/interfaces/HasPosition.java @@ -0,0 +1,35 @@ +package com.epam.jdi.light.angular.elements.interfaces; + +import com.epam.jdi.light.angular.elements.enums.Position; +import com.epam.jdi.light.elements.common.UIElement; +import com.epam.jdi.light.elements.interfaces.base.ICoreElement; +import org.apache.commons.lang3.StringUtils; + +public interface HasPosition extends ICoreElement { + + Position position(); + + /** + * Gets {@link Position} named constant from the given class name. + * + * @param className String class name to find position + * @param element UIElement to check + * @return position as {@link Position} + */ + default Position getPositionFromClass(UIElement element, String className) { + return Position.fromFullString(element.classes().stream() + .filter(c -> StringUtils.startsWith(c, className)) + .map(c -> c.replace(className, "")) + .findFirst().orElse("")); + } + + /** + * Gets {@link Position} named constant from the given attribute value. + * + * @param attributeValue String attribute value to find position + * @return position as {@link Position} + */ + default Position getPositionFromAttribute(String attributeValue) { + return Position.fromFullString(core().attr(attributeValue)); + } +}