Skip to content
Closed
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
15 changes: 14 additions & 1 deletion src/org/labkey/test/WebDriverWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2872,8 +2872,21 @@ public void clickAndWait(Locator l)

public void openLinkInNewWindow(WebElement link)
{
int winCount = getDriver().getWindowHandles().size();
link.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, Keys.ENTER));
switchToWindow(1);
switchToWindow(winCount);
waitForDocument();
}

public void openLinkInNewWindowOrThrow(WebElement link)
{
Comment on lines +2881 to +2882
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is redundant. switchToWindow will throw if the specified window index doesn't exist. That being said, I wouldn't hate if it threw a more informative error (currently, you'd just get an IndexOutOfBoundsException)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah switchToWindow waits 10 secs before throwing that IndexOutOfBoundsException. Since we're using this as a test to discover anchor tags that are links, there will be a relative high number of failures. So openLinkInNewWindowOrThrow speeds up that check for this use case and throws a more explicit exception. If you think it's ok to refactor openLinkInNewWindow to more quickly check and throw then we could use it here without slowing down this test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's still a pretty misleading method name. Maybe just add timeout parameters to openLinkInNewWindow and switchToWindow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that would be a pretty big refactor, switchToWindow is used in a lot of places. Maybe I'm pushing too hard to use this general functionality for a specific use case it doesn't quite match. I'll close this PR and do a more focused function in ehrModules.

int winCount = getDriver().getWindowHandles().size();
link.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, Keys.ENTER));
boolean winOpen = waitFor(() -> getDriver().getWindowHandles().size() > winCount, 1000);
if (!winOpen)
throw new IllegalStateException("Link did not open new window in tab.");

switchToWindow(winCount);
waitForDocument();
}

Expand Down