Skip to content

Commit 0dcd01f

Browse files
committed
Code review feedback
1 parent 15a7bff commit 0dcd01f

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

ehr/test/src/org/labkey/test/tests/ehr/AbstractGenericEHRTest.java

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.labkey.test.Locator;
2323
import org.labkey.test.Locators;
2424
import org.labkey.test.pages.ehr.AnimalHistoryPage;
25+
import org.labkey.test.util.Crawler;
2526
import org.labkey.test.util.DataRegionTable;
2627
import org.labkey.test.util.EscapeUtil;
2728
import org.labkey.test.util.Ext4Helper;
@@ -334,15 +335,13 @@ protected List<String> skipLinksForCrawling()
334335
"core-modulePropertyAdmin.view",
335336
"dataintegration-begin.view",
336337
"ldk-updateQuery",
337-
"junit-begin.view"
338+
"junit-begin.view",
339+
"admin-"
338340
);
339341
}
340342

341343
private String validLink(WebElement anchor)
342344
{
343-
boolean clickable = false;
344-
String validUrl = null;
345-
346345
String href = anchor.getDomAttribute("href");
347346
if (href != null && !href.startsWith("#"))
348347
{
@@ -369,46 +368,49 @@ private String validLink(WebElement anchor)
369368
}
370369

371370
// scope this to admin, ehr folder and subfolders
372-
if (!decodedHref.contains(getContainerPath()) && !decodedHref.startsWith("/admin"))
371+
String controller = new Crawler.ControllerActionId(decodedHref).getController();
372+
if (!decodedHref.contains(getContainerPath()) && !controller.equalsIgnoreCase("admin"))
373373
{
374374
log(href + " is in a different folder than the EHR folder, " + getContainerPath() + ". Skipping validation.");
375375
return null;
376376
}
377377
}
378378

379-
if (anchor.isDisplayed() && anchor.isEnabled())
380-
{
381-
clickable = true;
379+
if (!anchor.isDisplayed())
380+
return null;
382381

383-
try
384-
{
385-
openLinkInNewWindowOrThrow(anchor);
386-
}
387-
catch (WebDriverException | IllegalStateException e)
388-
{
389-
clickable = false;
390-
}
382+
boolean clickable = true;
383+
String validUrl = null;
391384

392-
if (clickable)
393-
{
394-
// Give page time to load
395-
boolean loaded = waitFor(() -> (getDriver().getCurrentUrl() != null && !getDriver().getCurrentUrl().equalsIgnoreCase("about:blank")), WAIT_FOR_PAGE);
396-
assertTrue("Link " + href + " did not load in " + WAIT_FOR_PAGE + "ms.", loaded);
397-
398-
// Assert page is not empty and does not have errors
399-
URL url = getURL();
400-
assertFalse("URL " + url + " is empty.", isPageEmpty());
401-
assertNoLabKeyErrors();
402-
403-
// assertNoLabKeyErrors does not catch all types of errors
404-
assertElementNotPresent("LabKey error found for URL " + url, Locators.labkeyErrorHeading);
405-
406-
// record link as valid and cleanup
407-
validUrl = url.toString();
408-
switchToWindow(0);
409-
quietlyCloseExtraWindows();
410-
}
385+
try
386+
{
387+
openLinkInNewWindowOrThrow(anchor);
388+
}
389+
catch (WebDriverException | IllegalStateException e)
390+
{
391+
clickable = false;
411392
}
393+
394+
if (clickable)
395+
{
396+
// Give page time to load
397+
boolean loaded = waitFor(() -> (getDriver().getCurrentUrl() != null && !getDriver().getCurrentUrl().equalsIgnoreCase("about:blank")), WAIT_FOR_PAGE);
398+
assertTrue("Link " + href + " did not load in " + WAIT_FOR_PAGE + "ms.", loaded);
399+
400+
// Assert page is not empty and does not have errors
401+
URL url = getURL();
402+
assertFalse("URL " + url + " is empty.", isPageEmpty());
403+
assertNoLabKeyErrors();
404+
405+
// assertNoLabKeyErrors does not catch all types of errors
406+
assertElementNotPresent("LabKey error found for URL " + url, Locators.labkeyErrorHeading);
407+
408+
// record link as valid and cleanup
409+
validUrl = url.toString();
410+
getDriver().close();
411+
switchToWindow(0);
412+
}
413+
412414
return validUrl;
413415
}
414416

@@ -426,7 +428,7 @@ private void validatePageLinks(Set<String> crawledLinks)
426428
{
427429
// Only validate links once
428430
String href = anchor.getDomAttribute("href");
429-
if (href != null && validLinksOnPage.contains(href))
431+
if (href != null && (validLinksOnPage.contains(href) || crawledLinks.contains(href)))
430432
continue;
431433

432434
// Validate and record valid links

0 commit comments

Comments
 (0)