Skip to content

Commit 56ae52b

Browse files
labkey-tchadlabkey-alan
authored andcommitted
Handle floating grid headers
1 parent 4868cd7 commit 56ae52b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/org/labkey/test/Locators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private Locators() { }
3131
public static final Locator.XPathLocator panelWebpartTitle = Locator.byClass("labkey-wp-title-text");
3232
public static final Locator.XPathLocator folderTitle = Locator.tagWithClass("a", "lk-body-title-folder");
3333
public static final Locator.XPathLocator loadingSpinner = Locator.byClass("fa-spinner");
34+
public static final Locator.CssLocator floatingGridHeader = Locator.css(".grid-panel__grid .table-responsive thead, .editable-grid__container .table-responsive thead");
3435

3536
public static Locator.XPathLocator headerContainer()
3637
{

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.labkey.test.util.DataRegionTable;
88
import org.labkey.test.util.TestLogger;
99
import org.openqa.selenium.JavascriptExecutor;
10+
import org.openqa.selenium.Point;
11+
import org.openqa.selenium.Rectangle;
1012
import org.openqa.selenium.WebDriver;
1113
import org.openqa.selenium.WebElement;
1214
import org.openqa.selenium.interactions.Locatable;
@@ -53,17 +55,15 @@ public static boolean scrollUnderFloatingHeader(WebElement webElement)
5355
Locators.floatingHeaderContainer(),
5456
Locators.appFloatingHeader(),
5557
Locators.domainDesignerFloatingHeader(),
56-
DataRegionTable.Locators.floatingHeader().notHidden());
58+
DataRegionTable.Locators.floatingHeader().notHidden(),
59+
Locators.floatingGridHeader);
5760

58-
int headerHeight = 0;
59-
for (WebElement floatingHeader : floatingHeaders)
61+
if (!floatingHeaders.isEmpty())
6062
{
61-
headerHeight += floatingHeader.getSize().getHeight();
62-
}
63-
if (headerHeight > 0)
64-
{
65-
int elYInViewPort = webElement.getLocation().getY() - getWindowScrollY(webDriver).intValue();
66-
if (headerHeight > elYInViewPort)
63+
Rectangle rect = webElement.getRect();
64+
Point elementCenter = new Point(rect.getX() + rect.getWidth()/2, rect.getY() + rect.getHeight()/2);
65+
66+
if (floatingHeaders.stream().anyMatch(el -> pointInRect(elementCenter, el.getRect())))
6767
{
6868
TestLogger.debug("Scrolled under floating headers:\n" + floatingHeaders.stream().map(WebElement::toString).collect(Collectors.joining("\n")));
6969
((Locatable) webElement).getCoordinates().inViewPort(); // 'inViewPort()' will scroll element into view
@@ -73,6 +73,12 @@ public static boolean scrollUnderFloatingHeader(WebElement webElement)
7373
return false;
7474
}
7575

76+
private static boolean pointInRect(Point point, Rectangle rect)
77+
{
78+
return rect.getX() <= point.getX() && point.getX() <= rect.getX() + rect.getWidth() &&
79+
rect.getY() <= point.getY() && point.getY() <= rect.getY() + rect.getHeight();
80+
}
81+
7682
public static Long getWindowScrollY(WebDriver webDriver)
7783
{
7884
Number N = (Number) executeScript(webDriver, "return window.scrollY;");

0 commit comments

Comments
 (0)