axe-core-npm icon indicating copy to clipboard operation
axe-core-npm copied to clipboard

when calling AxeBuilder.analyze() opens a new window at the end of a run

Open jameelakowsar opened this issue 1 year ago • 7 comments

Product: @axe-core/webdriverjs

Expectation: Analyze() should not open a new window at the end of a run

axe-core version: "^4.6.3" "@axe-core/webdriverjs": "^4.6.1",

  • Node version: v16.14.0
  • Platform: Linux

I am using selenoid to crawl a page and get the violations. My code

const {
    Builder,
    until,
    By
} = require('selenium-webdriver');
const AxeBuilder = require('@axe-core/webdriverjs');

runCrawl: async () => {
        const capabilities = {
            browserName: 'chrome',
            version: 'latest',
            chromeOptions: {
                args: [
                    '--disable-popup-blocking'
                ]
            },
            unexpectedAlertBehaviour: 'dismiss',
            'selenoid:options': {
                enableVNC: true,
                enableVideo: true,
                timeouts: {
                    pageLoad: 60000,
                    script: 30000,
                },
            }
        };
        const options = new Options();
        options.addArguments('--disable-popup-blocking');

        const driver = new Builder()
            .forBrowser('chrome')
            .usingServer('//server')
            .withCapabilities(capabilities)
            .setChromeOptions(options)
            .build();

        const url = 'https://www.google.com/'
        try {
            await driver.get(url)
            await driver.wait(async () => {
                const readyState = await driver.executeScript('return document.readyState;');
                return readyState === 'complete';
            }, 10000);

            const fromAxe = await new AxeBuilder(driver)
                .options({
                    resultTypes: ['violations']
                })
                .setLegacyMode()
                .analyze();

            const myViolations = fromAxe.violations;
        } catch (error) {
            console.error(`Failed to crawl  ${error.message}`);
            console.log('done')
        } finally {
            driver.quit();
        }
    }
    runCrawl();

I am experiencing an issue when using the AxeBuilder object in my code. Specifically, when I do not use the setLegacyMode() method, a new blank page opens which adds unnecessary time to my crawling process. I have reviewed the documentation and attempted to use the setLegacyCode() parameter, but I understand that it will soon be deprecated in v5 of the axe-core library. Additionally, I have tried using multiple capabilities and Chrome options to resolve the issue, but I have not had success. I would appreciate any guidance on how to resolve this issue in a more efficient manner. Thank you.

Used capabilities and chrome options

await driver.manage().window().setRect({
    width: 1920,
    height: 1080
});
await driver.manage().setTimeouts({
    implicit: 5000,
    pageLoad: 30000,
    script: 30000
});
await driver.manage().deleteAllCookies();
const options = new Options();
options.addArguments('--disable-popup-blocking')
.addArguments('--headless')
        .addArguments(`--disable-extensions`)
         .addArguments(`--disable-gpu`)
         .addArguments(`--disable-dev-shm-usage`)
         .addArguments(`--no-sandbox`)
         .addArguments(`--disable-infobars`)

Checked this page too: https://github.com/dequelabs/axe-core-npm/blob/develop/packages/webdriverjs/error-handling.md

jameelakowsar avatar Apr 14 '23 10:04 jameelakowsar

Hi @michael-siek Can you please help me to resolve this?

jameelakowsar avatar Apr 14 '23 10:04 jameelakowsar

Hey @jameelakowsar,

As part of the finishRun() method we pass partial run in to a new window which should close after analyzing. When using setLegacyMode() it does not utilize finishRun() so it does not have the need to open a new window.

Ref: https://github.com/dequelabs/axe-core-npm/blob/develop/packages/webdriverjs/src/index.ts#L247-L268

michael-siek avatar Apr 14 '23 12:04 michael-siek

Hey @michael-siek ,

Thank you for your response. If I may ask, is this part of crawling and will it not cause any additional loading time? Additionally, is it considered expected behavior if it opens a blank tag more than once?

jameelakowsar avatar Apr 15 '23 08:04 jameelakowsar

@jameelakowsar do you mind clarifying your question? WebDriverjs doesn't crawl, the expected additional time is just axe-core running with the test driver.

michael-siek avatar Apr 16 '23 02:04 michael-siek

My bad, I am currently using AxeBuilder to analyze the page, using the following code: const info = await new AxeBuilder(driver).analyze() However, I have observed that when a new page is opened for scanning, a blank page also appears (which I have since learned is a default behavior). I was wondering if this blank page is increasing the scanning time or is it an internal part.

is it considered expected behavior if it opens a blank tag more than once? @michael-siek

jameelakowsar avatar Apr 17 '23 05:04 jameelakowsar

Hey @jameelakowsar,

As part of the finishRun() method we pass partial run in to a new window which should close after analyzing. When using setLegacyMode() it does not utilize finishRun() so it does not have the need to open a new window.

Ref: https://github.com/dequelabs/axe-core-npm/blob/develop/packages/webdriverjs/src/index.ts#L247-L268

Hi @michael-siek could you help to figure out why did we do so? I mean why need to be opened a blank tab ?

udarrr avatar Jan 17 '24 08:01 udarrr