UNPKG

accessibility-checker

Version:

An automated testing tools for accessibility testing using Puppeteer, Selenium, or Zombie

591 lines (590 loc) 23.9 kB
import { eAssertResult, ICheckerReport, ICheckerReportCounts, IConfigUnsupported, ILogger, ReportResult } from "./api/IChecker"; import { IScanSummary } from "./reporters/ReportUtil"; import { Report, Rule } from "./api/IEngine"; export declare class ACReportManager { static config: IConfigUnsupported; static reporters: { html: any; json: any; csv: any; xlsx: any; }; static refactorMap: { [oldRuleId: string]: Rule; }; static baselineIssueList: string[]; static metricsLogger: any; static scanSummary: IScanSummary; static diffResults: any; static scanResults: any; static initialize(logger: ILogger): Promise<void>; /** * This function is responsible for checking if the provided label is unique or not. * * @param {String} label - Provide the label which should be checked if it exists or not * * @return {boolean} labelExists - return false if the label is not unique, otherwise return true * * PRIVATE METHOD * * @memberOf this */ static isLabelUnique(label: string): boolean; /** * This function is responsible for sending the scan results to the karma server accessibility-checker reporter. The * accessibility-checker reporter is responsible for writing the results to a file. The reporter will also keep track of * the summary results, on the server side. * * @param {Object} results - Provide the full results object which is to be reported/saved to file. * refer to return in function "aChecker.buildReport" prolog * * @return N/A * * PRIVATE METHOD * * @memberOf this */ static sendResultsToReporter(unFilteredResults: any, results: any, profile: any): Promise<void>; static sendScreenShotToReporter(screenshotResult: any): void; /** * This function is responsible for building the results object in a specific format which will be provided back to * the user to do any thing they want to do with it. (compare, print it, save to db, etc...) * * Note: This function converts it to match with the following format outlined at: * https://github.com/IBMa/equal-access/tree/master/karma-accessibility-checker * * @param {Object} results - The results object which we need to build the report based on, following is the format the * object needs to follow: * { * "report": { * "numChecked": 227, * "numTrigger": 1, * "ruleTime": 5, * "totalTime": 8, * "issues": [ * { * "severityCode": "eISHigh", * "messageCode": "rpt.g377.elemUniqueId", * "ruleId": "377", * "help": "idhi_accessibility_check_g377.html", * "msgArgs": [ * "div", * "firstDiv" * ], * "xpath": "/html[1]/body[1]/div[2]/div[2]", * "snippet": "<div id=\"firstDiv\">", * "bounds": { * "left": 10, * "top": 181, * "height": 0, * "width": 1249 * }, * "level": "violation" * } * ], * "docTitle": "Helo World" * }, * "counts": { * "violation": 1, * "potentialviolation": 0, * "recommendation": 0, * "potentialrecommendation": 0, * "manual": 0 * }, * "issueMessages": { * "messages": { * "rpt.g377.elemUniqueId": "The {0} element has the id \"{1}\" that is either empty or already in use." * }, * "lang": "en-us" * } * } * * @param {String} URL - The URL which the report is being built for * @param {String} label - A label to identify what this report is going to be for, in the case not using URL or local files. * @param {String} startScan - The start time of the scan. * * @return {Object} results - return the formatted results based in the following format: * * { * "scanID": "ef3aec68-f073-4f9c-b372-421ae00bd55d", * "toolID": "karma-ibma-v1.0.0", * "summary": { * "counts": { * "violation": 5, * "potentialviolation": 0, * "recommendation": 5, * "potentialrecommendation": 0, * "manual": 1 * }, * "scanTime": 80, * "policies": [ * "CI162_5_2_DCP080115" * ], * "reportLevels": [ * "violation", * "potentialviolation", * "recommendation", * "potentialrecommendation", * "manual" * ], * "startScan": "2016-06-06T00:52:41.603Z" * }, * "URL": "", * "label": "unitTestContent", * "screenshot": "<placeholder>", * "issueMessages": { * "messages": { * "rpt.g377.elemUniqueId": "The {0} element has the id \"{1}\" that is either empty or already in use." * }, * "lang": "en-us" * }, * "reports": [ * { * "frameIdx": "0", * "frameTitle": "Frame 0", * "issues": [ * { * "severity": "Low", * "message": "If style sheets are ignored or unsupported, ensure that pages are still readable and usable.", * "messageCode": "rpt.g1.styleTrigger", * "ruleId": "1", * "help": "idhi_accessibility_check_g1.html", * "msgArgs": [], * "bounds": { * "left": 0, * "top": 0, * "height": 0, * "width": 0 * }, * "level": "manual", * "xpath": "/html[1]/head[1]/style[1]", * "snippet": "<style type=\"text/css\">" * } * .... * ] * }, * { * "frameIdx": "1", * "frameTitle": "Frame 1", * "issues": [ * { * "severity": "High", * "message": "The table element with WAI-ARIA presentation role has structural element(s) and/or attribute(s) td.", * "messageCode": "rpt.g471.tableStructure", * "ruleId": "471", * "help": "idhi_accessibility_check_g471.html", * "msgArgs": [ * "table", * "td" * ], * "bounds": { * "left": 10, * "top": 990, * "height": 219, * "width": 335 * }, * "level": "violation", * "xpath": "/html[1]/body[1]/div[2]/table[3]", * "snippet": "<table id=\"layout_table3\" role=\"presentation\">" * } * .... * ] * } * ] * } * * PRIVATE METHOD * * @memberOf this */ static buildReport(inReport: Report, counts: ICheckerReportCounts, URL: any, label: any, startScan: any): ICheckerReport; /** * This function is responsible for indexing the results into global spaces based on label. * * @param {Object} results - Results object which will be provided to the user/wroten to the file. * Refer to aChecker.buildReport function's return to figure out what the object * will look like. * * @return - N/A - Global object is updated with the results * * PRIVATE METHOD * * @memberOf this */ static addResultsToGlobal: (results: ICheckerReport) => void; /** * This function is responsible for filtering the violations so that, only the violations levels that * are provided in reportLevels are presented in the report. * * TODO: Possibly we can add this to the engine, so that the results are not provided by the engine * when user has provided the reportLevels object. * * @param {Object} results - Provide the violation results, which follow the following format: * { * "report": { * "numChecked": 227, * "numTrigger": 1, * "ruleTime": 5, * "totalTime": 8, * "issues": [ * { * "severityCode": "eISHigh", * "messageCode": "rpt.g377.elemUniqueId", * "ruleId": "377", * "help": "idhi_accessibility_check_g377.html", * "msgArgs": [ * "div", * "firstDiv" * ], * "xpath": "/html[1]/body[1]/div[2]/div[2]", * "snippet": "<div id=\"firstDiv\">", * "bounds": { * "left": 10, * "top": 181, * "height": 0, * "width": 1249 * }, * "level": "violation" * } * ], * "docTitle": "Helo World" * }, * "counts": { * "level.violation": 1, * "level.potentialviolation": 0, * "level.recommendation": 0, * "level.potentialrecommendation": 0, * "level.manual": 0 * }, * "issueMessages": { * "messages": { * "rpt.g377.elemUniqueId": "The {0} element has the id \"{1}\" that is either empty or already in use." * }, * "lang": "en-us" * } * } * * @return {Object} results - return results object which only contains the violation that were requested, * follows the following format: * { * "report": { * "numChecked": 227, * "numTrigger": 1, * "ruleTime": 5, * "totalTime": 8, * "issues": [ * { * "severityCode": "eISHigh", * "messageCode": "rpt.g377.elemUniqueId", * "ruleId": "377", * "help": "idhi_accessibility_check_g377.html", * "msgArgs": [ * "div", * "firstDiv" * ], * "xpath": "/html[1]/body[1]/div[2]/div[2]", * "snippet": "<div id=\"firstDiv\">", * "bounds": { * "left": 10, * "top": 181, * "height": 0, * "width": 1249 * }, * "level": "violation" * } * ], * "docTitle": "Helo World" * }, * "counts": { * "level.violation": 1, * "level.potentialviolation": 0, * "level.recommendation": 0, * "level.potentialrecommendation": 0, * "level.manual": 0 * }, * "issueMessages": { * "messages": { * "rpt.g377.elemUniqueId": "The {0} element has the id \"{1}\" that is either empty or already in use." * }, * "lang": "en-us" * } * } * * The return object is pretty much filtered failures (results.report.fail), wrapped around another object with extra frameIdx value. * * PRIVATE METHOD * * @memberOf this */ static filterViolations(report: Report): Report; static setLevels(report: Report): Report; /** * This function is responsible for iterating over all the issue elements and updating the counts object. * * @param {Object} pageResults - Provide the page results object, in the following format: * { * "report": { * "numChecked": 227, * "numTrigger": 1, * "ruleTime": 5, * "totalTime": 8, * "issues": [ * { * "severityCode": "eISHigh", * "messageCode": "rpt.g377.elemUniqueId", * "ruleId": "377", * "help": "idhi_accessibility_check_g377.html", * "msgArgs": [ * "div", * "firstDiv" * ], * "xpath": "/html[1]/body[1]/div[2]/div[2]", * "snippet": "<div id=\"firstDiv\">", * "bounds": { * "left": 10, * "top": 181, * "height": 0, * "width": 1249 * }, * "level": "violation" * } * ], * "docTitle": "Helo World" * }, * "counts": { * "level.violation": 1, * "level.potentialviolation": 0, * "level.recommendation": 0, * "level.potentialrecommendation": 0, * "level.manual": 0 * }, * "issueMessages": { * "messages": { * "rpt.g377.elemUniqueId": "The {0} element has the id \"{1}\" that is either empty or already in use." * }, * "lang": "en-us" * } * } * ...... * * @return {Object} pageResults - return the results object with the count object updated * { * "report": { * "numChecked": 227, * "numTrigger": 1, * "ruleTime": 5, * "totalTime": 8, * "issues": [ * { * "severityCode": "eISHigh", * "messageCode": "rpt.g377.elemUniqueId", * "ruleId": "377", * "help": "idhi_accessibility_check_g377.html", * "msgArgs": [ * "div", * "firstDiv" * ], * "xpath": "/html[1]/body[1]/div[2]/div[2]", * "snippet": "<div id=\"firstDiv\">", * "bounds": { * "left": 10, * "top": 181, * "height": 0, * "width": 1249 * }, * "level": "violation" * } * ], * "docTitle": "Helo World" * }, * "counts": { * "level.violation": 1, * "level.potentialviolation": 0, * "level.recommendation": 0, * "level.potentialrecommendation": 0, * "level.manual": 0 * }, * "issueMessages": { * "messages": { * "rpt.g377.elemUniqueId": "The {0} element has the id \"{1}\" that is either empty or already in use." * }, * "lang": "en-us" * } * } * * PRIVATE METHOD * * @memberOf this */ static getCounts(report: Report): ICheckerReportCounts; /** * This function is responsible for updating/creating the global violation summary for the engine karma run * for browser that it is running on. Will take the pageCount object which is part of the page object and * add extract the values for each of the levels and add them to the global object. This will provide an overall * summary of violations for all testcases run and all scans done. * * @param {Object} pageCount - Provide the page count object, in the following format: * * @return N/A - Global summary object is updated with the counts * * PRIVATE METHOD * * @memberOf this */ static addToSummaryCount(pageCount: ICheckerReportCounts): void; /** * This function is responsible for comparing the scan results with baseline or checking that there are * no violations which fall into the failsLevels levels. In the case a baseline is found then baseline will * be used to perform the check, in the case no baseline is provided then we comply with only failing if * there is a sinble violation which falls into failLevels. * * @param {Object} actual - the actual results object provided by the user, this object should follow the * same format as outlined in the return of aChecker.buildReport function. * * @return {int} - return 0 in the case actual matches baseline or no violations fall into failsLevels, * return 1 in the case actual results does not match baseline results, * return 2 in the case that there is a failure based on failLevels (this means no baseline found). * return -1 in the case that there is an exception that occured in the results object which came from the scan engine. * * PUBLIC API * * @memberOf this */ static assertCompliance(actualResults: ReportResult): eAssertResult; /** * This function is responsible for checking if any of the issues reported have any level that falls * into the failsLevel array. * * @param {Object} results - Provide the scan results, object which would be in the * the same format as outlined in the return of aChecker.buildReport function. * * @return {int} - return 1 in the case a single issue was found which is in the failsLevel array. * return -1 in the case that there is an exception that occured in the results object which came from the scan engine. * * PRIVATE METHOD * * @memberOf this */ static compareBasedOnFailLevels(report: any): 0 | 1 | -1; /** * This function is responsible for comparing actual with expected and returning all the differences as an array. * * @param {Object} actual - Provide the actual object to be used for compare * @param {Object} expected - Provide the expected object to be used for compare * @param {boolean} clean - Provide a boolean if both the actual and expected objects need to be cleaned * cleaning refers to converting the objects to match with a basic compliance * compare of xpath and ruleId. * * @return {Object} differences - return an array of diff objects that were found, following is the format of the object: * [ * { * "kind": "E", * "path": [ * "reports", * 0, * "issues", * 10, * "xpath" * ], * "lhs": "/html[1]/body[1]/div[2]/table[5]", * "rhs": "/html[1]/body[1]/div[2]/table[5]d", * }, * { * "kind": "E", * "path": [ * "label" * ], * "lhs": "Table-layoutMultiple", * "rhs": "dependencies/tools-rules-html/v2/a11y/test/g471/Table-layoutMultiple.html", * } * ] * * PUBLIC API * * @memberOf this */ static diffResultsWithExpected(actual: any, expected: any, clean: any): any; /** * This function is responsible for cleaning up the compliance baseline or actual results, based on * a pre-defined set of criterias, such as the following: * 1. No need to compare summary object * 2. Only need to compare the ruleId and xpath in for each of the issues * * @param {Object} objectToClean - Provide either an baseline or actual results object which would be in the * the same format as outlined in the return of aChecker.buildReport function. * * @return {Object} objectToClean - return an object that was cleaned to only contain the information that is * needed for compare. Following is a sample of how the cleaned object will look like: * { * "label": "unitTestContent", * "reports": [ * { * "frameIdx": "0", * "frameTitle": "Frame 0", * "issues": [ * { * "ruleId": "1", * "xpath": "/html[1]/head[1]/style[1]" * } * .... * ] * }, * { * "frameIdx": "1", * "frameTitle": "Frame 1", * "issues": [ * { * "ruleId": "471", * "xpath": "/html[1]/body[1]/div[2]/table[3]" * } * .... * ] * } * ] * } * * PRIVATE METHOD * * @memberOf this */ static cleanComplianceObjectBeforeCompare(objectToClean: any): any; /** * This function is responsible for getting the baseline object for a label that was provided. * * @param {String} label - Provide a lable for which to get the baseline for. * * @return {Object} - return the baseline object from global space based on label provided, the object will be * in the same format as outlined in the return of aChecker.buildReport function. * * PUBLIC API * * @memberOf this */ static getBaseline(label: any): any; /** * This function is responsible for getting the diff results based on label for a scan that was already performed. * * @param {String} label - Provide a lable for which to get the diff results for. * * @return {Object} - return the diff results object from global space based on label provided, the object will be * in the same format as outlined in the return of aChecker.diffResultsWithExpected function. * * PUBLIC API * * @memberOf this */ static getDiffResults(label: string): any; /** * This function is responsible for printing the scan results to console. * * @param {Object} results - Provide the results from the scan. * * @return {String} resultsString - String representation of the results/violations. * * PUBLIC API * * @memberOf this */ static stringifyResults(reportP: ReportResult): string; static ignoreExtraBaselineViolations(actualReport: any, baselineReport: any): any; }