Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4942 refactoring: Snackbar element #5534

Open
wants to merge 12 commits into
base: angular_rework_development
Choose a base branch
from
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
@@ -0,0 +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 static TextField basicSnackbarMessageInput;

@UI("#snack-bar-action-input")
public static TextField basicSnackbarActionInput;

@UI("#snack-bar-open-button")
public static Button showBasicSnackbarButton;
@UI("//simple-snack-bar")
public static Snackbar snackbar;

@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;

@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-position-open-button")
public static Button showPositionSnackbarButton;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,70 +1,122 @@
package io.github.epam.angular.tests.elements.complex;

import com.jdiai.tools.func.JAction;
import com.epam.jdi.light.angular.elements.enums.Position;
import io.github.epam.TestsInit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Ignore;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
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.epam.jdi.light.angular.elements.enums.Position.CENTER_BOTTOM;
import static com.epam.jdi.light.angular.elements.enums.Position.CENTER_TOP;
import static com.epam.jdi.light.angular.elements.enums.Position.LEFT_BOTTOM;
import static com.epam.jdi.light.angular.elements.enums.Position.LEFT_TOP;
import static com.epam.jdi.light.angular.elements.enums.Position.RIGHT_BOTTOM;
import static com.epam.jdi.light.angular.elements.enums.Position.RIGHT_TOP;
import static com.epam.jdi.light.elements.base.Conditions.hidden;
import static com.epam.jdi.light.elements.base.Conditions.visible;
import static com.jdiai.tools.Timer.waitCondition;
import static io.github.com.StaticSite.snackBarPage;
import static io.github.com.pages.SnackBarPage.basicSnackbarActionInput;
import static io.github.com.pages.SnackBarPage.basicSnackbarMessageInput;
import static io.github.com.pages.SnackBarPage.customSnackbar;
import static io.github.com.pages.SnackBarPage.durationInput;
import static io.github.com.pages.SnackBarPage.horizontalPositionDropdown;
import static io.github.com.pages.SnackBarPage.showBasicSnackbarButton;
import static io.github.com.pages.SnackBarPage.showCustomSnackbarButton;
import static io.github.com.pages.SnackBarPage.showPositionSnackbarButton;
import static io.github.com.pages.SnackBarPage.snackbar;
import static io.github.com.pages.SnackBarPage.verticalPositionDropdown;

// 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();

snackbarSection.basicSnackbar.is().displayed();
snackbarSection.basicSnackbar.has().message(MESSAGE);
snackbarSection.basicSnackbar.has().action(ACTION);
public void basicSnackbarTest() {
basicSnackbarMessageInput.setValue(MESSAGE);
basicSnackbarActionInput.setValue(ACTION);
showBasicSnackbarButton.click();

snackbar.is()
.displayed();
snackbar.has()
.message(MESSAGE);
snackbar.action()
.has()
.text(ACTION);
}

@Test
public void checkSnackbarClickActionDismissTest() {
snackbarSection.messageInput.setValue(MESSAGE);
snackbarSection.actionInput.setValue(ACTION);
snackbarSection.openButton.click();
public void snackbarDismissAfterClickActionTest() {
basicSnackbarMessageInput.setValue(MESSAGE);
basicSnackbarActionInput.setValue(ACTION);
showBasicSnackbarButton.click();

snackbarSection.basicSnackbar.clickAction();
snackbarSection.basicSnackbar.is().disappear();
snackbar.action()
.click();
snackbar.is()
.disappear();
}

@Test
public void checkSnackbarWithNoActionTest() {
snackbarSection.messageInput.setValue(MESSAGE);
snackbarSection.actionInput.setValue("");
snackbarSection.openButton.click();
public void snackbarWithNoActionTest() {
basicSnackbarMessageInput.setValue(MESSAGE);
basicSnackbarActionInput.setValue("");
showBasicSnackbarButton.click();

snackbarSection.basicSnackbar.has().action();
snackbar.has()
.shown();
snackbar.action()
.has()
.notAppear();
}

@Test
public void checkSnackbarDurationTest() {
final int DURATION = 5;
public void snackbarDurationTest() {
final int DURATION = 3;

durationInput.setValue(String.valueOf(DURATION));
showCustomSnackbarButton.click();

JAction action = () -> {
snackbarSection.customSnackbar.base().timer().wait(() -> snackbarSection.customSnackbar.isDisplayed());
snackbarSection.customSnackbar.base().timer().wait(() -> snackbarSection.customSnackbar.isHidden());
};
customSnackbar.shouldBe(visible);
customSnackbar.is()
.notHidden(DURATION);
customSnackbar.shouldBe(hidden);
}

@Test(dataProvider = "positionProvider")
public void snackbarPositionTest(String horizontal, String vertical, Position position) {
horizontalPositionDropdown.select(horizontal);
verticalPositionDropdown.select(vertical);
showPositionSnackbarButton.click();
snackbar.has()
.shown()
.and()
.has()
.position(position);
}

snackbarSection.durationInput.setValue(String.valueOf(DURATION));
snackbarSection.customSnackbarOpenButton.click();
@DataProvider(name = "positionProvider")
public Object[][] providePositions() {
return new Object[][]{
{"Start", "Top", LEFT_TOP},
{"Center", "Top", CENTER_TOP},
{"End", "Top", RIGHT_TOP},
{"Left", "Top", LEFT_TOP},
{"Right", "Top", RIGHT_TOP},

//duration(DURATION, 1000, action);
{"Start", "Bottom", LEFT_BOTTOM},
{"Center", "Bottom", CENTER_BOTTOM},
{"End", "Bottom", RIGHT_BOTTOM},
{"Left", "Bottom", LEFT_BOTTOM},
{"Right", "Bottom", RIGHT_BOTTOM}};
}
}
}
Original file line number Diff line number Diff line change
@@ -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<A extends UIAssert<?, ?>, E extends HasPosition> extends UIAssert<A, E> {

@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;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +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<SnackbarAssert, Snackbar> {
public class SnackbarAssert extends PositionAssert<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().message()
.getText(), 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 '{0}'", isAssert = true)
public SnackbarAssert action(String expected) {
jdiAssert(element().action()
.getText(), Matchers.containsString(expected));
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 action button", isAssert = true)
public SnackbarAssert hasAction() {
jdiAssert(element().action()
.isExist(), Matchers.is(true), "Action doesn't exist in snackbar");
return this;
}

@JDIAction(value = "Assert that '{name}' has no action button", isAssert = true)
public SnackbarAssert hasNoAction() {
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;
}
}
Loading