在Windows 7上使用Ax可访问性工具运行node js脚本时遇到问题。

时间:2018-08-15 18:50:14

标签: node.js bash automated-tests accessibility uiaccessibility

我正在运行从https://www.npmjs.com/package/axe-reports找到的脚本,以为Ax可访问性工具创建易于阅读的报告。我正在运行示例:

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();

这是我得到的错误:

Command prompt error message

2 个答案:

答案 0 :(得分:0)

尝试:

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();
    });
  });
});

答案 1 :(得分:0)

您可以使用axe-playwright。该软件包包含可直接使用的包装器功能。

  • 将库添加为依赖项:
npm i -D axe-playwright
  • 在正确的axe上下文中注入page
beforeAll(async () => {
  browser = await chromium.launch();
  page = await browser.newPage();
  await page.goto(`http://localhost:3000/login`);
  await injectAxe(page);
});
  • 执行自定义命令以使用Playwright扫描辅助功能
it('simple accessibility run', async () => {
    await checkA11y(page);
  });