From 2d76e93242f125171cd928ba26a42051515c6c94 Mon Sep 17 00:00:00 2001 From: cnathe Date: Fri, 14 Aug 2026 16:11:28 -0500 Subject: [PATCH] Selenium test helpers for sample color test cases --- .../labkey/test/components/ui/AppPageHeader.java | 8 ++++++++ .../labkey/test/components/ui/PageDetailHeader.java | 13 +++++++++++++ .../test/components/ui/grids/DetailTable.java | 13 +++++++++++++ .../labkey/test/components/ui/grids/GridRow.java | 12 ++++++++++++ 4 files changed, 46 insertions(+) diff --git a/src/org/labkey/test/components/ui/AppPageHeader.java b/src/org/labkey/test/components/ui/AppPageHeader.java index e7f5c566c9..bbcdbdfa42 100644 --- a/src/org/labkey/test/components/ui/AppPageHeader.java +++ b/src/org/labkey/test/components/ui/AppPageHeader.java @@ -107,6 +107,14 @@ public String getLabelColor() throw new UnsupportedOperationException("Label color is not supported by AppPageHeader."); } + /** + * @throws UnsupportedOperationException Sample color is not supported by AppPageHeader. + */ + public String getSampleColor() + { + throw new UnsupportedOperationException("Sample color is not supported by AppPageHeader."); + } + @Override protected ElementCache newElementCache() { diff --git a/src/org/labkey/test/components/ui/PageDetailHeader.java b/src/org/labkey/test/components/ui/PageDetailHeader.java index 8c73c4ea62..22ccc69fae 100644 --- a/src/org/labkey/test/components/ui/PageDetailHeader.java +++ b/src/org/labkey/test/components/ui/PageDetailHeader.java @@ -42,6 +42,18 @@ public String getLabelColor() return tryMapElement(elementCache().colorIcon, el -> el.getCssValue("background-color")); } + /** + * Get the rgb style value for the sample color swatch that precedes the title. A sample with its own color shows + * this swatch instead of the sample type's label color in the subtitle. + * + * @return A string such as "rgb(104, 204, 202)", or an empty string if there is no sample color swatch. + */ + @Override + public String getSampleColor() + { + return tryMapElement(elementCache().sampleColorIcon, el -> el.getCssValue("background-color")); + } + @Override protected ElementCache elementCache() { @@ -81,6 +93,7 @@ protected Locator.XPathLocator getIconLocator() } final WebElement colorIcon = Locator.byClass("color-icon__circle-small").findWhenNeeded(subtitle); + final WebElement sampleColorIcon = Locator.byClass("sample-color-header").findWhenNeeded(title); } public static class PageDetailHeaderFinder extends WebDriverComponentFinder diff --git a/src/org/labkey/test/components/ui/grids/DetailTable.java b/src/org/labkey/test/components/ui/grids/DetailTable.java index 564e2638ab..44b6914d9a 100644 --- a/src/org/labkey/test/components/ui/grids/DetailTable.java +++ b/src/org/labkey/test/components/ui/grids/DetailTable.java @@ -153,6 +153,19 @@ public String getFieldValue(String fieldlabel) return getField(fieldlabel).getText(); } + /** + * Return the color of the swatch rendered in a field's value, for example the sample color on a details panel. + * + * @param fieldLabel The label of the field to get. + * @return A string such as "rgb(104, 204, 202)", or an empty string if the field has no color swatch. + **/ + public String getFieldColor(String fieldLabel) + { + WebElement icon = Locator.tagWithClassContaining("i", "color-icon__circle") + .findElementOrNull(getField(fieldLabel)); + return icon == null ? "" : icon.getCssValue("background-color"); + } + /** * Gets the value of a cell identified by its data-fieldKey attribute * @param fieldKey value of the data-fieldKey attribute on the intended element diff --git a/src/org/labkey/test/components/ui/grids/GridRow.java b/src/org/labkey/test/components/ui/grids/GridRow.java index 644c3885c6..79376acacd 100644 --- a/src/org/labkey/test/components/ui/grids/GridRow.java +++ b/src/org/labkey/test/components/ui/grids/GridRow.java @@ -125,6 +125,18 @@ public String getCellStyle(CharSequence columnIdentifier) return Locator.byClass("table-cell-content").child(Locator.tag("span")).findElement(cell).getAttribute("style"); } + /** + * gets the color of the swatch rendered in the specified cell, for example a sample color or a sample type's + * label color + * @return A string such as "rgb(104, 204, 202)", or an empty string if the cell has no color swatch + */ + public String getCellColor(CharSequence columnIdentifier) + { + WebElement icon = Locator.tagWithClassContaining("i", "color-icon__circle") + .findElementOrNull(getCell(columnIdentifier)); + return icon == null ? "" : icon.getCssValue("background-color"); + } + /** * Returns true if the row contains all of the specified column/value pairs * @param partialMap Map of key (column) value (text)