Skip to content
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,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.has().action(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.action.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().noAction();
}

@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,20 @@ 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));
jdiAssert(element().messageText(), 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");
public SnackbarAssert noAction() {
jdiAssert(element().isDisplayed(), Matchers.is(true), "No snackbar element found");
jdiAssert(element().isActionDisplayed(), Matchers.is(false), "Action button should be absent");
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().actionText(), Matchers.is(expected));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

если message это элемент с текстом, то это должен быть не UIElement

Copy link
Author

Choose a reason for hiding this comment

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

Заменил на public String messageText(), конструктор убрал вообще

protected String messageLocator = "./span";
protected String messageLocator = "//*[@matsnackbarlabel]";
Copy link
Contributor

Choose a reason for hiding this comment

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

стиль mdc-snackbar__label гораздо более понятнее смотрится

Copy link
Author

Choose a reason for hiding this comment

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

Пофиксил. Теперь так protected String messageLocator = ".mdc-snackbar__label";


protected UIElement action;
protected String actionLocator = ".//button";
public Button action;
protected String actionLocator = "//button";
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.

Вернул назад


public Snackbar() {
message = new UIElement();
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.

После введения проверок из элемента Button кнопка action теперь используется в тестах (сейчас кнопка переименована в actionButton). Если я правильно понял вопрос.

Copy link
Contributor

Choose a reason for hiding this comment

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

вопрос был зачем это делать в конструкторе, а не так же, как это сделано в остальных элементах

message.core().setLocator(messageLocator);

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

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

@JDIAction("Get '{name}' action")
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.

Переименовал getMessageText() в messageText() и getActionText() в actionText()

public String getActionText() {
public String actionText() {
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.

Выполнено. Теперь во всех тестах SnackbarTests используются валидаторы из Button

return action.getValue();
}

Expand Down