Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

Zidious
Copy link
Contributor

@Zidious Zidious commented Nov 18, 2023

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 cause NoSuchWindowException error. This would consistently throw when testing locally. After some digging, it appears when we called driver.executeScript("window.open('about:blank', '_blank')"); and attempt to switchTo() to the new window it would cause open the about:blank page and cause the current handle (the page being analyzed) to also navigate to the about: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 to about:blank.

I also noticed WebDriverExtensionsTest.java was missing a tests, so I added some there.

Closes: #391

Comment on lines +46 to +47
- dependency-name: "org.mockito:mockito-core"
versions: [ ">=5.0.0" ]
Copy link
Contributor Author

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">
Copy link
Contributor Author

@Zidious Zidious Nov 18, 2023

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

Comment on lines -124 to -128
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);
Copy link
Contributor Author

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

@Zidious Zidious marked this pull request as ready for review November 18, 2023 06:17
@Zidious Zidious requested a review from a team as a code owner November 18, 2023 06:17
selenium/pom.xml Outdated Show resolved Hide resolved
@Zidious
Copy link
Contributor Author

Zidious commented Nov 30, 2023

Unfortunately, newWindow is a Selenium 4 only function. We need to amend the solution to backwards support Selenium 3.

Putting this into draft until we can introduce a breaking change into our API's

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.

Empty tab is opened and closed in browser in the analyzePost43x private method of AxeBuilder.java class
2 participants