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
5 changes: 0 additions & 5 deletions src/org/labkey/test/Locator.java
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,6 @@ public static XPathLocator radioButton()
return tag("input").withAttribute("type", "radio");
}

public static XPathLocator imageMapLinkByTitle(String imageMapName, String title)
{
return tag("map").withAttribute("name", imageMapName).child(tag("area").withAttribute("title", title));
}

public static XPathLocator lookupLink(String schemaName, String queryName, String pkName)
{
String linkText = schemaName + "." + queryName + "." + (null != pkName ? pkName : "");
Expand Down
81 changes: 47 additions & 34 deletions src/org/labkey/test/pipeline/ExperimentGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,47 @@
*/
package org.labkey.test.pipeline;

import org.apache.commons.lang3.StringUtils;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.components.Component;
import org.labkey.test.components.WebDriverComponent;
import org.labkey.test.util.selenium.ScrollUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import static org.labkey.test.Locator.xq;

/**
* <code>ExperimentGraph</code>
*/
public class ExperimentGraph
public class ExperimentGraph extends WebDriverComponent<Component<?>.ElementCache>
{
private static final String MAP_NAME = "graphmap";

private final PipelineWebTestBase _test;
private final WebElement _el;
private final WebDriver _driver;

public ExperimentGraph(PipelineWebTestBase test)
public ExperimentGraph(BaseWebDriverTest test)
{
_test = test;
_driver = test.getDriver();
_el = Locator.id("graph_root").parent().findElement(test.getDriver());
}

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

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

public void clickLink(String link)
{
_test.clickAndWait(Locator.imageMapLinkByTitle(MAP_NAME, link));
ScrollUtils.scrollIntoViewPort(getComponentElement());
getWrapper().doAndWaitForPageToLoad(() -> getWrapper().actionClick(svgLinkByTitle(link)));
}

public void clickInputLink(String input)
Expand All @@ -61,7 +80,7 @@ public String getOutputLinkText(String output)

public boolean isNodePresent(String link)
{
return _test.isElementPresent(Locator.imageMapLinkByTitle(MAP_NAME, link));
return svgLinkByTitle(link).isDisplayed();
}

public boolean isInputPresent(String input)
Expand Down Expand Up @@ -94,40 +113,34 @@ public void validate(PipelineTestParams tp)
String[] names = tp.getExperimentLinks();
for (String name : names)
{
if (_test.isTextPresent(name))
{
assertNodePresent(name);
String baseName = getBaseName(tp);
assertInputPresent(tp.getParametersFile());
for (String inputExt : tp.getInputExtensions())
assertInputPresent(baseName + inputExt);
for (String outputExt : tp.getOutputExtensions())
assertOutputPresent(baseName + outputExt);
return;
}
assertNodePresent(name);
String baseName = getBaseName(tp);
assertInputPresent(tp.getParametersFile());
for (String inputExt : tp.getInputExtensions())
assertInputPresent(baseName + inputExt);
for (String outputExt : tp.getOutputExtensions())
assertOutputPresent(baseName + outputExt);
}

assertTrue("Unable to find experiment links: " + StringUtils.join(names, ", "), false);
}

private String getBaseName(PipelineTestParams tp)
{
String[] sampleNames = tp.getSampleNames();
if (sampleNames.length == 0)
for (String sampleName : sampleNames)
{
// AbstractMS2SearchProtocol.getJoinedBaseName() is hard-coded to use "all"
return "all";
}
else
{
for (String sampleName : sampleNames)
{
if (_test.isTextPresent(sampleName))
return sampleName;
}
if (getWrapper().isTextPresent(sampleName))
return sampleName;
}

// AbstractMS2SearchProtocol.getJoinedBaseName() is hard-coded to use "all"
// Probably fail later, but simpler than checking for null return.
return "all";
}

private WebElement svgLinkByTitle(String title)
{
// Funky locator to find element within an SVG
return Locator.xpath(".//*[local-name()='a'][@*[local-name()='title']=" + xq(title) + "]").findWhenNeeded(_el);
}

}
31 changes: 14 additions & 17 deletions src/org/labkey/test/selenium/ReclickingWebElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
*/
package org.labkey.test.selenium;

import org.apache.commons.lang3.mutable.Mutable;
import org.apache.commons.lang3.mutable.MutableObject;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;
import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.core.ProjectMenu;
import org.labkey.test.util.CachingSupplier;
import org.labkey.test.util.TestLogger;
import org.labkey.test.util.selenium.ScrollUtils;
import org.labkey.test.util.selenium.WebDriverUtils;
Expand All @@ -44,7 +43,8 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;

public class ReclickingWebElement extends WebElementDecorator
{
Expand All @@ -68,7 +68,7 @@ public void click()
{
if (getDriver() != null)
{
final String shortMessage = ex.getMessage().split("\n")[0];
final String shortMessage = trimToEmpty(ex.getMessage()).split("\n")[0];
TestLogger.debug("Retry click: " + shortMessage);
revealElement(getWrappedElement(), shortMessage);
super.click();
Expand All @@ -84,7 +84,7 @@ public void click()
&& getDriver().getClass().isAssignableFrom(FirefoxDriver.class))
{
String tagName = getWrappedElement().getTagName();
List<String> classes = Arrays.asList(getWrappedElement().getAttribute("class").toLowerCase().trim().split("\\s"));
List<String> classes = Arrays.asList(trimToEmpty(getWrappedElement().getAttribute("class")).toLowerCase().split("\\s"));
if ("tr".equals(tagName))
{
if (!clickRowInFirefox())
Expand Down Expand Up @@ -123,7 +123,7 @@ private void actionClick()
*/
private void clickImageMapArea()
{
String shape = getWrappedElement().getAttribute("shape");
String shape = trimToEmpty(getWrappedElement().getAttribute("shape"));
if (shape.equals("default"))
{
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");
Expand All @@ -146,13 +146,13 @@ private void clickImageMapArea()
/**
* Calculate the center of a convex &lt;area&gt; in an image-map. Can handle 'rect', 'circle', and 'poly' shapes
* Doc: <a href="https://www.w3schools.com/tags/tag_area.asp">tag_area</a>
* TODO: Implement this formula for concave polygons [https://en.wikipedia.org/wiki/Centroid#Of_a_polygon]
* Does not handle concave polygons [https://en.wikipedia.org/wiki/Centroid#Of_a_polygon]
* @return The center point of the area element relative to the image
*/
@NotNull
private Point getAreaCenter()
{
List<Integer> coords = Arrays.stream(getWrappedElement().getAttribute("coords").split(",")).map(Integer::parseInt).collect(Collectors.toList());
List<Integer> coords = Arrays.stream(trimToEmpty(getWrappedElement().getAttribute("coords")).split(",")).map(Integer::parseInt).toList();
int minX = Integer.MAX_VALUE;
Integer maxX = 0;
int minY = Integer.MAX_VALUE;
Expand Down Expand Up @@ -223,7 +223,7 @@ private void revealElement(WebElement el, String shortMessage)
if (interceptingElements.size() == 1)
{
//noinspection ResultOfMethodCallIgnored
WebDriverWrapper.waitFor(() -> ExpectedConditions.stalenessOf(interceptingElements.get(0)).apply(getDriver()), 1_000);
WebDriverWrapper.waitFor(() -> ExpectedConditions.stalenessOf(interceptingElements.getFirst()).apply(getDriver()), 1_000);
}
else if (interceptingElements.size() > 1)
{
Expand Down Expand Up @@ -262,20 +262,17 @@ private static Locator.XPathLocator parseInterceptingElementLoc(String shortMess
return interceptingElLoc;
}

private Mutable<WebDriver> _webDriver = null;
private final CachingSupplier<WebDriver> _webDriver = new CachingSupplier<>(() -> WebDriverUtils.extractWrappedDriver(getWrappedElement()));
private WebDriver getDriver()
{
if (_webDriver == null)
{
_webDriver = new MutableObject<>(WebDriverUtils.extractWrappedDriver(getWrappedElement()));
}
return _webDriver.getValue();
return _webDriver.get();
}

public static class TempEceptionParser
// Run manually to test parsing of exception message
public static class TempExceptionParserTest
{
@Test
public void testInterceptinElLoc()
public void testInterceptingElLoc()
{
final Locator.XPathLocator xPathLocator = parseInterceptingElementLoc("Element <a href=\"something\"> is not clickable at point (732,301) because another element " +
"<div id=\"elId\" class=\"cls1 cls2\"> obscures it");
Expand Down
14 changes: 13 additions & 1 deletion src/org/labkey/test/util/selenium/ScrollUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,25 @@ public static boolean scrollUnderFloatingHeader(WebElement targetElement)
if (floatingHeaders.stream().anyMatch(headerEl -> rectanglesOverlap(rect, headerEl.getRect())))
{
TestLogger.debug("Scrolled under floating headers:\n" + floatingHeaders.stream().map(WebElement::toString).collect(Collectors.joining("\n")));
((Locatable) targetElement).getCoordinates().inViewPort(); // 'inViewPort()' will scroll element into view
scrollIntoViewPort(targetElement);
return true;
}
}
return false;
}

/**
* An alternate method for scrolling an element into view. Tends to get more of the element into view.
*
* @param targetElement the element to scroll into view
* @return the target element
*/
public static WebElement scrollIntoViewPort(WebElement targetElement)
{
((Locatable) targetElement).getCoordinates().inViewPort(); // 'inViewPort()' will scroll element into view
return targetElement;
}

private static boolean rectanglesOverlap(Rectangle r1, Rectangle r2)
{
return r1.getX() < r2.getX() + r2.getWidth() && r2.getX() < r1.getX() + r1.getWidth()
Expand Down
Loading