Skip to content

Commit

Permalink
#5470 fix for Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed May 2, 2024
1 parent 557cc8a commit f2c5a80
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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<ListItem> list() {
return new MUIList<ListItem>().setCore(MUIList.class, core().find(".MuiList-root"));
}

public void select(int index) {
this.list().items(ListItem.class).get(index).click();
waitCondition(this::isHidden);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')]",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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(" ", "")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;


Expand All @@ -24,7 +28,7 @@

public class MUIList<T extends ICoreElement> extends UIBaseElement<ContainerListAssert> implements IMUIList<ICoreElement> {

protected String itemLocator = ".MuiListItem-container";
protected String itemLocator = ".MuiListItem-root";
protected String headerLocator = ".MuiListSubheader-root";

public void setup(Field field) {
Expand All @@ -42,14 +46,34 @@ public String itemLocator() {
public String headerLocator() {
return this.headerLocator;
}

@Override
public List<ICoreElement> 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<MUIButton>}
*/
@Override
public List<ICoreElement> items() {
return core().finds(itemLocator).stream().collect(Collectors.toList());
public <T extends ICoreElement> List<T> items(Class<T> cl) {
try {
Constructor<T> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,7 +23,7 @@ public class Dialog extends UIBaseElement<DialogAssert> {
/**
* 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";;

/**
Expand All @@ -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).
*
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit f2c5a80

Please sign in to comment.