dequelabs / axe-core-maven-html

Tools for using axe for web accessibility testing with JUnit, Selenium, and Playwright

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

java.lang.RuntimeException: Unable to inject axe script

satheesh6789 opened this issue · comments

`public class SampleTestWeb2 {

WebDriver driverLocal;
private static List<String> tags = Arrays.asList("wcag2a", "wcag2aa", "wcag2aaa", "wcag21a", "wcag21aa", "wcag21aaa");

@BeforeMethod
public void beforeMethod() {
	System.setProperty("webdriver.chrome.driver", "driverpath");
	driverLocal = new ChromeDriver();
	driverLocal.manage().window().maximize();
	driverLocal.get("https://www.google.com/");

}

@Test
public void sampleTest() {
   AxeBuilder axeBuilder= new AxeBuilder();
   axeBuilder.withTags(tags);
   	try {	
		Results responseJson = axeBuilder.analyze(driverLocal);
		List<Rule> violations = responseJson.getViolations();
		if(violations.size()==0) {
		System.out.println("NO violations found");
		}
		Assert.assertTrue(responseJson.violationFree());
		
	}catch(RuntimeException e) {
		e.printStackTrace();
	} }

@AfterMethod
public void afterMethod() {
driverLocal.close();
}}`

Console log:

[1678206674.807][WARNING]: virtual void DevToolsClientImpl::AddListener(DevToolsEventListener *) subscribing a listener to the already connected DevToolsClient. Connection notification will not arrive.
Mar 07, 2023 10:01:14 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
java.lang.RuntimeException: Unable to inject axe script
at com.deque.html.axecore.selenium.AxeBuilder.analyzeRawContext(AxeBuilder.java:448)
at com.deque.html.axecore.selenium.AxeBuilder.analyze(AxeBuilder.java:402)
at SampleTestWeb2.sampleTest(SampleTestWeb2.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
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:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
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)
Caused by: org.openqa.selenium.JavascriptException: javascript error: Unexpected token '<'
(Session info: chrome=110.0.5481.177)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '11.6', java.version: '17.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 110.0.5481.177, chrome: {chromedriverVersion: 110.0.5481.77 (65ed616c6e8e..., userDataDir: /var/folders/gb/cmsdz1vn5fb...}, goog:chromeOptions: {debuggerAddress: localhost:62612}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: b4e3de97873924736a55073fca341516
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
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.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489)
at com.deque.html.axecore.extensions.WebDriverInjectorExtensions.inject(WebDriverInjectorExtensions.java:78)
at com.deque.html.axecore.extensions.WebDriverInjectorExtensions.inject(WebDriverInjectorExtensions.java:64)
at com.deque.html.axecore.selenium.AxeBuilder.analyzeRawContext(AxeBuilder.java:445)
... 30 more

commented

Hey @satheesh6789,

We will investigate and get back to you shortly

commented

Using the below snippet on latest version 4.6.0 of our Selenium package I was unable to reproduce the error.

  AxeBuilder axeBuilder =
        new AxeBuilder()
            .withTags(
                Arrays.asList("wcag2a", "wcag2aa", "wcag2aaa", "wcag21a", "wcag21aa", "wcag21aaa"));

    WebDriver webDriver = new ChromeDriver(new ChromeOptions().setHeadless(false));
    webDriver.manage().window().maximize();

    webDriver.get("https://www.google.com/");

    Results axeResults = axeBuilder.analyze(webDriver);

    List<Rule> violations = axeResults.getViolations();

    if (violations.size() == 0) {
      System.out.println("You have 0 violations!");
    } else {
      System.out.println("Violations: \n" + violations);
    }

    webDriver.close();

Few things -

  • What version of the axe-core Selenium API are you using?
  • Does the issue still occur if you remove the code from the @ BeforeMethod hook into your @test block?

Due to Selenium-java dependency version I was facing this issue. what is least downstream version Axe can support for "Selenium-java dependency"