dequelabs / axe-core-maven-html

Tools for using axe for web accessibility testing with JUnit, Selenium, and Playwright
Mozilla Public License 2.0
81 stars 102 forks source link

fix(selenium): ensure switchTo() does not fail using SafariDriver #392

Closed Zidious closed 9 months ago

Zidious commented 10 months ago

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: https://github.com/dequelabs/axe-core-maven-html/issues/391

Zidious commented 10 months ago

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