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

Java Lang Runtime Exception: switchToWindow failed. Are you using updated browser drivers? Please check out #444

Closed reWireByAutomation closed 7 months ago

reWireByAutomation commented 7 months ago

Hi Team, I am trying to execute axe-core latest version library on deque demo site with one Java class using Selenium latest version , encountered below mentioned Java Runtime exception.

java.lang.RuntimeException: switchToWindow failed. Are you using updated browser drivers? Please check out https://github.com/dequelabs/axe-core-maven-html/blob/develop/error-handling.md at com.deque.html.axecore.extensions.WebDriverExtensions.openAboutBlank(WebDriverExtensions.java:148) at com.deque.html.axecore.selenium.AxeBuilder.analyzePost43x(AxeBuilder.java:804) at com.deque.html.axecore.selenium.AxeBuilder.analyzeRawContext(AxeBuilder.java:658) at com.deque.html.axecore.selenium.AxeBuilder.analyze(AxeBuilder.java:613)

Caused by: java.lang.RuntimeException: Unable to determine window handle at com.deque.html.axecore.extensions.WebDriverExtensions.openAboutBlank(WebDriverExtensions.java:141) ... 4 more

Simple Java Project Details: Java Project with Gradle Java Version: openjdk 11.0.21 2023-10-17 LTS OpenJDK Runtime Environment Microsoft-8519785 (build 11.0.21+9-LTS) OpenJDK 64-Bit Server VM Microsoft-8519785 (build 11.0.21+9-LTS, mixed mode)

Gradle Version: 7.6.3 Selenium Version: 4.18.1 axe-core version: 4.8.2 Chrome Version: 122 application: https://dequeuniversity.com/demo/mars/

PFA Project File: accessibilitypoc.zip

Request your response here Thanks, rewirechannel

Zidious commented 7 months ago

Hey @reWireByAutomation,

Thanks for reporting, I can take a look this afternoon and get back to you!

Zidious commented 7 months ago

Hey @reWireByAutomation,

I am not able to replicate your error, below is example of what I am executing:

Within my build.grade:

    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
    implementation 'org.seleniumhq.selenium:selenium-java:4.18.1'
    // https://mvnrepository.com/artifact/com.deque.html.axe-core/selenium
    implementation 'com.deque.html.axe-core:selenium:4.8.2'

A quick example to run:

import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.selenium.AxeBuilder;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Main {
    public static void main(String[] args) {

        AxeBuilder axeBuilder = new AxeBuilder();
        WebDriver driver = new ChromeDriver();

        driver.get("https://dequeuniversity.com/demo/mars/");

        try {
            Results results = axeBuilder.analyze(driver);
            results.getViolations().forEach(violation -> System.out.println(violation.getId()));
        } catch (RuntimeException e) {
            e.printStackTrace();
        } finally {
            driver.close();
        }
    }
}

Output:

button-name
color-contrast
frame-title
html-has-lang
image-alt
landmark-unique
link-in-text-block
link-name
region
select-name
tabindex

Process finished with exit code 0

Unfortunately for security we cannot download ZIP files. Would it be possible to either share it here and/or host in a repository and how you're running these tests?

reWireByAutomation commented 7 months ago

Hi,

As requested, PFA project zip file.

I see failures at the statement " Results results = axeBuilder.analyze(driver);"

I am using the Open JDK 11 version. Refer below

openjdk 11.0.21 2023-10-17 LTS OpenJDK Runtime Environment Microsoft-8519785 (build 11.0.21+9-LTS) OpenJDK 64-Bit Server VM Microsoft-8519785 (build 11.0.21+9-LTS, mixed mode)

Thanks and regards Kiran Edupuganti @reWireByAutomation https://www.youtube.com/channel/UC6sujnWmnjfymbp2TqXr0HQ

On Fri, Mar 22, 2024 at 3:09 PM Gabe @.***> wrote:

Hey @reWireByAutomation https://github.com/reWireByAutomation,

I am not able to replicate your error, below is example of what I am executing:

Within my build.grade:

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation 'org.seleniumhq.selenium:selenium-java:4.18.1'
// https://mvnrepository.com/artifact/com.deque.html.axe-core/selenium
implementation 'com.deque.html.axe-core:selenium:4.8.2'

A quick example to run:

import com.deque.html.axecore.results.Results;import com.deque.html.axecore.selenium.AxeBuilder;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver; public class Main { public static void main(String[] args) {

    AxeBuilder axeBuilder = new AxeBuilder();
    WebDriver driver = new ChromeDriver();

    driver.get("https://dequeuniversity.com/demo/mars/");

    try {
        Results results = axeBuilder.analyze(driver);
        results.getViolations().forEach(violation -> System.out.println(violation.getId()));
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        driver.close();
    }
}

}

Output:

button-name color-contrast frame-title html-has-lang image-alt landmark-unique link-in-text-block link-name region select-name tabindex

Process finished with exit code 0

Unfortunately for security we cannot download ZIP files. Would it be possible to either share it here and/or host in a repository and how you're running these tests?

— Reply to this email directly, view it on GitHub https://github.com/dequelabs/axe-core-maven-html/issues/444#issuecomment-2015828348, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFA7IQIZPQ6WKCT5UDZQGKLYZSFXJAVCNFSM6AAAAABFCWPCQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJVHAZDQMZUHA . You are receiving this because you were mentioned.Message ID: @.***>

Zidious commented 7 months ago

Sorry - we cannot download ZIP files due to security. Are you able to provide the entire code snippet or host the project on github?

reWireByAutomation commented 7 months ago

Hi Gabe,

I got some time today and did some deeper analysis.

Thanks for your support here. Yes, I can host projects in the GitHub repository. But the code is very simple like the code you have provided, I figured out RCA on this issue, the below chrome option caused a Java Runtime exception

// chromeOptions.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));

I don't see the exception if I run the code without the above-mentioned "Chrome option".

For reference, below is my code in the plain java class.

public class DequeDemoSite {

public static WebDriver driver = null;

public static void main(String[] args) throws InterruptedException {

    try {

        ChromeOptions chromeOptions = getChromeOptions();
      //  chromeOptions.setExperimentalOption("excludeSwitches",

List.of("disable-popup-blocking")); chromeOptions.addArguments("--start-maximized"); chromeOptions.addArguments("--remote-allow-origins=*");

        AxeBuilder axeBuilder = new AxeBuilder();
        driver = new ChromeDriver(chromeOptions);
        driver.get("https://dequeuniversity.com/demo/mars/");

        Results results = axeBuilder.analyze(driver);
        System.out.println("Total Number of Violations: " +

results.getViolations().size()); results.getViolations().forEach(violation -> System.out.println(violation.getId())); System.out.println("Results Error Message: " + results.getErrorMessage());

    } catch (RuntimeException e){
        e.printStackTrace();
    } finally {
        driver.close();
    }

}

private static ChromeOptions getChromeOptions() {
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBrowserVersion(String.valueOf("123"));
    chromeOptions.setPlatformName("Windows");
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    chromeOptions.setAcceptInsecureCerts(true);
    chromeOptions.setImplicitWaitTimeout(Duration.ofMillis(5000));
    chromeOptions.setPageLoadTimeout(Duration.ofMillis(300000));

chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS); return chromeOptions; }

}

Please enable the "Chrome option" which is commented on in the code and run it. Could you please share information on this? Also without the AxeBuilder analysis test, this option is running fine. I don't see any exceptions.

Additionally, I need some information. I don't see any of the deque blogs stating a summary of the report that presents violations along with details after execution. I wanted to present results into the report after analysis which gives inputs to teams for further analysis on the violations and fixes.

It would be more helpful if you could point to the right wiki of the methods that this library has and present the results in the report.

Kiran Edupuganti @.** https://www.youtube.com/channel/UC6sujnWmnjfymbp2TqXr0HQ Medium Blogging:* reWireByAutomation Blog https://rewirebyautomation.medium.com/

On Mon, Mar 25, 2024 at 8:27 AM Gabe @.***> wrote:

Sorry - we cannot download ZIP files due to security. Are you able to provide the entire code snippet or host the project on github?

— Reply to this email directly, view it on GitHub https://github.com/dequelabs/axe-core-maven-html/issues/444#issuecomment-2018008415, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFA7IQLUKF5FGE2JKPXMIXLY2AQ5VAVCNFSM6AAAAABFCWPCQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJYGAYDQNBRGU . You are receiving this because you were mentioned.Message ID: @.***>

Zidious commented 7 months ago

Thank you! I will take a look tomorrow and provide findings shortly after

reWireByAutomation commented 7 months ago

Hi ,

I have uploaded the project in the public repository - https://github.com/reWireByAutomation/accessibilitypoc. You may look at it.

Kiran Edupuganti @.** https://www.youtube.com/channel/UC6sujnWmnjfymbp2TqXr0HQ Medium Blogging:* reWireByAutomation Blog https://rewirebyautomation.medium.com/

On Wed, Mar 27, 2024 at 7:25 PM Gabe @.***> wrote:

Thank you! I will take a look tomorrow and provide findings shortly after

— Reply to this email directly, view it on GitHub https://github.com/dequelabs/axe-core-maven-html/issues/444#issuecomment-2024193490, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFA7IQK6554PSFTOC4NCSMDY2NIO5AVCNFSM6AAAAABFCWPCQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRUGE4TGNBZGA . You are receiving this because you were mentioned.Message ID: @.***>

Zidious commented 7 months ago

Hey @reWireByAutomation,

This chrome option:

chromeOptions.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));

Is not disabling popups but in-fact blocking popups, also suggested by Seleniums docs. As part of analyze() we require opening a blank page to finish the analysis. Disabling popups will cause the SwitchToWindow exception to throw.

reWireByAutomation commented 7 months ago

H,

Thanks for the update, I think we can close this ticket as this option is not advisable to use while doing analysis.

Hope hosted project is accessible to you. Please confirm.

Also, I have posted the below question earlier. Do you have any thoughts on this? Appreciate your help.

Additionally, I don't see any of the deque blogs stating a summary of the report that presents violations along with details after execution and analysis. I wanted to present results into the report after analysis which gives inputs to teams for further analysis on the violations and fixes.

Kiran Edupuganti @.** https://www.youtube.com/channel/UC6sujnWmnjfymbp2TqXr0HQ Medium Blogging:* reWireByAutomation Blog https://rewirebyautomation.medium.com/

On Thu, Mar 28, 2024 at 11:31 AM Gabe @.***> wrote:

Hey @reWireByAutomation https://github.com/reWireByAutomation,

This chrome option:

chromeOptions.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));

Is not disabling popups but in-fact blocking popups, also suggested by Seleniums docs https://www.selenium.dev/documentation/webdriver/browsers/chrome/#excluding-arguments. As part of analyze() we open a blank page to finish the analysis. Disabling popups will cause the SwitchToWindow exception to throw https://github.com/dequelabs/axe-core-maven-html/blob/c91e5ae030dec6b24d0755972c0fbb87a190909a/selenium/src/main/java/com/deque/html/axecore/extensions/WebDriverExtensions.java#L148-L151 .

— Reply to this email directly, view it on GitHub https://github.com/dequelabs/axe-core-maven-html/issues/444#issuecomment-2025634275, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFA7IQL5PNHY367ZQNHXGLTY2QZUDAVCNFSM6AAAAABFCWPCQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRVGYZTIMRXGU . You are receiving this because you were mentioned.Message ID: @.***>

Zidious commented 7 months ago

Thanks for the update, I think we can close this ticket as this option is not advisable to use while doing analysis. Hope hosted project is accessible to you. Please confirm.

Yep! I got your code example from https://github.com/reWireByAutomation/accessibilitypoc/blob/master/src/main/java/org/accessibility/poc/dequelabs/DequeDemoSite.java.

Additionally, I need some information. I don't see any of the deque blogs stating a summary of the report that presents violations along with details after execution. I wanted to present results into the report after analysis which gives inputs to teams for further analysis on the violations and fixes.

We have a AxeReporter class for writing axe-results to file if that's what you're looking for. Otherwise, we have extensive reporting capabilities with our axe-devtools-maven-html integrations: https://docs.deque.com/devtools-html/4.0.0/en/java-generate-reports.

Zidious commented 7 months ago

Closing as completed.