From d7cb365485c9a07894932f3270a2c731d0ed6efd Mon Sep 17 00:00:00 2001 From: Shunguo Date: Wed, 10 Apr 2024 11:10:55 -0500 Subject: [PATCH 01/13] Fix the browser close issue #1837 --- accessibility-checker/src-ts/bin/achecker.js | 2 +- accessibility-checker/src-ts/lib/ACHelper.ts | 64 +++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/accessibility-checker/src-ts/bin/achecker.js b/accessibility-checker/src-ts/bin/achecker.js index 146bd95e4..c88e351be 100755 --- a/accessibility-checker/src-ts/bin/achecker.js +++ b/accessibility-checker/src-ts/bin/achecker.js @@ -218,7 +218,7 @@ getInputFileList().then(async (rptInputFiles) => { } console.log(); console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`) - await aChecker.close(); + //await aChecker.close(); if (failures.length !== 0 || errors !== 0) { process.exitCode = 1; } diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index ab1cd9ce3..3b884ae26 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise { From 3c72827b14af21809ae680a8f553779377e6bb95 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Wed, 10 Apr 2024 13:46:06 -0500 Subject: [PATCH 02/13] update the accessibility-checker #1837 --- accessibility-checker/src-ts/bin/achecker.js | 79 +++++++++++--------- accessibility-checker/src-ts/lib/ACHelper.ts | 1 - 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/accessibility-checker/src-ts/bin/achecker.js b/accessibility-checker/src-ts/bin/achecker.js index c88e351be..563dc0bd0 100755 --- a/accessibility-checker/src-ts/bin/achecker.js +++ b/accessibility-checker/src-ts/bin/achecker.js @@ -181,45 +181,52 @@ getInputFileList().then(async (rptInputFiles) => { let idx = 0; let failures = []; let errors = 0; - for (let f of rptInputFiles) { - let result; - let isFile = false; - try { - isFile = fs.lstatSync(f).isFile(); - f = path.resolve(f); - } catch (e) {} - if (isFile) { - result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); - } else { - result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); - } - if (result) { - if (aChecker.assertCompliance(result.report) === 0) { - console.log("Passed:", f); + try { + for (let f of rptInputFiles) { + let result; + let isFile = false; + try { + isFile = fs.lstatSync(f).isFile(); + f = path.resolve(f); + } catch (e) {} + + if (isFile) { + result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); } else { - failures.push({ - file: f, - report: result.report - }); - console.log("Failed:", f); + result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); + } + if (result) { + if (aChecker.assertCompliance(result.report) === 0) { + console.log("Passed:", f); + } else { + failures.push({ + file: f, + report: result.report + }); + console.log("Failed:", f); + } + } else { + ++errors; + console.log("Error:", f); + } + } + if (failures.length > 0) { + console.log(); + console.log("Failing scan details:"); + console.log(); + for (const fail of failures) { + console.log(aChecker.stringifyResults(fail.report)); } - } else { - ++errors; - console.log("Error:", f); } - } - if (failures.length > 0) { - console.log(); - console.log("Failing scan details:"); console.log(); - for (const fail of failures) { - console.log(aChecker.stringifyResults(fail.report)); + console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`) + //await aChecker.close(); + if (failures.length !== 0 || errors !== 0) { + process.exitCode = 1; } - } - console.log(); - console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`) - //await aChecker.close(); - if (failures.length !== 0 || errors !== 0) { - process.exitCode = 1; - } + } catch (err) { + console.error(err); + } finally { + await aChecker.close(); + }; }) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index 3b884ae26..e4ed2e73a 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,6 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 10 Apr 2024 13:49:22 -0500 Subject: [PATCH 03/13] Update the readme #1837 --- accessibility-checker/src/README.md | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/accessibility-checker/src/README.md b/accessibility-checker/src/README.md index f61b1fd84..2303c8ad2 100644 --- a/accessibility-checker/src/README.md +++ b/accessibility-checker/src/README.md @@ -32,18 +32,26 @@ The following is how to perform an accessibility scan within your test cases and ```javascript const aChecker = require("accessibility-checker"); -// Perform the accessibility scan using the aChecker.getCompliance API -aChecker.getCompliance(testDataFileContent, testLabel).then((results) => { - const report = results.report; - - // Call the aChecker.assertCompliance API which is used to compare the results with the baseline object if we can find one that - // matches the same label which was provided. - const returnCode = aChecker.assertCompliance(report); - - // In the case that the violationData is not defined then trigger an error right away. - expect(returnCode).toBe(0, "Scanning " + testLabel + " failed."); -}); +try { + // Perform the accessibility scan using the aChecker.getCompliance API + aChecker.getCompliance(testDataFileContent, testLabel).then((results) => { + const report = results.report; + + // Call the aChecker.assertCompliance API which is used to compare the results with the baseline object if we can find one that + // matches the same label which was provided. + const returnCode = aChecker.assertCompliance(report); + + // In the case that the violationData is not defined then trigger an error right away. + expect(returnCode).toBe(0, "Scanning " + testLabel + " failed."); + }); +} catch (err) { + console.error(err); + } finally { + // close the engine + await aChecker.close(); + }; ``` +Note that it's important to close the engine, otherwise, output files for the report may not be generated properly. Refer to [Examples](https://github.com/IBMa/equal-access/tree/master/accessibility-checker/boilerplates) for sample usage scenarios. From 4f0eca60ebc48a4d2debe7baef84ce7a29a1559f Mon Sep 17 00:00:00 2001 From: Shunguo Date: Wed, 10 Apr 2024 13:56:44 -0500 Subject: [PATCH 04/13] Update achecker.js --- accessibility-checker/src-ts/bin/achecker.js | 79 +++++++++----------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/accessibility-checker/src-ts/bin/achecker.js b/accessibility-checker/src-ts/bin/achecker.js index 563dc0bd0..146bd95e4 100755 --- a/accessibility-checker/src-ts/bin/achecker.js +++ b/accessibility-checker/src-ts/bin/achecker.js @@ -181,52 +181,45 @@ getInputFileList().then(async (rptInputFiles) => { let idx = 0; let failures = []; let errors = 0; - try { - for (let f of rptInputFiles) { - let result; - let isFile = false; - try { - isFile = fs.lstatSync(f).isFile(); - f = path.resolve(f); - } catch (e) {} - - if (isFile) { - result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); - } else { - result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); - } - if (result) { - if (aChecker.assertCompliance(result.report) === 0) { - console.log("Passed:", f); - } else { - failures.push({ - file: f, - report: result.report - }); - console.log("Failed:", f); - } - } else { - ++errors; - console.log("Error:", f); - } + for (let f of rptInputFiles) { + let result; + let isFile = false; + try { + isFile = fs.lstatSync(f).isFile(); + f = path.resolve(f); + } catch (e) {} + if (isFile) { + result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); + } else { + result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); } - if (failures.length > 0) { - console.log(); - console.log("Failing scan details:"); - console.log(); - for (const fail of failures) { - console.log(aChecker.stringifyResults(fail.report)); + if (result) { + if (aChecker.assertCompliance(result.report) === 0) { + console.log("Passed:", f); + } else { + failures.push({ + file: f, + report: result.report + }); + console.log("Failed:", f); } + } else { + ++errors; + console.log("Error:", f); } + } + if (failures.length > 0) { console.log(); - console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`) - //await aChecker.close(); - if (failures.length !== 0 || errors !== 0) { - process.exitCode = 1; + console.log("Failing scan details:"); + console.log(); + for (const fail of failures) { + console.log(aChecker.stringifyResults(fail.report)); } - } catch (err) { - console.error(err); - } finally { - await aChecker.close(); - }; + } + console.log(); + console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`) + await aChecker.close(); + if (failures.length !== 0 || errors !== 0) { + process.exitCode = 1; + } }) From 84c53109d796f14b6a2d0fa31a8eb0ad09d2a351 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Wed, 10 Apr 2024 14:01:33 -0500 Subject: [PATCH 05/13] Update ACHelper.ts --- accessibility-checker/src-ts/lib/ACHelper.ts | 62 +++++++++----------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index e4ed2e73a..f21eed26f 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise { From e57f9b327dc9334e07eda3bca650e596571050b3 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Wed, 10 Apr 2024 14:03:10 -0500 Subject: [PATCH 06/13] Update ACHelper.ts --- accessibility-checker/src-ts/lib/ACHelper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index f21eed26f..b3f9cbe57 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 10 Apr 2024 14:04:19 -0500 Subject: [PATCH 07/13] Update ACHelper.ts --- accessibility-checker/src-ts/lib/ACHelper.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index b3f9cbe57..572c693b8 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,6 +153,7 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 10 Apr 2024 14:33:17 -0500 Subject: [PATCH 08/13] modify the boilerplates to properly close the engine --- .../features/step_definitions/browser_step.js | 10 +++- .../jest-customRS/matchers/toBeAccessible.js | 26 +++++---- .../jest-selenium/matchers/toBeAccessible.js | 24 +++++--- .../jest/matchers/toBeAccessible.js | 24 +++++--- .../mocha-puppeteer-ts/test-ts/basic.test.ts | 34 ++++++----- .../mocha-selenium/test/basic.test.js | 42 ++++++++------ .../boilerplates/protractor/test/spec.js | 58 ++++++++++--------- .../webdriverio/test/specs/example.e2e.ts | 26 +++++---- accessibility-checker/src-ts/lib/ACHelper.ts | 2 +- accessibility-checker/src/README.md | 12 ++-- 10 files changed, 152 insertions(+), 106 deletions(-) diff --git a/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js b/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js index adfeef83e..888a1da40 100644 --- a/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js +++ b/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js @@ -183,8 +183,8 @@ Then(/^I should see "([^"]*)"$/, function(text) { Then(/^Page is accessible with label "([^"]*)"$/, { "timeout": 30000 }, async function(label) { const world = this; - const { report } = await aChecker.getCompliance(world.driver, label); try { + const { report } = await aChecker.getCompliance(world.driver, label); // If assert fails, value is either 1 or 2 depending on if there's a baseline let assertResult = aChecker.assertCompliance(report); expect(assertResult).to.equal(0, assertResult === 1 ? "Results do not match baseline": "Failing issues found"); @@ -193,18 +193,22 @@ Then(/^Page is accessible with label "([^"]*)"$/, { "timeout": 30000 }, async fu const buffer = await world.driver.takeScreenshot(); await world.attach(buffer, 'image/png'); return Promise.reject(e); + } finally { + await aChecker.close(); } }) Then(/^Scan page for accessibility with label "([^"]*)"$/, { "timeout": 30000 }, async function(label) { const world = this; - const { report } = await aChecker.getCompliance(world.driver, label); try { + const { report } = await aChecker.getCompliance(world.driver, label); let assertResult = aChecker.assertCompliance(report); expect(assertResult).to.equal(0, assertResult === 1 ? "Results do not match baseline": "Failing issues found"); } catch (e) { world.attach(escape(aChecker.stringifyResults(report))); const buffer = await world.driver.takeScreenshot(); await world.attach(buffer, 'image/png'); - }; + } finally { + await aChecker.close(); + } }) \ No newline at end of file diff --git a/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js b/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js index f1dabe453..637d1ef98 100644 --- a/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js +++ b/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js @@ -36,16 +36,22 @@ async function toBeAccessible(node) { aChecker.addRuleset(customRuleset); } - const results = await aChecker.getCompliance(node, this.currentTestName); - if (aChecker.assertCompliance(results.report) === 0) { - return { - pass: true - } - } else { - return { - pass: false, - message: () => aChecker.stringifyResults(results.report) - }; + try { + const results = await aChecker.getCompliance(node, this.currentTestName); + if (aChecker.assertCompliance(results.report) === 0) { + return { + pass: true + } + } else { + return { + pass: false, + message: () => aChecker.stringifyResults(results.report) + }; + } + } catch (e) { + console.error(e); + } finally { + await aChecker.close(); } } diff --git a/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js b/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js index 84c25e458..04ca69af5 100644 --- a/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js +++ b/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js @@ -10,16 +10,22 @@ const aChecker = require("accessibility-checker"); async function toBeAccessible(node, label) { - let results = await aChecker.getCompliance(node, label); - if (aChecker.assertCompliance(results.report) === 0) { - return { - pass: true - } - } else { - return { - pass:false, - message: () => aChecker.stringifyResults(results.report) + try { + let results = await aChecker.getCompliance(node, label); + if (aChecker.assertCompliance(results.report) === 0) { + return { + pass: true + } + } else { + return { + pass:false, + message: () => aChecker.stringifyResults(results.report) + } } + } catch (e) { + console.error(e); + } finally { + await aChecker.close(); } } diff --git a/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js b/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js index 84c25e458..ca20b2968 100644 --- a/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js +++ b/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js @@ -10,16 +10,22 @@ const aChecker = require("accessibility-checker"); async function toBeAccessible(node, label) { - let results = await aChecker.getCompliance(node, label); - if (aChecker.assertCompliance(results.report) === 0) { - return { - pass: true - } - } else { - return { - pass:false, - message: () => aChecker.stringifyResults(results.report) + try { + let results = await aChecker.getCompliance(node, label); + if (aChecker.assertCompliance(results.report) === 0) { + return { + pass: true + } + } else { + return { + pass:false, + message: () => aChecker.stringifyResults(results.report) + } } + } catch (e) { + console.error(e); + } finally { + await aChecker.close(); } } diff --git a/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts b/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts index c139d02ce..8d2b45470 100644 --- a/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts +++ b/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts @@ -1,7 +1,7 @@ 'use strict'; import * as Puppeteer from "puppeteer"; // import { Browser, Page, launch } from "puppeteer"; -import { assertCompliance, getCompliance, stringifyResults } from "accessibility-checker"; +import { assertCompliance, getCompliance, stringifyResults, close } from "accessibility-checker"; import * as path from "path"; import { expect } from "chai"; import { before, after, describe, it } from "mocha"; @@ -27,20 +27,26 @@ after(async() => { // Describe this Suite of testscases, describe is a test Suite and 'it' is a testcase. describe("Hello World Basics", function () { - it("HomePage", async () => { - const sample = path.join(__dirname, "..", "sample", "Hello.html"); - await page.goto(`file://${sample}`); + try { + it("HomePage", async () => { + const sample = path.join(__dirname, "..", "sample", "Hello.html"); + await page.goto(`file://${sample}`); - const result = await getCompliance(page, "HOME"); - const report : ICheckerReport = result!.report as ICheckerReport; - expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); - }).timeout(10000); + const result = await getCompliance(page, "HOME"); + const report : ICheckerReport = result!.report as ICheckerReport; + expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); + }).timeout(10000); - it("Homepage, Show Card", async() => { - await page.click("#clickMe"); - const result = await getCompliance(page, "HOME_CARD"); - const report : ICheckerReport = result!.report as ICheckerReport; - expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); - }).timeout(10000); + it("Homepage, Show Card", async() => { + await page.click("#clickMe"); + const result = await getCompliance(page, "HOME_CARD"); + const report : ICheckerReport = result!.report as ICheckerReport; + expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); + }).timeout(10000); + } catch (e) { + console.error(e); + } finally { + close(); + } }); //# sourceMappingURL=basic.test.js.map diff --git a/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js b/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js index 12b593f22..cbcbe0e52 100644 --- a/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js +++ b/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js @@ -45,25 +45,31 @@ after(function(done) { // Describe this Suite of testscases, describe is a test Suite and 'it' is a testcase. describe("Hello World Basics", function () { this.timeout(0); - it("HomePage", function (done) { - const sample = path.join(__dirname, "..", "sample", "Hello.html"); - loadSeleniumTestFile(browser, sample).then(function() { - // Perform the accessibility scan using the IBMaScan Wrapper - aChecker.getCompliance(browser, "HOME", function (data, doc) { - try { - expect(aChecker.assertCompliance(data)).to.equal(0, aChecker.stringifyResults(data)); - done(); - } catch (e) { - done(e); - } + try { + it("HomePage", function (done) { + const sample = path.join(__dirname, "..", "sample", "Hello.html"); + loadSeleniumTestFile(browser, sample).then(function() { + // Perform the accessibility scan using the IBMaScan Wrapper + aChecker.getCompliance(browser, "HOME", function (data, doc) { + try { + expect(aChecker.assertCompliance(data)).to.equal(0, aChecker.stringifyResults(data)); + done(); + } catch (e) { + done(e); + } + }); }); }); - }); - it("Hompage, Show Card", async () => { - await browser.findElement({"id": "clickMe"}).click(); - let result = await aChecker.getCompliance(browser, "HOME_CARD"); - let report = result.report; - expect(aChecker.assertCompliance(report)).to.equal(0, aChecker.stringifyResults(report)); - }); + it("Hompage, Show Card", async () => { + await browser.findElement({"id": "clickMe"}).click(); + let result = await aChecker.getCompliance(browser, "HOME_CARD"); + let report = result.report; + expect(aChecker.assertCompliance(report)).to.equal(0, aChecker.stringifyResults(report)); + }); + } catch (e) { + console.error(e); + } finally { + aChecker.close(); + } }); diff --git a/accessibility-checker/boilerplates/protractor/test/spec.js b/accessibility-checker/boilerplates/protractor/test/spec.js index ac8991cad..39f678b45 100644 --- a/accessibility-checker/boilerplates/protractor/test/spec.js +++ b/accessibility-checker/boilerplates/protractor/test/spec.js @@ -2,35 +2,41 @@ const aChecker = require("accessibility-checker"); describe('Protractor Demo App', function() { - it("HomePage", function (done) { - browser.get("http://localhost:3003/Hello.html").then(function() { - // Perform the accessibility scan using the IBMaScan Wrapper - aChecker.getCompliance(browser, "HOME", function(data, doc) { - try { - console.log(data.reports[0].issues); - expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME")); - done(); - } catch (e) { - console.log(aChecker.getDiffResults("HOME")); - done(e); - } + try { + it("HomePage", function (done) { + browser.get("http://localhost:3003/Hello.html").then(function() { + // Perform the accessibility scan using the IBMaScan Wrapper + aChecker.getCompliance(browser, "HOME", function(data, doc) { + try { + console.log(data.reports[0].issues); + expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME")); + done(); + } catch (e) { + console.log(aChecker.getDiffResults("HOME")); + done(e); + } + }); }); }); - }); - it("Hompage, Show Card", function (done) { - browser.findElement({"id": "clickMe"}).click().then(function() { - // Perform the accessibility scan using the IBMaScan Wrapper - aChecker.getCompliance(browser, "HOME_CARD", function (data, doc) { - try { - expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME_CARD")); - done(); - } catch (e) { - console.log(aChecker.getDiffResults("HOME_CARD")); - done(e); - } + it("Hompage, Show Card", function (done) { + browser.findElement({"id": "clickMe"}).click().then(function() { + // Perform the accessibility scan using the IBMaScan Wrapper + aChecker.getCompliance(browser, "HOME_CARD", function (data, doc) { + try { + expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME_CARD")); + done(); + } catch (e) { + console.log(aChecker.getDiffResults("HOME_CARD")); + done(e); + } + }); }); - }); - }); + }); + } catch (e) { + console.error(e); + } finally { + aChecker.close(); + } }) \ No newline at end of file diff --git a/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts b/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts index 6c46a74a0..6605b02a1 100644 --- a/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts +++ b/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts @@ -1,17 +1,23 @@ import LoginPage from '../pageobjects/login.page' import SecurePage from '../pageobjects/secure.page' -import { getCompliance } from "accessibility-checker"; +import { getCompliance, close } from "accessibility-checker"; describe('My Login application', () => { - it('should login with valid credentials', async () => { - await LoginPage.open() - console.log(browser.constructor); - console.log(await getCompliance(browser, "TEST")); - await LoginPage.login('tomsmith', 'SuperSecretPassword!') - await expect(SecurePage.flashAlert).toBeExisting() - await expect(SecurePage.flashAlert).toHaveTextContaining( - 'You logged into a secure area!') - }) + try { + it('should login with valid credentials', async () => { + await LoginPage.open() + console.log(browser.constructor); + console.log(await getCompliance(browser, "TEST")); + await LoginPage.login('tomsmith', 'SuperSecretPassword!') + await expect(SecurePage.flashAlert).toBeExisting() + await expect(SecurePage.flashAlert).toHaveTextContaining( + 'You logged into a secure area!') + }) + } catch (e) { + console.error(e); + } finally { + close(); + } }) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index 572c693b8..a1de7d4e1 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 10 Apr 2024 15:04:14 -0500 Subject: [PATCH 09/13] Update ACHelper.ts --- accessibility-checker/src-ts/lib/ACHelper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index a1de7d4e1..ab1cd9ce3 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 17 Apr 2024 14:11:18 -0500 Subject: [PATCH 10/13] reverse the change #1837 --- .../features/step_definitions/browser_step.js | 10 +--- .../jest-customRS/matchers/toBeAccessible.js | 26 ++++----- .../jest-selenium/matchers/toBeAccessible.js | 24 +++----- .../jest/matchers/toBeAccessible.js | 24 +++----- .../mocha-puppeteer-ts/test-ts/basic.test.ts | 34 +++++------ .../mocha-selenium/test/basic.test.js | 42 ++++++-------- .../boilerplates/protractor/test/spec.js | 58 +++++++++---------- .../webdriverio/test/specs/example.e2e.ts | 26 ++++----- accessibility-checker/src-ts/lib/ACHelper.ts | 2 +- accessibility-checker/src/README.md | 12 ++-- 10 files changed, 106 insertions(+), 152 deletions(-) diff --git a/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js b/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js index 888a1da40..adfeef83e 100644 --- a/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js +++ b/accessibility-checker/boilerplates/cucumber-selenium/features/step_definitions/browser_step.js @@ -183,8 +183,8 @@ Then(/^I should see "([^"]*)"$/, function(text) { Then(/^Page is accessible with label "([^"]*)"$/, { "timeout": 30000 }, async function(label) { const world = this; + const { report } = await aChecker.getCompliance(world.driver, label); try { - const { report } = await aChecker.getCompliance(world.driver, label); // If assert fails, value is either 1 or 2 depending on if there's a baseline let assertResult = aChecker.assertCompliance(report); expect(assertResult).to.equal(0, assertResult === 1 ? "Results do not match baseline": "Failing issues found"); @@ -193,22 +193,18 @@ Then(/^Page is accessible with label "([^"]*)"$/, { "timeout": 30000 }, async fu const buffer = await world.driver.takeScreenshot(); await world.attach(buffer, 'image/png'); return Promise.reject(e); - } finally { - await aChecker.close(); } }) Then(/^Scan page for accessibility with label "([^"]*)"$/, { "timeout": 30000 }, async function(label) { const world = this; + const { report } = await aChecker.getCompliance(world.driver, label); try { - const { report } = await aChecker.getCompliance(world.driver, label); let assertResult = aChecker.assertCompliance(report); expect(assertResult).to.equal(0, assertResult === 1 ? "Results do not match baseline": "Failing issues found"); } catch (e) { world.attach(escape(aChecker.stringifyResults(report))); const buffer = await world.driver.takeScreenshot(); await world.attach(buffer, 'image/png'); - } finally { - await aChecker.close(); - } + }; }) \ No newline at end of file diff --git a/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js b/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js index 637d1ef98..f1dabe453 100644 --- a/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js +++ b/accessibility-checker/boilerplates/jest-customRS/matchers/toBeAccessible.js @@ -36,22 +36,16 @@ async function toBeAccessible(node) { aChecker.addRuleset(customRuleset); } - try { - const results = await aChecker.getCompliance(node, this.currentTestName); - if (aChecker.assertCompliance(results.report) === 0) { - return { - pass: true - } - } else { - return { - pass: false, - message: () => aChecker.stringifyResults(results.report) - }; - } - } catch (e) { - console.error(e); - } finally { - await aChecker.close(); + const results = await aChecker.getCompliance(node, this.currentTestName); + if (aChecker.assertCompliance(results.report) === 0) { + return { + pass: true + } + } else { + return { + pass: false, + message: () => aChecker.stringifyResults(results.report) + }; } } diff --git a/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js b/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js index 04ca69af5..84c25e458 100644 --- a/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js +++ b/accessibility-checker/boilerplates/jest-selenium/matchers/toBeAccessible.js @@ -10,22 +10,16 @@ const aChecker = require("accessibility-checker"); async function toBeAccessible(node, label) { - try { - let results = await aChecker.getCompliance(node, label); - if (aChecker.assertCompliance(results.report) === 0) { - return { - pass: true - } - } else { - return { - pass:false, - message: () => aChecker.stringifyResults(results.report) - } + let results = await aChecker.getCompliance(node, label); + if (aChecker.assertCompliance(results.report) === 0) { + return { + pass: true + } + } else { + return { + pass:false, + message: () => aChecker.stringifyResults(results.report) } - } catch (e) { - console.error(e); - } finally { - await aChecker.close(); } } diff --git a/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js b/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js index ca20b2968..84c25e458 100644 --- a/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js +++ b/accessibility-checker/boilerplates/jest/matchers/toBeAccessible.js @@ -10,22 +10,16 @@ const aChecker = require("accessibility-checker"); async function toBeAccessible(node, label) { - try { - let results = await aChecker.getCompliance(node, label); - if (aChecker.assertCompliance(results.report) === 0) { - return { - pass: true - } - } else { - return { - pass:false, - message: () => aChecker.stringifyResults(results.report) - } + let results = await aChecker.getCompliance(node, label); + if (aChecker.assertCompliance(results.report) === 0) { + return { + pass: true + } + } else { + return { + pass:false, + message: () => aChecker.stringifyResults(results.report) } - } catch (e) { - console.error(e); - } finally { - await aChecker.close(); } } diff --git a/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts b/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts index 8d2b45470..c139d02ce 100644 --- a/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts +++ b/accessibility-checker/boilerplates/mocha-puppeteer-ts/test-ts/basic.test.ts @@ -1,7 +1,7 @@ 'use strict'; import * as Puppeteer from "puppeteer"; // import { Browser, Page, launch } from "puppeteer"; -import { assertCompliance, getCompliance, stringifyResults, close } from "accessibility-checker"; +import { assertCompliance, getCompliance, stringifyResults } from "accessibility-checker"; import * as path from "path"; import { expect } from "chai"; import { before, after, describe, it } from "mocha"; @@ -27,26 +27,20 @@ after(async() => { // Describe this Suite of testscases, describe is a test Suite and 'it' is a testcase. describe("Hello World Basics", function () { - try { - it("HomePage", async () => { - const sample = path.join(__dirname, "..", "sample", "Hello.html"); - await page.goto(`file://${sample}`); + it("HomePage", async () => { + const sample = path.join(__dirname, "..", "sample", "Hello.html"); + await page.goto(`file://${sample}`); - const result = await getCompliance(page, "HOME"); - const report : ICheckerReport = result!.report as ICheckerReport; - expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); - }).timeout(10000); + const result = await getCompliance(page, "HOME"); + const report : ICheckerReport = result!.report as ICheckerReport; + expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); + }).timeout(10000); - it("Homepage, Show Card", async() => { - await page.click("#clickMe"); - const result = await getCompliance(page, "HOME_CARD"); - const report : ICheckerReport = result!.report as ICheckerReport; - expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); - }).timeout(10000); - } catch (e) { - console.error(e); - } finally { - close(); - } + it("Homepage, Show Card", async() => { + await page.click("#clickMe"); + const result = await getCompliance(page, "HOME_CARD"); + const report : ICheckerReport = result!.report as ICheckerReport; + expect(assertCompliance(report)).to.equal(0, stringifyResults(report)); + }).timeout(10000); }); //# sourceMappingURL=basic.test.js.map diff --git a/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js b/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js index cbcbe0e52..12b593f22 100644 --- a/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js +++ b/accessibility-checker/boilerplates/mocha-selenium/test/basic.test.js @@ -45,31 +45,25 @@ after(function(done) { // Describe this Suite of testscases, describe is a test Suite and 'it' is a testcase. describe("Hello World Basics", function () { this.timeout(0); - try { - it("HomePage", function (done) { - const sample = path.join(__dirname, "..", "sample", "Hello.html"); - loadSeleniumTestFile(browser, sample).then(function() { - // Perform the accessibility scan using the IBMaScan Wrapper - aChecker.getCompliance(browser, "HOME", function (data, doc) { - try { - expect(aChecker.assertCompliance(data)).to.equal(0, aChecker.stringifyResults(data)); - done(); - } catch (e) { - done(e); - } - }); + it("HomePage", function (done) { + const sample = path.join(__dirname, "..", "sample", "Hello.html"); + loadSeleniumTestFile(browser, sample).then(function() { + // Perform the accessibility scan using the IBMaScan Wrapper + aChecker.getCompliance(browser, "HOME", function (data, doc) { + try { + expect(aChecker.assertCompliance(data)).to.equal(0, aChecker.stringifyResults(data)); + done(); + } catch (e) { + done(e); + } }); }); + }); - it("Hompage, Show Card", async () => { - await browser.findElement({"id": "clickMe"}).click(); - let result = await aChecker.getCompliance(browser, "HOME_CARD"); - let report = result.report; - expect(aChecker.assertCompliance(report)).to.equal(0, aChecker.stringifyResults(report)); - }); - } catch (e) { - console.error(e); - } finally { - aChecker.close(); - } + it("Hompage, Show Card", async () => { + await browser.findElement({"id": "clickMe"}).click(); + let result = await aChecker.getCompliance(browser, "HOME_CARD"); + let report = result.report; + expect(aChecker.assertCompliance(report)).to.equal(0, aChecker.stringifyResults(report)); + }); }); diff --git a/accessibility-checker/boilerplates/protractor/test/spec.js b/accessibility-checker/boilerplates/protractor/test/spec.js index 39f678b45..ac8991cad 100644 --- a/accessibility-checker/boilerplates/protractor/test/spec.js +++ b/accessibility-checker/boilerplates/protractor/test/spec.js @@ -2,41 +2,35 @@ const aChecker = require("accessibility-checker"); describe('Protractor Demo App', function() { - try { - it("HomePage", function (done) { - browser.get("http://localhost:3003/Hello.html").then(function() { - // Perform the accessibility scan using the IBMaScan Wrapper - aChecker.getCompliance(browser, "HOME", function(data, doc) { - try { - console.log(data.reports[0].issues); - expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME")); - done(); - } catch (e) { - console.log(aChecker.getDiffResults("HOME")); - done(e); - } - }); + it("HomePage", function (done) { + browser.get("http://localhost:3003/Hello.html").then(function() { + // Perform the accessibility scan using the IBMaScan Wrapper + aChecker.getCompliance(browser, "HOME", function(data, doc) { + try { + console.log(data.reports[0].issues); + expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME")); + done(); + } catch (e) { + console.log(aChecker.getDiffResults("HOME")); + done(e); + } }); }); + }); - it("Hompage, Show Card", function (done) { - browser.findElement({"id": "clickMe"}).click().then(function() { - // Perform the accessibility scan using the IBMaScan Wrapper - aChecker.getCompliance(browser, "HOME_CARD", function (data, doc) { - try { - expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME_CARD")); - done(); - } catch (e) { - console.log(aChecker.getDiffResults("HOME_CARD")); - done(e); - } - }); + it("Hompage, Show Card", function (done) { + browser.findElement({"id": "clickMe"}).click().then(function() { + // Perform the accessibility scan using the IBMaScan Wrapper + aChecker.getCompliance(browser, "HOME_CARD", function (data, doc) { + try { + expect(aChecker.assertCompliance(data)).toEqual(0, aChecker.getDiffResults("HOME_CARD")); + done(); + } catch (e) { + console.log(aChecker.getDiffResults("HOME_CARD")); + done(e); + } }); - }); - } catch (e) { - console.error(e); - } finally { - aChecker.close(); - } + + }); }) \ No newline at end of file diff --git a/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts b/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts index 6605b02a1..6c46a74a0 100644 --- a/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts +++ b/accessibility-checker/boilerplates/webdriverio/test/specs/example.e2e.ts @@ -1,23 +1,17 @@ import LoginPage from '../pageobjects/login.page' import SecurePage from '../pageobjects/secure.page' -import { getCompliance, close } from "accessibility-checker"; +import { getCompliance } from "accessibility-checker"; describe('My Login application', () => { - try { - it('should login with valid credentials', async () => { - await LoginPage.open() - console.log(browser.constructor); - console.log(await getCompliance(browser, "TEST")); - await LoginPage.login('tomsmith', 'SuperSecretPassword!') - await expect(SecurePage.flashAlert).toBeExisting() - await expect(SecurePage.flashAlert).toHaveTextContaining( - 'You logged into a secure area!') - }) - } catch (e) { - console.error(e); - } finally { - close(); - } + it('should login with valid credentials', async () => { + await LoginPage.open() + console.log(browser.constructor); + console.log(await getCompliance(browser, "TEST")); + await LoginPage.login('tomsmith', 'SuperSecretPassword!') + await expect(SecurePage.flashAlert).toBeExisting() + await expect(SecurePage.flashAlert).toHaveTextContaining( + 'You logged into a secure area!') + }) }) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index ab1cd9ce3..49c9971bc 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 17 Apr 2024 14:13:33 -0500 Subject: [PATCH 11/13] reverse the changes #1837 --- accessibility-checker/src-ts/lib/ACHelper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accessibility-checker/src-ts/lib/ACHelper.ts b/accessibility-checker/src-ts/lib/ACHelper.ts index 49c9971bc..ab1cd9ce3 100644 --- a/accessibility-checker/src-ts/lib/ACHelper.ts +++ b/accessibility-checker/src-ts/lib/ACHelper.ts @@ -153,7 +153,7 @@ export async function getComplianceHelper(content, label) : Promise Date: Wed, 17 Apr 2024 14:31:05 -0500 Subject: [PATCH 12/13] Update the README for batch scan #1837 --- accessibility-checker/src-ts/bin/achecker.js | 54 +++++++++++--------- accessibility-checker/src/README.md | 52 +++++++++++++++++-- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/accessibility-checker/src-ts/bin/achecker.js b/accessibility-checker/src-ts/bin/achecker.js index 146bd95e4..1b1bc2f29 100755 --- a/accessibility-checker/src-ts/bin/achecker.js +++ b/accessibility-checker/src-ts/bin/achecker.js @@ -181,32 +181,38 @@ getInputFileList().then(async (rptInputFiles) => { let idx = 0; let failures = []; let errors = 0; - for (let f of rptInputFiles) { - let result; - let isFile = false; - try { - isFile = fs.lstatSync(f).isFile(); - f = path.resolve(f); - } catch (e) {} - if (isFile) { - result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); - } else { - result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); - } - if (result) { - if (aChecker.assertCompliance(result.report) === 0) { - console.log("Passed:", f); + try { + for (let f of rptInputFiles) { + let result; + let isFile = false; + try { + isFile = fs.lstatSync(f).isFile(); + f = path.resolve(f); + } catch (e) {} + if (isFile) { + result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); } else { - failures.push({ - file: f, - report: result.report - }); - console.log("Failed:", f); + result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); + } + if (result) { + if (aChecker.assertCompliance(result.report) === 0) { + console.log("Passed:", f); + } else { + failures.push({ + file: f, + report: result.report + }); + console.log("Failed:", f); + } + } else { + ++errors; + console.log("Error:", f); } - } else { - ++errors; - console.log("Error:", f); } + } catch (e) { + console.error(e); + } finally { + await aChecker.close(); } if (failures.length > 0) { console.log(); @@ -218,7 +224,7 @@ getInputFileList().then(async (rptInputFiles) => { } console.log(); console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`) - await aChecker.close(); + //await aChecker.close(); if (failures.length !== 0 || errors !== 0) { process.exitCode = 1; } diff --git a/accessibility-checker/src/README.md b/accessibility-checker/src/README.md index 2303c8ad2..115ed7806 100644 --- a/accessibility-checker/src/README.md +++ b/accessibility-checker/src/README.md @@ -45,13 +45,57 @@ try { expect(returnCode).toBe(0, "Scanning " + testLabel + " failed."); }); } catch (err) { - console.error(err); + console.error(err); +} finally { + // close the engine + await aChecker.close(); +}; +``` +Note that it's critical to close the engine, otherwise, output files for the report may not be generated properly. +If you execute batch scans, the engine should be closed after all the scans are completed for better performance: +```javascript +async batchScan(rptInputFiles) { + let failures = []; + try { + for (let f of rptInputFiles) { + let result; + let isFile = false; + try { + isFile = fs.lstatSync(f).isFile(); + f = path.resolve(f); + } catch (e) {} + if (isFile) { + result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_")); + } else { + result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_")); + } + if (result) { + if (aChecker.assertCompliance(result.report) === 0) { + console.log("Passed:", f); + } else { + failures.push({ + file: f, + report: result.report + }); + console.log("Failed:", f); + } + } else { + console.log("Error:", f); + } + } + if (failures.length > 0) { + console.log("Failing scan details:"); + for (const fail of failures) { + console.log(aChecker.stringifyResults(fail.report)); + } + } + } catch (e) { + console.error(e); } finally { - // close the engine await aChecker.close(); - }; + } +} ``` -Note that it's important to close the engine, otherwise, output files for the report may not be generated properly. Refer to [Examples](https://github.com/IBMa/equal-access/tree/master/accessibility-checker/boilerplates) for sample usage scenarios. From ab8abe56b67ffe40db979956c76df93c8708fda5 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Wed, 17 Apr 2024 14:38:37 -0500 Subject: [PATCH 13/13] Update README.md --- accessibility-checker/src/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accessibility-checker/src/README.md b/accessibility-checker/src/README.md index 115ed7806..09fc4b3f2 100644 --- a/accessibility-checker/src/README.md +++ b/accessibility-checker/src/README.md @@ -52,7 +52,7 @@ try { }; ``` Note that it's critical to close the engine, otherwise, output files for the report may not be generated properly. -If you execute batch scans, the engine should be closed after all the scans are completed for better performance: +If you execute batch scans, the engine should be closed after all the scans are completed for better performance. The following is a sample usage scenario: ```javascript async batchScan(rptInputFiles) { let failures = [];