diff --git a/jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java b/jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java
index a743f30d60..179221624b 100644
--- a/jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java
+++ b/jdi-light-angular-tests/src/main/java/io/github/com/pages/SnackBarPage.java
@@ -1,30 +1,39 @@
package io.github.com.pages;
import com.epam.jdi.light.angular.elements.complex.Snackbar;
+import com.epam.jdi.light.elements.complex.dropdown.Dropdown;
+import com.epam.jdi.light.elements.pageobjects.annotations.locators.JDropdown;
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 SnackBarPage extends AngularPage {
+ @UI("#snack-bar-custom-component-input")
+ public static TextField durationInput;
+
+ @UI("#snack-bar-custom-component-button")
+ public static Button showCustomSnackbarButton;
+
+ @UI("#snack-bar-custom-component")
+ public static Snackbar customSnackbar;
@UI("#snack-bar-message-input")
- public TextField messageInput;
+ public static TextField basicSnackbarMessageInput;
@UI("#snack-bar-action-input")
- public TextField actionInput;
+ public static TextField basicSnackbarActionInput;
@UI("#snack-bar-open-button")
- public Button openButton;
-
+ public static Button showBasicSnackbarButton;
@UI("//simple-snack-bar")
- public Snackbar basicSnackbar;
+ public static Snackbar snackbar;
- @UI("#snack-bar-custom-component-input")
- public TextField durationInput;
+ @JDropdown(root = "mat-form-field.mat-mdc-form-field-type-mat-select:has(#snack-bar-position-horizontal-select)", value = "span.mat-mdc-select-min-line", list = "//ancestor::body//mat-option")
+ public static Dropdown horizontalPositionDropdown;
- @UI("#snack-bar-custom-component-button")
- public Button customSnackbarOpenButton;
+ @JDropdown(root = "mat-form-field.mat-mdc-form-field-type-mat-select:has(#snack-bar-position-vertival-select)", value = "span.mat-mdc-select-min-line", list = "//ancestor::body//mat-option")
+ public static Dropdown verticalPositionDropdown;
- @UI("#snack-bar-custom-component")
- public Snackbar customSnackbar;
+ @UI("#snack-bar-position-open-button")
+ public static Button showPositionSnackbarButton;
}
diff --git a/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PositionAssert.java b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PositionAssert.java
new file mode 100644
index 0000000000..adda7368b4
--- /dev/null
+++ b/jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/PositionAssert.java
@@ -0,0 +1,24 @@
+package com.epam.jdi.light.angular.asserts;
+
+import com.epam.jdi.light.angular.elements.enums.Position;
+import com.epam.jdi.light.angular.elements.interfaces.HasPosition;
+import com.epam.jdi.light.asserts.generic.UIAssert;
+import com.epam.jdi.light.common.JDIAction;
+import org.hamcrest.Matchers;
+
+import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
+
+public abstract class PositionAssert, E extends HasPosition> extends UIAssert {
+
+ @JDIAction(value = "Assert that '{name}' has position '{0}'", isAssert = true)
+ public A position(String position) {
+ jdiAssert(element().position(), Matchers.is(Position.fromFullString(position)));
+ return (A) this;
+ }
+
+ @JDIAction(value = "Assert that '{name}' has position '{0}'", isAssert = true)
+ public A position(Position position) {
+ jdiAssert(element().position(), Matchers.is(position));
+ return (A) this;
+ }
+}
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 9e641d0ed3..c9df06655c 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
@@ -1,31 +1,52 @@
package com.epam.jdi.light.angular.asserts;
import com.epam.jdi.light.angular.elements.complex.Snackbar;
-import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
+import com.jdiai.tools.Timer;
+import com.jdiai.tools.func.JAction;
import org.hamcrest.Matchers;
import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
-public class SnackbarAssert extends UIAssert {
+public class SnackbarAssert extends PositionAssert {
@JDIAction(value = "Assert that '{name}' has message '{0}'", isAssert = true)
public SnackbarAssert message(String expected) {
- jdiAssert(element().messageText(), Matchers.containsString(expected));
+ jdiAssert(element().message()
+ .getText(), Matchers.containsString(expected));
return this;
}
- @JDIAction(value = "Assert that '{name}' has action icon", isAssert = true)
+ @JDIAction(value = "Assert that '{name}' has action '{0}'", isAssert = true)
+ public SnackbarAssert action(String expected) {
+ jdiAssert(element().action()
+ .getText(), Matchers.containsString(expected));
+ return this;
+ }
+
+ @JDIAction(value = "Assert that '{name}' has action button", isAssert = true)
public SnackbarAssert hasAction() {
- jdiAssert(element().actionIcon()
+ jdiAssert(element().action()
.isExist(), Matchers.is(true), "Action doesn't exist in snackbar");
return this;
}
- @JDIAction(value = "Assert that '{name}' has no action icon", isAssert = true)
+ @JDIAction(value = "Assert that '{name}' has no action button", isAssert = true)
public SnackbarAssert hasNoAction() {
- jdiAssert(element().actionIcon()
+ jdiAssert(element().action()
.isNotExist(), Matchers.is(true), "Action exists in snackbar");
return this;
}
+
+ @JDIAction(value = "Assert that '{name}' is visible during '{0}' seconds", isAssert = true)
+ public SnackbarAssert notHidden(int timeoutSec) {
+ JAction action = () -> {
+ element().base()
+ .timer()
+ .wait(() -> element().isDisplayed());
+ };
+ boolean result = new Timer(timeoutSec * 1000L).wait(action);
+ jdiAssert(result ? "displayed" : "hidden", Matchers.is("displayed"));
+ 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 570d4623fe..261adbcb0a 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
@@ -12,80 +12,34 @@
*/
public class Snackbar extends UIBaseElement implements HasPosition {
- @Deprecated
- private UIElement message;
- @Deprecated
- protected UIElement action;
- private String messageLocator = ".mat-mdc-snack-bar-label .mdc-snackbar__label";
- private String actionLocator = ".//button";
+ private static final String MESSAGE_LOCATOR = ".mat-mdc-snack-bar-label .mdc-snackbar__label";
+ private static final String ACTION_LOCATOR = ".//button";
+ private static final String OVERLAY_LOCATOR = "//ancestor::div[@class='cdk-global-overlay-wrapper']";
- @Deprecated
- public Snackbar() {
- message = new UIElement();
- message.core()
- .setLocator(messageLocator);
-
- action = new UIElement();
- 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();
+ public UIElement action() {
+ return core().find(ACTION_LOCATOR);
}
@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();
- }
-
- @Override
- public SnackbarAssert is() {
- return new SnackbarAssert().set(this);
+ public UIElement message() {
+ return core().find(MESSAGE_LOCATOR);
}
@Override
+ @JDIAction("Get '{name}' position")
public Position position() {
- return null;
+ return getPositionFromAttribute("style");
}
@Override
- public Position getPositionFromClass(final UIElement element, final String className) {
- return HasPosition.super.getPositionFromClass(element, className);
+ public Position getPositionFromAttribute(String attributeValue) {
+ return Position.fromFullString(core().find(OVERLAY_LOCATOR)
+ .attr(attributeValue));
}
@Override
- public Position getPositionFromAttribute(final String attributeValue) {
- return HasPosition.super.getPositionFromAttribute(attributeValue);
+ public SnackbarAssert is() {
+ return new SnackbarAssert().set(this);
}
}
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
index b8d392a5cd..71e012c2f7 100644
--- 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
@@ -13,19 +13,30 @@
* 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");
+ TOP("align-items: flex-start"),
+ BOTTOM("align-items: flex-end"),
+
+ START("justify-content: flex-start"),
+ CENTER("justify-content: center"),
+ END("justify-content: flex-end"),
+ LEFT("justify-content: flex-start"),
+ RIGHT("justify-content: flex-end"),
+
+ START_BOTTOM("justify-content: flex-start; align-items: flex-end;"),
+ CENTER_BOTTOM("justify-content: center; align-items: flex-end;"),
+ END_BOTTOM("justify-content: flex-end; align-items: flex-end;"),
+ LEFT_BOTTOM("justify-content: flex-start; align-items: flex-end;"),
+ RIGHT_BOTTOM("justify-content: flex-end; align-items: flex-end;"),
+
+ START_TOP("justify-content: flex-start; align-items: flex-start;"),
+
+ CENTER_TOP("justify-content: center; align-items: flex-start;"),
+
+ END_TOP("justify-content: flex-end; align-items: flex-start;"),
+
+ LEFT_TOP("justify-content: flex-start; align-items: flex-start;"),
+
+ RIGHT_TOP("justify-content: flex-end; align-items: flex-start;");
private final String value;
@@ -46,28 +57,28 @@ public static Position fromFullString(String text) {
}
return Arrays.stream(Position.values())
.filter(p -> StringUtils.containsAnyIgnoreCase(text, p.toString()))
- .max(Comparator.comparing(p -> p.toString().length()))
+ .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()));
+ 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("");
+ .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()));
+ 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)));
+ .orElseThrow(() -> runtimeException(String.format("No appropriate %s constant found for value '%s'", Position.class.getName(), positionClass)));
}
/**