Skip to content

Commit a5e4a12

Browse files
authored
Update tests for new experiment graph (#2955)
1 parent cb28faa commit a5e4a12

4 files changed

Lines changed: 67 additions & 34 deletions

File tree

src/org/labkey/test/Locator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,6 @@ public static XPathLocator radioButton()
901901
return tag("input").withAttribute("type", "radio");
902902
}
903903

904-
public static XPathLocator imageMapLinkByTitle(String imageMapName, String title)
905-
{
906-
return tag("map").withAttribute("name", imageMapName).child(tag("area").withAttribute("title", title));
907-
}
908-
909904
public static XPathLocator lookupLink(String schemaName, String queryName, String pkName)
910905
{
911906
String linkText = schemaName + "." + queryName + "." + (null != pkName ? pkName : "");

src/org/labkey/test/pipeline/ExperimentGraph.java

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,49 @@
1616
package org.labkey.test.pipeline;
1717

1818
import org.apache.commons.lang3.StringUtils;
19+
import org.labkey.test.BaseWebDriverTest;
1920
import org.labkey.test.Locator;
21+
import org.labkey.test.components.Component;
22+
import org.labkey.test.components.WebDriverComponent;
23+
import org.labkey.test.util.selenium.ScrollUtils;
24+
import org.openqa.selenium.WebDriver;
25+
import org.openqa.selenium.WebElement;
2026

21-
import static org.junit.Assert.*;
27+
import static org.junit.Assert.assertTrue;
28+
import static org.labkey.test.Locator.xq;
2229

2330
/**
2431
* <code>ExperimentGraph</code>
2532
*/
26-
public class ExperimentGraph
33+
public class ExperimentGraph extends WebDriverComponent<Component<?>.ElementCache>
2734
{
28-
private static final String MAP_NAME = "graphmap";
29-
30-
private final PipelineWebTestBase _test;
35+
private final WebElement _el;
36+
private final WebDriver _driver;
3137

32-
public ExperimentGraph(PipelineWebTestBase test)
38+
public ExperimentGraph(BaseWebDriverTest test)
3339
{
34-
_test = test;
40+
_driver = test.getDriver();
41+
_el = Locator.id("graph_root").parent().findElement(test.getDriver());
42+
}
43+
44+
@Override
45+
protected WebDriver getDriver()
46+
{
47+
return _driver;
48+
}
49+
50+
@Override
51+
public WebElement getComponentElement()
52+
{
53+
return _el;
3554
}
3655

3756
public void clickLink(String link)
3857
{
39-
_test.clickAndWait(Locator.imageMapLinkByTitle(MAP_NAME, link));
58+
ScrollUtils.scrollIntoViewPort(getComponentElement());
59+
WebElement linkEl = svgLinkByTitle(link);
60+
// It is challenging to scroll SVG elements to the correct part of the page. Just navigate.
61+
getWrapper().beginAt(linkEl.getAttribute("xlink:href"));
4062
}
4163

4264
public void clickInputLink(String input)
@@ -61,7 +83,7 @@ public String getOutputLinkText(String output)
6183

6284
public boolean isNodePresent(String link)
6385
{
64-
return _test.isElementPresent(Locator.imageMapLinkByTitle(MAP_NAME, link));
86+
return svgLinkByTitle(link).isDisplayed();
6587
}
6688

6789
public boolean isInputPresent(String input)
@@ -94,7 +116,7 @@ public void validate(PipelineTestParams tp)
94116
String[] names = tp.getExperimentLinks();
95117
for (String name : names)
96118
{
97-
if (_test.isTextPresent(name))
119+
if (getWrapper().isTextPresent(name))
98120
{
99121
assertNodePresent(name);
100122
String baseName = getBaseName(tp);
@@ -122,12 +144,19 @@ private String getBaseName(PipelineTestParams tp)
122144
{
123145
for (String sampleName : sampleNames)
124146
{
125-
if (_test.isTextPresent(sampleName))
147+
if (getWrapper().isTextPresent(sampleName))
126148
return sampleName;
127149
}
128150
}
129151

130152
// Probably fail later, but simpler than checking for null return.
131153
return "all";
132154
}
155+
156+
private WebElement svgLinkByTitle(String title)
157+
{
158+
// Funky locator to find element within an SVG
159+
return Locator.xpath(".//*[local-name()='a'][@*[local-name()='title']=" + xq(title) + "]").findWhenNeeded(_el);
160+
}
161+
133162
}

src/org/labkey/test/selenium/ReclickingWebElement.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
*/
1616
package org.labkey.test.selenium;
1717

18-
import org.apache.commons.lang3.mutable.Mutable;
19-
import org.apache.commons.lang3.mutable.MutableObject;
2018
import org.jetbrains.annotations.NotNull;
2119
import org.junit.Assert;
2220
import org.junit.Test;
2321
import org.labkey.test.Locator;
2422
import org.labkey.test.WebDriverWrapper;
2523
import org.labkey.test.components.core.ProjectMenu;
24+
import org.labkey.test.util.CachingSupplier;
2625
import org.labkey.test.util.TestLogger;
2726
import org.labkey.test.util.selenium.ScrollUtils;
2827
import org.labkey.test.util.selenium.WebDriverUtils;
@@ -44,7 +43,8 @@
4443
import java.util.List;
4544
import java.util.regex.Matcher;
4645
import java.util.regex.Pattern;
47-
import java.util.stream.Collectors;
46+
47+
import static org.apache.commons.lang3.StringUtils.trimToEmpty;
4848

4949
public class ReclickingWebElement extends WebElementDecorator
5050
{
@@ -68,7 +68,7 @@ public void click()
6868
{
6969
if (getDriver() != null)
7070
{
71-
final String shortMessage = ex.getMessage().split("\n")[0];
71+
final String shortMessage = trimToEmpty(ex.getMessage()).split("\n")[0];
7272
TestLogger.debug("Retry click: " + shortMessage);
7373
revealElement(getWrappedElement(), shortMessage);
7474
super.click();
@@ -84,7 +84,7 @@ public void click()
8484
&& getDriver().getClass().isAssignableFrom(FirefoxDriver.class))
8585
{
8686
String tagName = getWrappedElement().getTagName();
87-
List<String> classes = Arrays.asList(getWrappedElement().getAttribute("class").toLowerCase().trim().split("\\s"));
87+
List<String> classes = Arrays.asList(trimToEmpty(getWrappedElement().getAttribute("class")).toLowerCase().split("\\s"));
8888
if ("tr".equals(tagName))
8989
{
9090
if (!clickRowInFirefox())
@@ -123,7 +123,7 @@ private void actionClick()
123123
*/
124124
private void clickImageMapArea()
125125
{
126-
String shape = getWrappedElement().getAttribute("shape");
126+
String shape = trimToEmpty(getWrappedElement().getAttribute("shape"));
127127
if (shape.equals("default"))
128128
{
129129
throw new IllegalArgumentException("Refusing to click the 'default' <area> of an image map. Can't guarantee that it won't click a different <area> instead");
@@ -146,13 +146,13 @@ private void clickImageMapArea()
146146
/**
147147
* Calculate the center of a convex &lt;area&gt; in an image-map. Can handle 'rect', 'circle', and 'poly' shapes
148148
* Doc: <a href="https://www.w3schools.com/tags/tag_area.asp">tag_area</a>
149-
* TODO: Implement this formula for concave polygons [https://en.wikipedia.org/wiki/Centroid#Of_a_polygon]
149+
* Does not handle concave polygons [https://en.wikipedia.org/wiki/Centroid#Of_a_polygon]
150150
* @return The center point of the area element relative to the image
151151
*/
152152
@NotNull
153153
private Point getAreaCenter()
154154
{
155-
List<Integer> coords = Arrays.stream(getWrappedElement().getAttribute("coords").split(",")).map(Integer::parseInt).collect(Collectors.toList());
155+
List<Integer> coords = Arrays.stream(trimToEmpty(getWrappedElement().getAttribute("coords")).split(",")).map(Integer::parseInt).toList();
156156
int minX = Integer.MAX_VALUE;
157157
Integer maxX = 0;
158158
int minY = Integer.MAX_VALUE;
@@ -223,7 +223,7 @@ private void revealElement(WebElement el, String shortMessage)
223223
if (interceptingElements.size() == 1)
224224
{
225225
//noinspection ResultOfMethodCallIgnored
226-
WebDriverWrapper.waitFor(() -> ExpectedConditions.stalenessOf(interceptingElements.get(0)).apply(getDriver()), 1_000);
226+
WebDriverWrapper.waitFor(() -> ExpectedConditions.stalenessOf(interceptingElements.getFirst()).apply(getDriver()), 1_000);
227227
}
228228
else if (interceptingElements.size() > 1)
229229
{
@@ -262,20 +262,17 @@ private static Locator.XPathLocator parseInterceptingElementLoc(String shortMess
262262
return interceptingElLoc;
263263
}
264264

265-
private Mutable<WebDriver> _webDriver = null;
265+
private final CachingSupplier<WebDriver> _webDriver = new CachingSupplier<>(() -> WebDriverUtils.extractWrappedDriver(getWrappedElement()));
266266
private WebDriver getDriver()
267267
{
268-
if (_webDriver == null)
269-
{
270-
_webDriver = new MutableObject<>(WebDriverUtils.extractWrappedDriver(getWrappedElement()));
271-
}
272-
return _webDriver.getValue();
268+
return _webDriver.get();
273269
}
274270

275-
public static class TempEceptionParser
271+
// Run manually to test parsing of exception message
272+
public static class TempExceptionParserTest
276273
{
277274
@Test
278-
public void testInterceptinElLoc()
275+
public void testInterceptingElLoc()
279276
{
280277
final Locator.XPathLocator xPathLocator = parseInterceptingElementLoc("Element <a href=\"something\"> is not clickable at point (732,301) because another element " +
281278
"<div id=\"elId\" class=\"cls1 cls2\"> obscures it");

src/org/labkey/test/util/selenium/ScrollUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,25 @@ public static boolean scrollUnderFloatingHeader(WebElement targetElement)
6464
if (floatingHeaders.stream().anyMatch(headerEl -> rectanglesOverlap(rect, headerEl.getRect())))
6565
{
6666
TestLogger.debug("Scrolled under floating headers:\n" + floatingHeaders.stream().map(WebElement::toString).collect(Collectors.joining("\n")));
67-
((Locatable) targetElement).getCoordinates().inViewPort(); // 'inViewPort()' will scroll element into view
67+
scrollIntoViewPort(targetElement);
6868
return true;
6969
}
7070
}
7171
return false;
7272
}
7373

74+
/**
75+
* An alternate method for scrolling an element into view. Tends to get more of the element into view.
76+
*
77+
* @param targetElement the element to scroll into view
78+
* @return the target element
79+
*/
80+
public static WebElement scrollIntoViewPort(WebElement targetElement)
81+
{
82+
((Locatable) targetElement).getCoordinates().inViewPort(); // 'inViewPort()' will scroll element into view
83+
return targetElement;
84+
}
85+
7486
private static boolean rectanglesOverlap(Rectangle r1, Rectangle r2)
7587
{
7688
return r1.getX() < r2.getX() + r2.getWidth() && r2.getX() < r1.getX() + r1.getWidth()

0 commit comments

Comments
 (0)