-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(selenium): ensure switchTo() does not fail using SafariDriver #392
Conversation
- dependency-name: "org.mockito:mockito-core" | ||
versions: [ ">=5.0.0" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,215 +1,224 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies - this must have been formatting after adding Mockito
JavascriptExecutor driver = (JavascriptExecutor) webDriver; | ||
driver.executeScript("window.open('about:blank', '_blank')"); | ||
ArrayList<String> handles = new ArrayList<String>(webDriver.getWindowHandles()); | ||
String abHandle = handles.get(handles.size() - 1); | ||
webDriver.switchTo().window(abHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to look at the git history to see why we did it this way vs newWindow(..)
but couldn't find anything
…-html into fix-safari-switch-two-issue
Unfortunately, Putting this into draft until we can introduce a breaking change into our API's |
So, this was a strange one. The way we were opening
about:blank
and handles was a bit strange. Using the Safari driver going to any website would would causeNoSuchWindowException
error. This would consistently throw when testing locally. After some digging, it appears when we calleddriver.executeScript("window.open('about:blank', '_blank')");
and attempt toswitchTo()
to the new window it would cause open theabout:blank
page and cause the current handle (the page being analyzed) to also navigate to theabout:blank
page, it appears the window handle would reference itself and not the newly opened page.To avoid doing
executeScript
and checking window handles, we can simply lean on Selenium for switching to a new window that is a tab and safely navigate toabout:blank
.I also noticed
WebDriverExtensionsTest.java
was missing a tests, so I added some there.Closes: #391