我正在运行从 https://www.npmjs.com/package/axe-reports 中找到的脚本为 Axe 辅助工具创建人类可读的报告。我正在运行示例:
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();
这是我得到的错误:
最佳答案
试试这个:
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();
});
});
});
关于node.js - 在 Windows 7 上使用 Ax 辅助工具运行 Node js 脚本时遇到问题。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51864691/