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

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

Closed
tvtester opened this issue Feb 25, 2022 · 11 comments · Fixed by #412
Assignees
Labels
next up Ticket is groomed for next sprint PRIORITY: high High priority item; should be scheduled in this or next sprint QA SIGNOFF: passed This ticket has passed QA

Comments

@tvtester
Copy link

Following method is opening empty tab in the browser at the code: String prevWindow = WebDriverExtensions.openAboutBlank(webDriver); and WebDriverExtensions.closeAboutBlank(webDriver, prevWindow);

`private Results analyzePost43x(final WebDriver webDriver, final Object rawContextArg) {
String rawOptionsArg = getOptions().equals("{}")
? AxeReporter.serialize(runOptions) : getOptions();

ArrayList<Object> partialResults;
try {
  partialResults = runPartialRecursive(webDriver, rawOptionsArg, rawContextArg, true);
} catch (RuntimeException re) {
  if (re.getMessage().contains("Unable to inject axe script")) {
    throw re;
  }
  return buildErrorResults(re);
}

String prevWindow = WebDriverExtensions.openAboutBlank(webDriver);
injectAxe(webDriver);
Object resResponse;
try {
  resResponse = WebDriverInjectorExtensions.executeScript(webDriver, finishRunScript, partialResults);
} catch (Exception e) {
  throw new RuntimeException("axe.finishRun failed. Please check out https://github.com/dequelabs/axe-core-maven-html/blob/develop/error-handling.md", e);

}
WebDriverExtensions.closeAboutBlank(webDriver, prevWindow);
Results res = objectMapper.convertValue(resResponse, Results.class);


return res;

}`

Product:

Expectation: Empty or additional tab should not be open in the browser

Actual: Driver is opening empty tab and close it, though there is no need of it

Motivation:


axe-core version: X.Y.Z
axe-webdriver, extension or other integration version: X.Y.Z

Browser and Assistive Technology versions

For Tooling issues:
- Node version: XX  
- Platform:  
@WilcoFiers
Copy link
Contributor

@tvtester This is intentional. As of axe-core 4.3 a number of operations are run in an isolated context. That's what the blank frame is for. This is to improve integrity and security of the results.

Are you experiencing any difficulties because of this change? We've attempted to do this in a way that was unlikely to impact the environment, although admittedly this does have some impact on performance.

@rshidling
Copy link

rshidling commented Mar 29, 2022

For Safari Browser I am getting the below error , however for Chrome, FF and Edge there is not issue at all.

org.openqa.selenium.NoSuchWindowException: Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z' System info: host:, os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202' Driver info: org.openqa.selenium.remote.RemoteWebDriver Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 15.0, javascriptEnabled: true, platform: MAC, platformName: MAC, safari:automaticInspection: false, safari:automaticProfiling: false, safari:diagnose: false, safari:platformBuildVersion: 20G165, safari:platformVersion: 11.6, safari:useSimulator: false, setWindowRect: true, strictFileInteractability: false, webdriver.remote.sessionid: 5423BD3E-DA04-4A24-8A59-A99..., webkit:WebRTC: {DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}} Session ID: 5423BD3E-DA04-4A24-8A59-A99216287B4E at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:899) at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:910) at com.deque.html.axecore.extensions.WebDriverExtensions.closeAboutBlank(WebDriverExtensions.java:148) at com.deque.html.axecore.selenium.AxeBuilder.analyzePost43x(AxeBuilder.java:620) at com.deque.html.axecore.selenium.AxeBuilder.analyzeRawContext(AxeBuilder.java:527) at com.deque.html.axecore.selenium.AxeBuilder.analyze(AxeBuilder.java:485) at globalLibrary.AccessibilityUtils.axeCore(AccessibilityUtils.java:410) at globalLibrary.AccessibilityUtils.testAccessibilityWithWCAGStandards(AccessibilityUtils.java:550) at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134) at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:240) at com.test.globaldriver.Testbase.run(Testbase.java:3280) at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:252) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:593) at org.testng.internal.TestInvoker.retryFailed(TestInvoker.java:213) at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:58) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.util.ArrayList.forEach(Unknown Source) at org.testng.TestRunner.privateRun(TestRunner.java:766) at org.testng.TestRunner.run(TestRunner.java:587) at org.testng.SuiteRunner.runTest(SuiteRunner.java:384) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337) at org.testng.SuiteRunner.run(SuiteRunner.java:286) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187) at org.testng.TestNG.runSuitesLocally(TestNG.java:1109) at org.testng.TestNG.runSuites(TestNG.java:1039) at org.testng.TestNG.run(TestNG.java:1007) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

@straker
Copy link
Contributor

straker commented Mar 29, 2022

@rshidling Interesting. Does the error happen on a specific url, or does the error always happen for any url? If it's a specific url, are you able to share the url?

@sriramkukkadapu
Copy link

sriramkukkadapu commented Feb 26, 2023

I am facing this same issue. @straker

PFA code. I am using selenium latest version ad axe dependency also latest version.

Code:

package Accessibility_AXECore;
import java.io.IOException;
import javax.naming.OperationNotSupportedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.deque.html.axecore.extensions.WebDriverExtensions;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.selenium.AxeBuilder;
public class ChromeTestAccessibility {
    public static void main(String args[]) throws OperationNotSupportedException, IOException {
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.co.in");
//        Results results = WebDriverExtensions.analyze(driver);
        Results results = new AxeBuilder().analyze(driver);
        System.out.println(results.toString());
        driver.quit();
    }
}

Error i am facing:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Starting ChromeDriver 2.40.565386 (45a059dc425e08165f9a10324bd1380cc13ca363) on port 15441
Only local connections are allowed.
Feb 26, 2023 1:25:28 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 110, so returning the closest version found: 109
Exception in thread "main" java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:423)
at com.deque.html.axecore.extensions.WebDriverExtensions.closeAboutBlank(WebDriverExtensions.java:146)
at com.deque.html.axecore.selenium.AxeBuilder.analyzePost43x(AxeBuilder.java:610)
at com.deque.html.axecore.selenium.AxeBuilder.analyzeRawContext(AxeBuilder.java:505)
at com.deque.html.axecore.selenium.AxeBuilder.analyze(AxeBuilder.java:463)
at Accessibility_AXECore.ChromeTestAccessibility.main(ChromeTestAccessibility.java:24)

Maven dependencies that i have

	<dependency>
	    <groupId>com.deque.html.axe-core</groupId>
	    <artifactId>selenium</artifactId>
	    <version>4.5.1</version>
	</dependency>
	
	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-java</artifactId>
			<version>4.8.0</version> 
	</dependency>
	
	<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-devtools-v108 -->
	<dependency>
	    <groupId>org.seleniumhq.selenium</groupId>
	    <artifactId>selenium-devtools-v108</artifactId>
	    <version>4.8.0</version>
	</dependency>	

@pankaj-sukale
Copy link

Do we have any update on this ? Are we planning any fix ?

@benken-parasoft
Copy link

I occasionally run into the same NoSuchWindowException when testing on Safari. It seems rather sporadic.

@straker
Copy link
Contributor

straker commented Nov 17, 2023

@pankaj-sukale @benken-parasoft are both of you also experiencing this using one of the axe-core-maven pacakges? If so I may move this issue to that repository for better tracking.

@benken-parasoft
Copy link

benken-parasoft commented Nov 17, 2023

I am using the "com.deque.html.axe-core:selenium" Maven Java library.
I have been working around this issue by catching the NoSuchWindowException and trying again:

import org.openqa.selenium.WebDriver;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.selenium.AxeBuilder;
...
    static Results analyze(AxeBuilder builder, WebDriver webDriver) {
        try {
            return builder.analyze(webDriver);
        } catch (NoSuchWindowException e) {
            // retry if NoSuchWindowException is thrown
            // see issue https://github.com/dequelabs/axe-core-maven-html/issues/391
            return builder.analyze(webDriver);
        }
    }

I only run into this issue on Safari on macOS where the NoSuchWindowException happens a bit randomly. I also test with Chrome, Edge, and Firefox on Linux, macOS, and Windows but never see the issue in those environments.

@straker
Copy link
Contributor

straker commented Nov 17, 2023

Thanks for the info. I'm going to port this issue to axe-core-maven repository as it looks like it's a Java issue, and more specifically could be a Safari and MacOs issue.

@straker straker transferred this issue from dequelabs/axe-core Nov 17, 2023
@Zidious Zidious self-assigned this Nov 18, 2023
@straker
Copy link
Contributor

straker commented Nov 30, 2023

We've identified the issue and will work on getting a fix in place that works for our supported versions of Selenium. Until then you can mitigate this issue by using setLegacyMode(true) before analyzing. Just note that legacy mode is deprecated and will be removed in v5.0.

@dequejenn dequejenn added PRIORITY: high High priority item; should be scheduled in this or next sprint next up Ticket is groomed for next sprint labels Nov 30, 2023
@padmavemulapati
Copy link

Verified with the latest QA-Build (4.8.1-SNAPSHOT/4.8.1-20240109.201525-1) , With Safari driver we were able to run the axe-core-maven-html tests successfully. not seeing any exceptions or failures.

Code tested:

package com.deque;

import static com.deque.html.axecore.selenium.AxeReporter.getAxeResultString;
import static com.deque.html.axecore.selenium.AxeReporter.getReadableAxeResults;
import static org.junit.Assert.assertEquals;

import com.deque.html.axecore.providers.FileAxeScriptProvider;
import com.deque.html.axecore.results.CheckedNode;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.results.Rule;
import com.deque.html.axecore.selenium.AxeBuilder;
import com.deque.html.axecore.selenium.AxeReporter;

import java.io.File;
import java.io.IOException;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.naming.OperationNotSupportedException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;



import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.openqa.selenium.safari.SafariDriver;
/** The example tests using the updated files. */
public class SeleniumJavaTest {
    private WebDriver webDriver;
    static String rootPath = System.getProperty("user.dir");
    String baseUrl = "http://abcdcomputech.dequecloud.com/";
 /** Instantiate the WebDriver and navigate to the test site */
    @Before
    public void setUp() {
          webDriver = new SafariDriver();
       
    }

    /** Ensure we close the WebDriver after finishing */
    @After
    public void tearDown() {
       if (webDriver != null) {
            webDriver.quit();
        }
    }

    /** Basic test */
    @Test
    public void completePageScanTest() {
        this.webDriver.get(baseUrl);
        Results result = new AxeBuilder().analyze(webDriver);
        Assert.assertEquals(8, result.getViolations().size()); 
    }
public static int getViolationsCount(String reportName) {
        JSONParser parser = new JSONParser();
        String filePath = rootPath + File.separator + "src/test/java/results/"+ reportName  + ".json";
        int i=0;
        try {
            Object obj = parser.parse(new FileReader(filePath));
            JSONObject jsonObject = (JSONObject)obj;
            String url = (String)jsonObject.get("url");
            System.out.println("url: " + url);
            JSONArray violations = (JSONArray)jsonObject.get("violations");
            return violations.size();
            
        } catch(Exception e) {
            e.printStackTrace();
        }
       return i;
    }
}

image

Environment:

Label Value
Product axe-core-maven-html
Version _ 4.8.1-SNAPSHOT/4.8.1-20240109.201525-1_
OS-Details _MAC- Intel Core i7 - 11.6.8 & Windows11 _
BrowserDetails Chrome Version 120.0.6099.129 (Official Build) (64-bit) & Firefox 121.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next up Ticket is groomed for next sprint PRIORITY: high High priority item; should be scheduled in this or next sprint QA SIGNOFF: passed This ticket has passed QA
Projects
None yet
10 participants