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

5378 Fix failing tests for Snackbar #5379

Open
wants to merge 11 commits into
base: angular_rework_development
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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,13 +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 NewAngularPage {
@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,66 @@

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.actionButton().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.actionButton().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.actionButton().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,7 @@ public class SnackbarAssert extends UIAssert<SnackbarAssert, Snackbar> {

@JDIAction(value = "Assert that '{name}' has message '{0}'", isAssert = true)
public SnackbarAssert message(String expected) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на текст всегда ставим валидатор с матчером, чтобы не только на полное соответствие можно было проверить

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Заменил на Matchers.containsString(expected)

jdiAssert(element().getMessageText(), Matchers.is(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");
return this;
}

@JDIAction(value = "Assert that '{name}' has action {0}", isAssert = true)
public SnackbarAssert action(String expected) {
jdiAssert(element().getActionText(), Matchers.is(expected));
jdiAssert(element().messageText(), Matchers.containsString(expected));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,24 @@
import com.epam.jdi.light.angular.asserts.SnackbarAssert;
import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.common.UIElement;
import com.epam.jdi.light.ui.html.elements.common.Button;

/**
* 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";

protected UIElement action;
protected String messageLocator = ".mdc-snackbar__label";
protected String actionLocator = ".//button";

public Snackbar() {
message = new UIElement();
message.core().setLocator(messageLocator);

action = new UIElement();
action.core().setLocator(actionLocator);
}

@JDIAction("Get '{name}' message")
public String getMessageText() {
return message.getValue();
}

@JDIAction("Get '{name}' action")
public String getActionText() {
return action.getValue();
}

@JDIAction("Click '{name}' action")
public void clickAction() {
action.click();
public Button actionButton() {
return new Button().setCore(Button.class, core().find(this.actionLocator));
}

@JDIAction("Is '{name}' action displayed")
public boolean isActionDisplayed() {
return action.isDisplayed();
@JDIAction("Get Snackbar message")
public String messageText() {
return this.find(messageLocator).getText();
}

@Override
Expand Down