Skip to content

Conversation

@labkey-martyp
Copy link
Contributor

Rationale

Test helper functions for EHR link crawler test.

Related Pull Requests

  • TBD

Changes

  • Add a close extra windows function that doesn't log everytime.
  • Throw in openLinkInNewWindow if window doesn't open

Comment on lines 2896 to 2902
int winCount = getDriver().getWindowHandles().size();
link.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, Keys.ENTER));
if (getDriver().getWindowHandles().size() < (winCount + 1))
throw new IllegalStateException("Link did not open new window in tab.");

switchToWindow(1);
waitForDocument();
Copy link
Member

Choose a reason for hiding this comment

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

switchToWindow already waits for the new window. However, this should be updated to switch to the new window instead of always using index 1.

Suggested change
int winCount = getDriver().getWindowHandles().size();
link.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, Keys.ENTER));
if (getDriver().getWindowHandles().size() < (winCount + 1))
throw new IllegalStateException("Link did not open new window in tab.");
switchToWindow(1);
waitForDocument();
int winCount = getDriver().getWindowHandles().size();
link.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, Keys.ENTER));
switchToWindow(winCount);
waitForDocument();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'm trying to test all anchor tags that could function like links, whether they have a href or a click event handler attached later. And there are many anchor tags on our pages that are not links. So I'm using this function to determine if an anchor tag is a link by trying to click on it and see if a new window pops up. If so, it's a real link. If not, it throws which is caught in the crawler test and it moves on to the next anchor tag. I incorporated your suggestion above, but also created a new function, openLinkInNewWindowOrThrow more designed for this use case.

Comment on lines +2902 to +2903
public void openLinkInNewWindowOrThrow(WebElement link)
{
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.

Comment on lines +2902 to +2903
public void openLinkInNewWindowOrThrow(WebElement link)
{
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

@labkey-martyp
Copy link
Contributor Author

Closing this PR for more specific implementation in the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants