3

I am running this script that i found from https://www.npmjs.com/package/axe-reports to create human-readable reports for the Axe accessibility tool. I am running the example:

var AxeBuilder = require('axe-webdriverjs'),
    AxeReports = require('axe-reports'),
    webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
    .forBrowser('chrome') //or firefox or whichever driver you use
    .build();

var AXE_BUILDER = AxeBuilder(driver)
    .withTags(['wcag2a', 'wcag2aa']); // specify your test criteria (see aXe documentation for more info)

AxeReports.createCsvReportHeaderRow();
driver.get('https://www.google.com');
driver.wait(until.titleIs('Google'), 1000)
    .then(function () {
        AXE_BUILDER.analyze(function (results) {
            AxeReports.createCsvReportRow(results);
        });
    });
driver.get('https://www.bing.com');
driver.wait(until.titleIs('Bing'), 1000)
    .then(function () {
        AXE_BUILDER.analyze(function (results) {
            AxeReports.createCsvReportRow(results);
        });
    });
driver.quit();

This is the error that i get:

Command prompt error message

monkey123
  • 183
  • 1
  • 3
  • 11

2 Answers2

0

try this:

var selenium = require("selenium-webdriver"),
  AxeBuilder = require("axe-webdriverjs"),
  AxeReports = require("axe-reports");

describe("Accessibility", function() {
  var driver;

  beforeEach(function(done) {
    driver = new selenium.Builder().forBrowser("chrome").build();

    driver.get("https://www.google.com").then(function() {
      done();
    });
  });

  // Close website after each test is run (so it is opened fresh each time)
  afterEach(function(done) {
    driver.quit().then(function() {
      done();
    });
  });

  it("should analyze the page with aXe", function(done) {
    AxeBuilder(driver).analyze(function(results) {
      console.log(
        "Accessibility Violations stored in aXe-test-results, # of violations: ",
        results.violations.length
      );
      if (results.violations.length > 0) {
        AxeReports.processResults(results, "csv", "aXe-test-results", true);
      }
      expect(results.violations.length).toBe(0);
      done();
    });
  });
});
0

You can use axe-playwright. This package contains wrapper functionalities you can directly use.

  • Add the library as a dependency:
npm i -D axe-playwright
  • Inject axe in the context of the correct page
beforeAll(async () => {
  browser = await chromium.launch();
  page = await browser.newPage();
  await page.goto(`http://localhost:3000/login`);
  await injectAxe(page);
});
  • Execute custom command to scan the accessibility with Playwright
it('simple accessibility run', async () => {
    await checkA11y(page);
  });
Abhinaba
  • 376
  • 1
  • 8