From 5cf20478e61477824e1125d1732622bc4460181f Mon Sep 17 00:00:00 2001 From: alanv Date: Tue, 13 Feb 2024 13:30:44 -0600 Subject: [PATCH] ProductMenu: Update to account for new DOM --- .../components/ui/navigation/ProductMenu.java | 68 ++++++++++++------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/src/org/labkey/test/components/ui/navigation/ProductMenu.java b/src/org/labkey/test/components/ui/navigation/ProductMenu.java index e5d0599ebe..f85e1c3a62 100644 --- a/src/org/labkey/test/components/ui/navigation/ProductMenu.java +++ b/src/org/labkey/test/components/ui/navigation/ProductMenu.java @@ -6,8 +6,9 @@ import org.labkey.test.BootstrapLocators; import org.labkey.test.Locator; -import org.labkey.test.components.react.BaseBootstrapMenu; -import org.labkey.test.components.react.MultiMenu; +import org.labkey.test.WebDriverWrapper; +import org.labkey.test.components.Component; +import org.labkey.test.components.WebDriverComponent; import org.labkey.test.util.TestLogger; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -19,23 +20,37 @@ import java.util.Map; import java.util.stream.Collectors; -public class ProductMenu extends BaseBootstrapMenu +public class ProductMenu extends WebDriverComponent { + private final WebElement _componentElement; + private final WebDriver _driver; protected ProductMenu(WebElement element, WebDriver driver) { - super(element, driver); + _componentElement = element; + _driver = driver; } public static SimpleWebDriverComponentFinder finder(WebDriver driver) { - return new MultiMenu.MultiMenuFinder(driver).withButtonId("product-menu").wrap(ProductMenu::new); + return new SimpleWebDriverComponentFinder<>(driver, rootLocator, ProductMenu::new); } @Override + protected WebDriver getDriver() + { + return _driver; + } + + @Override + public WebElement getComponentElement() + { + return _componentElement; + } + protected boolean isExpanded() { - boolean ariaExpanded = super.isExpanded(); + boolean ariaExpanded = "true".equals(elementCache().toggle.getAttribute("aria-expanded")); boolean menuContentDisplayed = elementCache().menuContent.isDisplayed(); TestLogger.debug(String.format("Product menu expansion state: aria-expanded is %b, menuContentDisplayed is %b.", ariaExpanded, menuContentDisplayed)); @@ -44,6 +59,23 @@ protected boolean isExpanded() ExpectedConditions.invisibilityOfAllElements(BootstrapLocators.loadingSpinner.findElements(this)).apply(getDriver()); } + public void expand() + { + if (!isExpanded()) + { + elementCache().toggle.click(); + WebDriverWrapper.waitFor(this::isExpanded, "AppsMenu did not expand as expected", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); + } + } + + public void collapse() + { + if (isExpanded()) + { + elementCache().toggle.click(); + } + } + public List getMenuSectionHeaders() { expand(); @@ -138,38 +170,28 @@ public int getAdministrationIconCount() public String getButtonTitle() { - WebElement buttonTitle = Locator.tagWithId("button", "product-menu") - .child(Locator.tagWithClass("div", "title")).findElement(this); + WebElement buttonTitle = elementCache().toggle.findElement(Locator.byClass("title")); return buttonTitle.getText(); } public String getButtonSubtitle() { - WebElement buttonSubtitle = Locator.tagWithId("button", "product-menu") - .child(Locator.tagWithClass("div", "subtitle")).findElement(this); + WebElement buttonSubtitle = elementCache().toggle.findElement(Locator.byClass("subtitle")); return buttonSubtitle.getText(); } - @Override - protected Locator getToggleLocator() - { - return Locator.tagWithId("button", "product-menu"); - } - - @Override - protected ElementCache elementCache() - { - return (ElementCache) super.elementCache(); - } - @Override protected ElementCache newElementCache() { return new ElementCache(); } - protected class ElementCache extends BaseBootstrapMenu.ElementCache + static Locator rootLocator = Locator.byClass("product-menu"); + + protected class ElementCache extends Component.ElementCache { + private final WebElement rootElement = rootLocator.findElement(getDriver()); + private final WebElement toggle = Locator.byClass("product-menu-button").findElement(rootElement); private final WebElement menuContent = Locator.tagWithClass("div", "product-menu-content").refindWhenNeeded(this); private final WebElement sectionContent = Locator.tagWithClass("div", "sections-content").refindWhenNeeded(menuContent);