Skip to content
Draft
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
32 changes: 19 additions & 13 deletions src/org/labkey/test/components/react/MultiMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package org.labkey.test.components.react;

import org.apache.commons.lang3.StringUtils;
import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.WebDriverComponent;
import org.labkey.test.components.html.BootstrapMenu;
import org.labkey.test.util.LogMethod;
import org.labkey.test.util.LoggedParam;
import org.labkey.test.util.selenium.WebElementUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -285,8 +287,8 @@ protected List<WebElement> getMenuItemsUnderHeading(String heading)

for (WebElement item : listItems)
{
String className = item.getAttribute("class");
String role = item.getAttribute("role");
String className = StringUtils.trimToEmpty(item.getAttribute("class"));
String role = StringUtils.trimToEmpty(item.getAttribute("role"));
String text = item.getText().trim();

if (className.contains("dropdown-header") && text.equalsIgnoreCase(heading))
Expand Down Expand Up @@ -329,6 +331,17 @@ public void clickMenuItemUnderHeading(String heading, String menuItem)
item.click();
}

/**
* Get the text of all the menu section headers
*
* @return text from the menu section headers
*/
public List<String> getSectionHeadersText()
{
expand();
return WebElementUtils.getTexts(Locators.dropdownHeader.findElements(this));
}

/**
* gets the names of dropdown-section__menu-items between a toggle and the next toggle or divider
*
Expand Down Expand Up @@ -425,24 +438,17 @@ static public Locator.XPathLocator menuContainer()

static public Locator.XPathLocator menuContainer(String text)
{
return menuContainer().withChild(dropdownToggle().withText(text));
return menuContainer().withChild(dropdownToggle.withText(text));
}

static public Locator.XPathLocator menuContainerContains(String text)
{
return menuContainer().withChild(dropdownToggle().containing(text));
return menuContainer().withChild(dropdownToggle.containing(text));
}

// finds the toggle to expand/collapse the root menu
public static Locator.XPathLocator dropdownToggle()
{
return Locator.byClass("dropdown-toggle");
}

public static Locator.XPathLocator dropdownHeader()
{
return Locator.tagWithClass("li", "dropdown-header");
}
public static final Locator.XPathLocator dropdownToggle = Locator.byClass("dropdown-toggle");
public static final Locator.XPathLocator dropdownHeader = Locator.tagWithClass("li", "dropdown-header");

// finds a menu-item
public static Locator.XPathLocator menuItem()
Expand Down
164 changes: 164 additions & 0 deletions src/org/labkey/test/components/ui/AppPageHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2018-2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test.components.ui;

import org.labkey.test.Locator;
import org.labkey.test.components.Component;
import org.labkey.test.components.WebDriverComponent;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import static org.labkey.test.util.selenium.WebElementUtils.tryMapElement;

/**
* Wraps <AppPageHeader/> component
*/
public class AppPageHeader extends WebDriverComponent<AppPageHeader.ElementCache>
{
private final WebElement _el;
private final WebDriver _driver;

protected AppPageHeader(WebElement element, WebDriver driver)
{
_el = element;
_driver = driver;
}

@Override
public WebElement getComponentElement()
{
return _el;
}

@Override
public WebDriver getDriver()
{
return _driver;
}

@Override
protected void waitForReady()
{
getWrapper().shortWait().withMessage(getClass().getSimpleName() + " is not present.")
.until(ExpectedConditions.elementToBeClickable(getComponentElement()));
}

/**
* Get the source file of the page icon. If there is no icon returns an empty string.
*
* @return The 'src' attribute header icon, empty string if element is not there.
*/
public String getIconSource()
{
return tryMapElement(elementCache().icon, el -> el.getDomAttribute("src"));
}

/**
* Gets the text of the page header. If there is no header returns an empty string.
*
* @return Text from the page title, empty string if element is not there.
*/
public String getTitle()
{
return tryMapElement(elementCache().title, WebElement::getText);
}

/**
* Get the text of the subtitle of the page. If there is no subtitle, return an empty string.
*
* @return Text from the page subtitle, empty string if element is not there.
*/
public String getSubtitle()
{
return tryMapElement(elementCache().subtitle, WebElement::getText);
}

/**
* Get the text of the description of the page. If there is no description, returns an empty string.
*
* @return Text from the page description, empty string if element is not there.
*/
public String getDescription()
{
return tryMapElement(elementCache().description, WebElement::getText);
}

/**
* @throws UnsupportedOperationException Label color is not supported by AppPageHeader.
*/
public String getLabelColor()
{
throw new UnsupportedOperationException("Label color is not supported by AppPageHeader.");
}

@Override
protected ElementCache newElementCache()
{
return new ElementCache();
}

protected class ElementCache extends Component<ElementCache>.ElementCache
{
public final WebElement icon = getIconLocator().findWhenNeeded(this);
public final WebElement title = getTitleLocator().findWhenNeeded(this);
public final WebElement subtitle = getSubtitleLocator().findWhenNeeded(this);
public final WebElement description = getDescriptionLocator().findWhenNeeded(this);
public final WebElement children = Locator.byClass("app-page-header__children").findWhenNeeded(this);

protected Locator.XPathLocator getIconLocator()
{
return Locator.byClass("app-page-header__icon");
}

protected Locator.XPathLocator getTitleLocator()
{
return Locator.byClass("app-page-header__title");
}

protected Locator.XPathLocator getSubtitleLocator()
{
return Locator.byClass("app-page-header__subtitle");
}

protected Locator.XPathLocator getDescriptionLocator()
{
return Locator.byClass("app-page-header__description");
}
}

public static class AppPageHeaderFinder extends WebDriverComponentFinder<AppPageHeader, AppPageHeaderFinder>
{
private final Locator.XPathLocator _baseLocator = Locator.byClass("app-page-header");

public AppPageHeaderFinder(WebDriver driver)
{
super(driver);
}

@Override
protected AppPageHeader construct(WebElement el, WebDriver driver)
{
return new AppPageHeader(el, driver);
}

@Override
protected Locator locator()
{
return _baseLocator;
}
}
}
107 changes: 107 additions & 0 deletions src/org/labkey/test/components/ui/PageDetailHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2018-2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test.components.ui;

import org.labkey.test.Locator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import static org.labkey.test.util.selenium.WebElementUtils.tryMapElement;

/**
* Wraps <PageDetailHeader/> component
*/
public class PageDetailHeader extends AppPageHeader
{
protected PageDetailHeader(WebElement element, WebDriver driver)
{
super(element, driver);
}

/**
* Get the rgb style value for the label color in the header
*
* @return A string such as "rgb(104, 204, 202)" as used in the "color-icon__circle-small" "i" element in the detail header or the empty string if element is not there.
*/
@Override
public String getLabelColor()
{
return tryMapElement(elementCache().colorIcon, el -> el.getCssValue("background-color"));
}

@Override
protected ElementCache elementCache()
{
return (ElementCache) super.elementCache();
}

@Override
protected ElementCache newElementCache()
{
return new ElementCache();
}

protected class ElementCache extends AppPageHeader.ElementCache
{
@Override
protected Locator.XPathLocator getTitleLocator()
{
return Locator.byClass("detail__header--name");
}

@Override
protected Locator.XPathLocator getDescriptionLocator()
{
return Locator.byClass("detail__header--desc");
}

@Override
protected Locator.XPathLocator getSubtitleLocator()
{
return Locator.byClass("detail-subtitle");
}

@Override
protected Locator.XPathLocator getIconLocator()
{
return Locator.byClass("detail__header-icon");
}

final WebElement colorIcon = Locator.byClass("color-icon__circle-small").findWhenNeeded(subtitle);
}

public static class PageDetailHeaderFinder extends WebDriverComponentFinder<PageDetailHeader, PageDetailHeaderFinder>
{
private final Locator.XPathLocator _baseLocator = Locator.byClass("page-header");

public PageDetailHeaderFinder(WebDriver driver)
{
super(driver);
}

@Override
protected PageDetailHeader construct(WebElement el, WebDriver driver)
{
return new PageDetailHeader(el, driver);
}

@Override
protected Locator locator()
{
return _baseLocator;
}
}
}
Loading