diff --git a/jdi-light-material-ui-tests/src/main/java/io/github/com/custom/elements/dialog/DialogWithList.java b/jdi-light-material-ui-tests/src/main/java/io/github/com/custom/elements/dialog/DialogWithList.java new file mode 100644 index 0000000000..24aed56616 --- /dev/null +++ b/jdi-light-material-ui-tests/src/main/java/io/github/com/custom/elements/dialog/DialogWithList.java @@ -0,0 +1,26 @@ +package io.github.com.custom.elements.dialog; + +import com.epam.jdi.light.common.JDIAction; +import com.epam.jdi.light.material.elements.displaydata.list.ListItem; +import com.epam.jdi.light.material.elements.displaydata.list.MUIList; +import com.epam.jdi.light.material.elements.displaydata.list.SimpleList; +import com.epam.jdi.light.material.elements.feedback.Dialog; + +import static com.jdiai.tools.Timer.waitCondition; + +public class DialogWithList extends Dialog { + /** + * Gets the list with items within the dialog. + * + * @return list with items within dialog as {@link SimpleList} + */ + @JDIAction("Get '{name}' list items") + public MUIList list() { + return new MUIList().setCore(MUIList.class, core().find(".MuiList-root")); + } + + public void select(int index) { + this.list().items(ListItem.class).get(index).click(); + waitCondition(this::isHidden); + } +} diff --git a/jdi-light-material-ui-tests/src/main/java/io/github/com/pages/feedback/DialogPage.java b/jdi-light-material-ui-tests/src/main/java/io/github/com/pages/feedback/DialogPage.java index 6a5915825b..e993b9e1e3 100644 --- a/jdi-light-material-ui-tests/src/main/java/io/github/com/pages/feedback/DialogPage.java +++ b/jdi-light-material-ui-tests/src/main/java/io/github/com/pages/feedback/DialogPage.java @@ -9,13 +9,16 @@ import io.github.com.custom.elements.ButtonWithDialog; import io.github.com.custom.elements.MUIListItemWithDialog; import io.github.com.custom.elements.dialog.DialogWithEmail; +import io.github.com.custom.elements.dialog.DialogWithList; public class DialogPage extends WebPage { - @JButtonWithDialog(root = "//button[./*[text()='Open simple dialog']]", - dialog = "//div[@aria-labelledby = 'simple-dialog-title']/parent::div[contains(@class, 'MuiDialog-container')]", - actionText = "#simpleDialogSelection") - public static ButtonWithDialog simpleDialogButton; + @UI("//*[contains(@class, 'MuiDialog-container')][.//h2[text()='Set backup account']]") + public static DialogWithList simpleDialog; + @UI("//button[./*[text()='Open simple dialog']]") + public static MUIButton simpleDialogButton; + @UI("#simpleDialogSelection") + public static Typography simpleDialogAction; @JButtonWithDialog(root = "//button[./*[text()='Open alert dialog']]", dialog = "//h2[text() ='Alert dialog question?']/ancestor::div[contains(@class, 'MuiDialog-container')]", diff --git a/jdi-light-material-ui-tests/src/test/java/io/github/epam/material/tests/feedback/DialogTests.java b/jdi-light-material-ui-tests/src/test/java/io/github/epam/material/tests/feedback/DialogTests.java index e1a3bd4f21..c8eef38247 100644 --- a/jdi-light-material-ui-tests/src/test/java/io/github/epam/material/tests/feedback/DialogTests.java +++ b/jdi-light-material-ui-tests/src/test/java/io/github/epam/material/tests/feedback/DialogTests.java @@ -1,5 +1,6 @@ package io.github.epam.material.tests.feedback; +import com.epam.jdi.light.material.elements.displaydata.list.ListItem; import io.github.epam.TestsInit; import io.github.epam.test.data.DialogDataProvider; import org.testng.annotations.BeforeMethod; @@ -13,6 +14,8 @@ import static io.github.com.pages.feedback.DialogPage.formDialogAction; import static io.github.com.pages.feedback.DialogPage.scrollBodyDialogButton; import static io.github.com.pages.feedback.DialogPage.scrollPaperDialogButton; +import static io.github.com.pages.feedback.DialogPage.simpleDialog; +import static io.github.com.pages.feedback.DialogPage.simpleDialogAction; import static io.github.com.pages.feedback.DialogPage.simpleDialogButton; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalToIgnoringCase; @@ -25,18 +28,16 @@ public void before() { dialogPage.isOpened(); } - // @todo #5341 Closing dialog should not change anything on the page, - // only explicit click on buttons should be used - @Test(enabled = false, dataProviderClass = DialogDataProvider.class, dataProvider = "simpleDialogDataProvider") + @Test(dataProviderClass = DialogDataProvider.class, dataProvider = "simpleDialogDataProvider") public void simpleDialogTest(String titleText, int index, String text) { simpleDialogButton.click(); - simpleDialogButton.dialog().is().displayed().and().has().title(); - simpleDialogButton.dialog().title().has().text(titleText); - simpleDialogButton.dialog().list().has().size(3); - simpleDialogButton.dialog().list().items().get(index).has().text(text); - simpleDialogButton.dialog().list().items().get(index).click(); - simpleDialogButton.dialog().is().hidden(); - simpleDialogButton.actionText().has() + simpleDialog.is().displayed().and().has().title(); + simpleDialog.title().has().text(titleText); + simpleDialog.list().has().size(3); + simpleDialog.list().items(ListItem.class).get(index).has().text(text); + simpleDialog.select(index); + simpleDialog.is().hidden(); + simpleDialogAction.has() .text(equalToIgnoringCase("Selected: " + text.replaceAll(" ", ""))); } diff --git a/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/asserts/feedback/DialogAssert.java b/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/asserts/feedback/DialogAssert.java index ae624701db..a3a9b4a668 100644 --- a/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/asserts/feedback/DialogAssert.java +++ b/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/asserts/feedback/DialogAssert.java @@ -75,12 +75,12 @@ public DialogAssert content() { } public DialogAssert actions() { - jdiAssert(element().actionButtons().isExist(), Matchers.is(true), "Dialog actions is not exist"); + jdiAssert(element().actions().isExist(), Matchers.is(true), "Dialog actions is not exist"); return this; } public DialogAssert noActions() { - jdiAssert(element().actionButtons().isExist(), Matchers.is(false), "Dialog actions is exist"); + jdiAssert(element().actions().isExist(), Matchers.is(false), "Dialog actions is exist"); return this; } } diff --git a/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/displaydata/list/MUIList.java b/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/displaydata/list/MUIList.java index e639d9aebf..5c98587e97 100644 --- a/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/displaydata/list/MUIList.java +++ b/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/displaydata/list/MUIList.java @@ -1,16 +1,20 @@ package com.epam.jdi.light.material.elements.displaydata.list; import com.epam.jdi.light.elements.base.UIBaseElement; +import com.epam.jdi.light.elements.complex.WebList; import com.epam.jdi.light.elements.interfaces.base.ICoreElement; import com.epam.jdi.light.material.annotations.JMUIList; import com.epam.jdi.light.material.asserts.displaydata.ContainerListAssert; import com.epam.jdi.light.material.interfaces.displaydata.IMUIList; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.stream.Collectors; +import static com.epam.jdi.light.common.Exceptions.runtimeException; import static com.epam.jdi.light.elements.pageobjects.annotations.objects.FillFromAnnotationRules.fieldHasAnnotation; @@ -24,7 +28,7 @@ public class MUIList extends UIBaseElement implements IMUIList { - protected String itemLocator = ".MuiListItem-container"; + protected String itemLocator = ".MuiListItem-root"; protected String headerLocator = ".MuiListSubheader-root"; public void setup(Field field) { @@ -42,14 +46,34 @@ public String itemLocator() { public String headerLocator() { return this.headerLocator; } + + @Override + public List items() { + return core().finds(itemLocator).stream().collect(Collectors.toList()); + } + + public WebList weblist() { + return core().finds(itemLocator); + } /** * Get list of items * * @return list of items as {@code List} */ - @Override - public List items() { - return core().finds(itemLocator).stream().collect(Collectors.toList()); + public List items(Class cl) { + try { + Constructor constr = cl.getConstructor(); + return core().finds(itemLocator).stream().map(o -> { + try { + return constr.newInstance().setCore(cl, o); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }) + .collect(Collectors.toList()); + } catch (Exception ex) { + throw runtimeException("Can not create a new object " + cl, ex); + } } @Override diff --git a/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/feedback/Dialog.java b/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/feedback/Dialog.java index c0c351212b..2aa4d58d7b 100644 --- a/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/feedback/Dialog.java +++ b/jdi-light-material-ui/src/main/java/com/epam/jdi/light/material/elements/feedback/Dialog.java @@ -5,7 +5,6 @@ import com.epam.jdi.light.elements.common.UIElement; import com.epam.jdi.light.elements.complex.WebList; import com.epam.jdi.light.material.asserts.feedback.DialogAssert; -import com.epam.jdi.light.material.elements.displaydata.list.SimpleList; import com.epam.jdi.light.ui.html.elements.common.Text; import org.openqa.selenium.Keys; @@ -24,7 +23,7 @@ public class Dialog extends UIBaseElement { /** * Script to find scrollable content. */ - private static final String EXECUTE_SCRIPT = "return arguments[0].scrollHeight > arguments[0].offsetHeight;"; + private static final String SEARCH_SCROLL_SCRIPT = "return arguments[0].scrollHeight > arguments[0].offsetHeight;"; private final String contentLocator = ".MuiDialogContent-root";; /** @@ -37,20 +36,10 @@ public Text title() { return new Text().setCore(Text.class, core().find(".MuiDialogTitle-root")); } - /** - * Gets the list with items within the dialog. - * - * @return list with items within dialog as {@link SimpleList} - */ - // @todo #5431 looks like list is not a required part of Dialog, should be removed - @JDIAction("Get '{name}' list items") - public SimpleList list() { - return new SimpleList().setCore(SimpleList.class, core().find(".MuiList-root")); - } - public UIElement content() { return core().find(contentLocator); } + /** * Gets the text content of this dialog (part of the content). * @@ -88,7 +77,7 @@ public WebList actionButtons() { */ @JDIAction("Check that '{name}' has scrollable content") public boolean hasScrollableContent() { - return jsExecute(EXECUTE_SCRIPT, core().find(contentLocator).getFast()); + return jsExecute(SEARCH_SCROLL_SCRIPT, core().find(contentLocator).getFast()); } /** @@ -108,7 +97,7 @@ public void scrollContentTo(int scrollHeight) { */ @JDIAction("Check that '{name}' has scrollable body") public boolean hasScrollableBody() { - return jsExecute(EXECUTE_SCRIPT, core().getFast()); + return jsExecute(SEARCH_SCROLL_SCRIPT, core().getFast()); } /** @@ -129,7 +118,7 @@ public void scrollDialogBodyTo(int scrollHeight) { @JDIAction("Close '{name}' dialog") public void close() { core().actions(a -> a.sendKeys(Keys.ESCAPE)); - waitCondition(() -> core().isHidden()); + waitCondition(this::isHidden); } /**