|
30 | 30 | import org.labkey.test.util.PortalHelper; |
31 | 31 | import org.labkey.test.util.ext4cmp.Ext4ComboRef; |
32 | 32 | import org.labkey.test.util.external.labModules.LabModuleHelper; |
| 33 | +import org.labkey.test.util.selenium.WebDriverUtils; |
33 | 34 | import org.openqa.selenium.By; |
| 35 | +import org.openqa.selenium.Keys; |
34 | 36 | import org.openqa.selenium.WebDriverException; |
35 | 37 | import org.openqa.selenium.WebElement; |
36 | 38 |
|
@@ -307,6 +309,21 @@ private void testUserAgainstAllStates(@LoggedParam EHRUser user) |
307 | 309 | 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 |
308 | 310 | } |
309 | 311 |
|
| 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 | + |
310 | 327 | protected List<String> skipLinksForValidation() |
311 | 328 | { |
312 | 329 | return List.of( |
@@ -385,7 +402,7 @@ private String validLink(WebElement anchor) |
385 | 402 |
|
386 | 403 | try |
387 | 404 | { |
388 | | - openLinkInNewWindowOrThrow(anchor); |
| 405 | + verifyLInk(anchor); |
389 | 406 | } |
390 | 407 | catch (WebDriverException | IllegalStateException e) |
391 | 408 | { |
|
0 commit comments