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

5470 fix Dialog #5523

Merged
merged 7 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.epam.jdi.light.material.elements.displaydata.Avatar;
import com.epam.jdi.light.material.elements.displaydata.Icon;
import com.epam.jdi.light.material.elements.inputs.Checkbox;
import com.epam.jdi.light.material.elements.inputs.Switch;
import com.epam.jdi.light.material.interfaces.CanBeDisabled;
import com.epam.jdi.light.material.interfaces.CanBeSelected;
import com.epam.jdi.light.ui.html.elements.common.Button;
Expand Down Expand Up @@ -85,6 +86,11 @@ public Checkbox checkbox() {
return new Checkbox().setCore(Checkbox.class, core().find(CHECKBOX));
}

@JDIAction(value = "Get '{name}' checkbox element")
public Switch switcher() {
return new Switch().setCore(Switch.class, this.secondaryAction().find(".MuiSwitch-root"));
}

@Override
public CustomSiteListItemAssert is() {
return new CustomSiteListItemAssert().set(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public class MUIListItemWithDialog extends ListItem implements ISetup, HasDialog
protected String root = "//div[contains(@class, 'MuiListItem-root')";
protected String dialogLocator = "//div[contains(@class, 'MuiDialog-container')";

public MUIListItemWithDialog() {
super();
}

public MUIListItemWithDialog(UIElement base) {
setCore(MUIListItemWithDialog.class, base);
}

@Override
public void setup(Field field) {
if (!fieldHasAnnotation(field, JListItemWithDialog.class, MUIListItemWithDialog.class)) {
Expand All @@ -28,6 +36,7 @@ public void setup(Field field) {
base().setLocator(root);
}


@JDIAction("Get '{name}'s dialog")
@Override
public Dialog dialog() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.com.custom.elements.dialog;

import com.epam.jdi.light.material.elements.feedback.Dialog;
import com.epam.jdi.light.material.elements.inputs.TextField;

public class DialogWithEmail extends Dialog {

public TextField email() {
return new TextField().setCore(TextField.class, core().find(".MuiTextField-root"));
}


}
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 @@ -2,6 +2,7 @@

import com.epam.jdi.light.elements.composite.WebPage;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.material.annotations.JMUIList;
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.inputs.Checkbox;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class MUIListPage extends WebPage {
public static MUIList<CustomSiteListItem> checkboxList;

@UI("#listWithSwitch")
@JMUIList(items = ".MuiListItem-container")
public static MUIList<CustomSiteListItem> listWithSwitch;

@UI("#pinnedSubheaderList")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
package io.github.com.pages.feedback;

import com.epam.jdi.light.elements.composite.WebPage;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.material.elements.displaydata.Typography;
import com.epam.jdi.light.material.elements.inputs.MUIButton;
import io.github.com.custom.annotations.JButtonWithDialog;
import io.github.com.custom.annotations.JListItemWithDialog;
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 = "//span[text()='Open simple dialog']/parent::button",
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 = "//span[text()='Open alert dialog']/parent::button",
@JButtonWithDialog(root = "//button[./*[text()='Open alert dialog']]",
dialog = "//h2[text() ='Alert dialog question?']/ancestor::div[contains(@class, 'MuiDialog-container')]",
actionText = "#alertDialogSelection")
public static ButtonWithDialog alertDialogButton;

@JButtonWithDialog(root = "//span[text()='Open form dialog']/parent::button",
dialog = "//h2[text() ='Form Dialog']/ancestor::div[contains(@class, 'MuiDialog-container')]",
actionText = "#mailDialogSelection")
public static ButtonWithDialog formDialogButton;
@UI("//*[contains(@class, 'MuiDialog-container')][.//h2[text()='Form Dialog']]")
public static DialogWithEmail formDialog;
@UI("//button[./*[text()='Open form dialog']]")
public static MUIButton formDialogButton;
@UI("#mailDialogSelection")
public static Typography formDialogAction;

@JListItemWithDialog(root = "//div[contains(@class, 'MuiListItem-root') and @aria-label = 'phone ringtone']",
dialog = "//h2[text() ='Phone Ringtone']/ancestor::div[contains(@class, 'MuiDialog-container')]")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.epam.material.tests.displaydata;

import com.epam.jdi.light.material.elements.displaydata.Icon;
import com.epam.jdi.light.material.elements.inputs.Checkbox;
import com.epam.jdi.light.material.elements.inputs.Switch;
import com.epam.jdi.light.ui.html.elements.common.Text;
import io.github.com.custom.elements.CustomSiteListItem;
import io.github.epam.TestsInit;
Expand Down Expand Up @@ -121,12 +119,10 @@ public void checkboxListTests() {
public void listWithSwitchTests() {
listWithSwitch.show();
listWithSwitch.has().headers();
CustomSiteListItem item = listWithSwitch.item(0).with(CustomSiteListItem.class);
Switch el = new Switch().setCore(Switch.class, item.secondaryAction().find(".MuiSwitch-root").base());
el.is().enabled();
el.is().checked();
el.uncheck();
el.is().unchecked();
CustomSiteListItem item = listWithSwitch.items(CustomSiteListItem.class).get(0);
item.switcher().is().enabled().and().checked();
item.switcher().uncheck();
item.switcher().is().unchecked();

}

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 @@ -8,9 +9,13 @@
import static io.github.com.StaticSite.dialogPage;
import static io.github.com.pages.feedback.DialogPage.alertDialogButton;
import static io.github.com.pages.feedback.DialogPage.confirmationDialogListItem;
import static io.github.com.pages.feedback.DialogPage.formDialog;
import static io.github.com.pages.feedback.DialogPage.formDialogButton;
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 @@ -23,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 All @@ -54,41 +57,40 @@ public void alertDialogTest() {
alertDialogButton.actionText().has().text("Selected: ok");
}

// @todo #5341 Closing dialog should not change anything on the page, explicit click on buttons should be used
@Test(enabled = false)
@Test
public void formDialogsTest() {
final String email = "[email protected]";
formDialogButton.click();
formDialogButton.dialog().is().displayed();
formDialogButton.dialog().title().has().text("Form Dialog");
formDialogButton.dialog().textContent().has().text(containsString("Lorem ipsum dolor sit amet"));
formDialogButton.dialog().textField().sendKeys(email);
formDialogButton.dialog().confirm();
formDialogButton.dialog().is().hidden();
formDialogButton.actionText().has().text("Entered email: " + email);
formDialog.is().displayed();
formDialog.title().has().text("Form Dialog");
formDialog.textContent().has().text(containsString("Lorem ipsum dolor sit amet"));
formDialog.email().sendKeys(email);
formDialog.confirm();
formDialog.is().hidden();
formDialogAction.has().text("Entered email: " + email);
formDialogButton.click();
formDialogButton.dialog().is().displayed();
formDialogButton.dialog().textField().has().text(email);
formDialogButton.dialog().close();
formDialogButton.dialog().is().hidden();
formDialogButton.actionText().has().text("Entered email:");
formDialog.is().displayed();
formDialog.email().has().text(email);
formDialog.close();
formDialog.is().hidden();
formDialogAction.has().text("Entered email:");
}

@Test
@Test(enabled = false)
public void confirmationDialogTest() {
confirmationDialogListItem.click();
confirmationDialogListItem.dialog().is().displayed();
confirmationDialogListItem.dialog().title().has().text("Phone Ringtone");
confirmationDialogListItem.dialog().radioButtons().has().size(14);
confirmationDialogListItem.dialog().radioButtons().select("Callisto");
//confirmationDialogListItem.dialog().radioButtons().has().size(14);
//confirmationDialogListItem.dialog().radioButtons().select("Callisto");
confirmationDialogListItem.dialog().confirm();
confirmationDialogListItem.has().secondaryText("Callisto");
confirmationDialogListItem.click();
confirmationDialogListItem.dialog().radioButtons().select("None");
//confirmationDialogListItem.dialog().radioButtons().select("None");
confirmationDialogListItem.dialog().confirm();
confirmationDialogListItem.has().secondaryText("None");
confirmationDialogListItem.click();
confirmationDialogListItem.dialog().radioButtons().select("Triton");
//confirmationDialogListItem.dialog().radioButtons().select("Triton");
confirmationDialogListItem.dialog().cancel();
confirmationDialogListItem.has().secondaryText("None");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@Target(ElementType.FIELD)
public @interface JMUIList {
@MarkupLocator String header() default ".MuiListSubheader-root";
@MarkupLocator String items() default ".MuiListItem-container";
@MarkupLocator String items() default ".MuiListItem-root";
}
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
Expand Up @@ -2,6 +2,7 @@

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.elements.interfaces.base.HasClick;
import com.epam.jdi.light.elements.interfaces.common.IsText;
import com.epam.jdi.light.material.asserts.displaydata.ListItemAssert;
Expand Down Expand Up @@ -36,6 +37,13 @@ public class ListItem extends UIBaseElement<ListItemAssert> implements IsText, H
private static final String ICON_LOCATOR = ".MuiListItemIcon-root > .MuiSvgIcon-root";
private static final String TEXT_LOCATOR = ".MuiTypography-root";

public ListItem() {
super();
}
public ListItem(UIElement base) {
setCore(ListItem.class, base);
}

@Override
@JDIAction("Get '{name}' text")
public String getText() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.epam.jdi.light.material.elements.displaydata.list;

import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.complex.ISetup;
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;
Expand All @@ -22,11 +24,13 @@
* @see <a href="https://jdi-testing.github.io/jdi-light/material/simple_list">MUI test page</a>
*/

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

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

@Override
public void setup(Field field) {
if (fieldHasAnnotation(field, JMUIList.class, MUIList.class)) {
JMUIList listLocators = field.getAnnotation(JMUIList.class);
Expand All @@ -42,16 +46,16 @@ public String itemLocator() {
public String headerLocator() {
return this.headerLocator;
}
/**
* 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 WebList weblist() {
return core().finds(itemLocator);
}

@Override
public ContainerListAssert is() {
return new ContainerListAssert().set(this);
Expand Down
Loading