Skip to content

Commit

Permalink
- refactoring: Snackbar element
Browse files Browse the repository at this point in the history
- Update test site: Snackbar element
  • Loading branch information
Aleksandr_Vorobev committed Jun 11, 2024
1 parent d87901b commit 35bfdb3
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -53,4 +54,7 @@ public class StaticSite {

@Url("slide_toggle")
public static SlideTogglePage slideTogglePage;

@Url("snack_bar")
public static SnackBarPage snackBarPage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,65 @@

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
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ public class SnackbarAssert extends UIAssert<SnackbarAssert, Snackbar> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<SnackbarAssert> {
protected UIElement message;
protected String messageLocator = "./span";

public class Snackbar extends UIBaseElement<SnackbarAssert> 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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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;
}
}
Loading

0 comments on commit 35bfdb3

Please sign in to comment.