dequelabs / axe-core-npm

Mozilla Public License 2.0
592 stars 67 forks source link

WebdriverJS with the Safari driver causes noSuchWindowException #936

Closed Zidious closed 5 months ago

Zidious commented 9 months ago

Product

webdriverjs

Product Version

4.8.0

Latest Version

Issue Description

Expectation

Print axe results

Actual

Throws an error

How to Reproduce

const { AxeBuilder } = require("@axe-core/webdriverjs");
const { Builder } = require("selenium-webdriver");

(async () => {
  const driver = new Builder().forBrowser("safari").build();
  await driver.get("https://www.google.com");

  const results = await new AxeBuilder(driver).analyze();
  console.log(results);

  await driver.quit();
})();

Additional context

Run into the same issue in Ruby and Java.

We should look to to removing: https://github.com/dequelabs/axe-core-npm/blob/5fcb30f8be6bdcd196484384efd0e036b0bc5184/packages/webdriverjs/src/index.ts#L276-L285

In favour of something like:

try {
  await driver.switchTo().newWindow('tab')
  await driver.get('about:blank');
} catch (error) {
  throw new Error(
    `switchTo failed. Are you using updated browser drivers? \nDriver reported:\n${error}`
  );
}

Selenium doesn't appear to document the above in their docs, but it's available within their source code

padmavemulapati commented 5 months ago

Verified this with the latest RC-build (4.9.1-4cb64b0.0 ) I am seeing below error when executing on safari (working fine on chrome and firefox)

dq_padmavathi@DQPadmavathi-MacBook-Pro axe-core-npm % node tests/wdjs.js               
/Users/dq_padmavathi/Desktop/DevtoolsAutomation/qa-axe-devtools-api-daf/axe-core-npm/node_modules/selenium-webdriver/remote/index.js:256
              let cancelToken = earlyTermination.catch((e) => reject(Error(e.message)))
                                                                     ^

Error: Server terminated early with status 1
    at /Users/dq_padmavathi/Desktop/DevtoolsAutomation/qa-axe-devtools-api-daf/axe-core-npm/node_modules/selenium-webdriver/remote/index.js:256:70
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.11.1

for this axe-core/webdriverjs -version is 4.9.1-4cb64b0.0 selenium-webdriver- version is 4.19.0, which is latest`

Code used

const { AxeBuilder } = require("@axe-core/webdriverjs");
const { Builder } = require("selenium-webdriver");

(async () => {
  const driver = new Builder().forBrowser("safari").build();
  await driver.get("https://www.google.com");

  const results = await new AxeBuilder(driver).analyze();
  console.log(results);

  await driver.quit();
})();

and enabled the 'Allow Remote Automation' option in Safari's Develop menu also to control Safari via WebDriver

Environment:

Label Value
Product axe-core-npm
Version 4.9.1-4cb64b0.0
Selenium-webdriver-Version 4.19.0
OS-Details _MACOS-Sonoma14.4 and Windows 11
BrowserDetails Chrome Version 123.0.6312.87 && Firefox 123.0.1

@Zidious / @michael-siek can you please take a look into this

Note: Tried with Axe-core/webdriverjs@next version - 4.8.6-b72c735.0" andselenium-webdriver-4.17.0` too same error getting

scottmries commented 5 months ago

I'm not able to reproduce this, but I wonder if it's because of the requirement to enable safaridriver. If it is, how do we disable safaridriver locally to verify manually, and then test?

padmavemulapati commented 5 months ago

Getting the results when executing on Safari Browser, Valdiated with the RC-build -4.9.1-4cb64b0.0 Steps validated:

1. create a directory and cd to that
2. npm init -y
3. npm i @axe-core/webdriverjs@rc
4. npm i selenium-webdriver
5. create a test file 'test.js' with contents -
const { AxeBuilder } = require("@axe-core/webdriverjs");
const { Builder } = require("selenium-webdriver");

(async () => {
  const driver = new Builder().forBrowser("safari").build();
  await driver.get("https://www.google.com/");

  const results = await new AxeBuilder(driver).analyze();
  console.log(results);

  await driver.quit();
})();
Execute with - node test.js

Gettting the Results: image

Result file attaching with .txt. format

result.txt

Environment:

Label Value
Product axe-core-npm
Version 4.9.1-4cb64b0.0
Selenium-webdriver-Version 4.19.0
OS-Details _MACOS-Sonoma14.4
BrowserDetails Chrome Version 123.0.6312.87 , Safari Version 17.4.1 (19618.1.15.11.14) && Firefox 123.0.1