Skip to content

Commit d871bfa

Browse files
committed
verify link function
1 parent c389b07 commit d871bfa

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import org.labkey.test.util.PortalHelper;
3131
import org.labkey.test.util.ext4cmp.Ext4ComboRef;
3232
import org.labkey.test.util.external.labModules.LabModuleHelper;
33+
import org.labkey.test.util.selenium.WebDriverUtils;
3334
import org.openqa.selenium.By;
35+
import org.openqa.selenium.Keys;
3436
import org.openqa.selenium.WebDriverException;
3537
import org.openqa.selenium.WebElement;
3638

@@ -307,6 +309,21 @@ private void testUserAgainstAllStates(@LoggedParam EHRUser user)
307309
resetErrors(); //note: inserting records without permission will log errors by design. the UI should prevent this from happening, so we want to be aware if it does occur
308310
}
309311

312+
// Clicks the link and switches to the window if it's a viable link. Otherwise throws an exception.
313+
private void verifyLInk(WebElement link)
314+
{
315+
int winCount = getDriver().getWindowHandles().size();
316+
link.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, Keys.ENTER));
317+
318+
// Short wait for a new window to open. If not then throw exception
319+
boolean winOpen = waitFor(() -> getDriver().getWindowHandles().size() > winCount, 1000);
320+
if (!winOpen)
321+
throw new IllegalStateException("Link did not open new window in tab.");
322+
323+
List<String> windows = new ArrayList<>(getDriver().getWindowHandles());
324+
getDriver().switchTo().window(windows.get(1));
325+
}
326+
310327
protected List<String> skipLinksForValidation()
311328
{
312329
return List.of(
@@ -385,7 +402,7 @@ private String validLink(WebElement anchor)
385402

386403
try
387404
{
388-
openLinkInNewWindowOrThrow(anchor);
405+
verifyLInk(anchor);
389406
}
390407
catch (WebDriverException | IllegalStateException e)
391408
{

0 commit comments

Comments
 (0)