accessibility-checker
Version:
An automated testing tools for accessibility testing using Puppeteer, Selenium, or Zombie
323 lines (319 loc) • 13.4 kB
TypeScript
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
import { eAssertResult, ICheckerReport, ICheckerResult, ReportResult } from "./lib/api/IChecker.js";
import { IConfig, IConfigInternal } from "./lib/common/config/IConfig.js";
import { IBaselineReport } from "./lib/common/engine/IReport.js";
export { eAssertResult, ICheckerReport, ICheckerResult, ReportResult } from "./lib/api/IChecker.js";
export { IBaselineReport } from "./lib/common/engine/IReport.js";
/**
* This function is responsible performing a scan based on the context that is provided, following are
* the supported context type:
* Single node (HTMLElement)
* Local file path (String)
* URL (String)
* document node
* data stream for html content (String)
*
* Future Items
* Multiple node (Array of HTMLElements) ---> FUTURE
*
* @param {(String|HTMLElement|DocumentNode|Puppeteer Page |)} content - Provide the context to scan, which includes the items from above.
* @param {String} label - Provide a label for the scan that is being performed
* @param {Function} callback - (optional) Provide callback function which will be executed once the results are extracted.
* @return Promise with the ICheckerResult
*/
export declare function getCompliance(content: any, label: string, callback?: (report: ReportResult, webdriver: any) => void): Promise<ICheckerResult>;
/**
* 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 {ReportResult} 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.
*/
export declare function assertCompliance(report: IBaselineReport): eAssertResult;
/**
* 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
*/
export declare function stringifyResults(report: ICheckerReport): string;
export declare function getConfig(): Promise<IConfig>;
export declare function getConfigUnsupported(): Promise<IConfigInternal>;
export declare function setConfig(config: IConfig): Promise<void>;
export declare function close(): Promise<void>;
/**
* 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.
*/
export declare function getDiffResults(label: string): 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.
*/
export declare function getBaseline(label: string): IBaselineReport;
/**
* 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",
* }
* ]
*/
export declare function 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]"
* }
* ....
* ]
* }
* ]
* }
*/
export declare function cleanComplianceObjectBeforeCompare(objectToClean: any): any;
export declare function addRuleset(ruleset: any): void;
export declare function getRuleset(rsId: any): Promise<any>;
export declare function getRulesets(): Promise<any[]>;
export declare function getRules(): Promise<any[]>;
export declare const ruleIdToLegacyId: {
list_structure_proper: string;
marquee_elem_avoid: string;
heading_markup_misuse: string;
imagebutton_alt_exists: string;
img_ismap_misuse: string;
object_text_exists: string;
applet_alt_exists: string;
media_audio_transcribed: string;
blockquote_cite_exists: string;
meta_refresh_delay: string;
frame_title_exists: string;
input_label_exists: string;
media_alt_brief: string;
a_target_warning: string;
area_alt_exists: string;
RPT_Media_ImgColorUsage: string;
meta_redirect_optional: string;
element_attribute_deprecated: string;
text_quoted_correctly: string;
element_mouseevent_keyboard: string;
page_title_exists: string;
text_block_heading: string;
form_submit_button_exists: string;
element_id_unique: string;
form_font_color: string;
form_label_unique: string;
img_alt_misuse: string;
img_longdesc_misuse: string;
img_alt_valid: string;
style_background_decorative: string;
asciiart_alt_exists: string;
media_track_available: string;
media_alt_exists: string;
style_color_misuse: string;
select_options_grouped: string;
list_markup_review: string;
script_onclick_misuse: string;
table_structure_misuse: string;
WCAG20_Img_AltTriggerNonDecorative: string;
blink_elem_deprecated: string;
blink_css_review: string;
html_skipnav_exists: string;
page_title_valid: string;
heading_content_exists: string;
html_lang_exists: string;
form_interaction_review: string;
a_text_purpose: string;
fieldset_legend_valid: string;
media_live_captioned: string;
text_sensory_misuse: string;
media_autostart_controllable: string;
style_focus_visible: string;
img_alt_redundant: string;
RPT_Style_ExternalStyleSheet: string;
script_onclick_avoid: string;
table_summary_redundant: string;
input_label_before: string;
input_label_after: string;
embed_noembed_exists: string;
table_scope_valid: string;
img_alt_null: string;
input_fields_grouped: string;
input_checkboxes_grouped: string;
script_select_review: string;
input_onchange_review: string;
embed_alt_exists: string;
noembed_content_exists: string;
table_caption_empty: string;
table_caption_nested: string;
label_content_exists: string;
dir_attribute_valid: string;
frame_src_valid: string;
table_headers_related: string;
table_layout_linearized: string;
table_headers_exists: string;
label_ref_valid: string;
element_accesskey_unique: string;
script_focus_blur_review: string;
imagemap_alt_exists: string;
emoticons_alt_exists: string;
style_before_after_review: string;
text_whitespace_valid: string;
aria_role_allowed: string;
aria_attribute_value_valid: string;
aria_id_unique: string;
aria_attribute_required: string;
aria_attribute_exists: string;
aria_attribute_allowed: string;
aria_activedescendant_tabindex_valid: string;
aria_child_tabbable: string;
aria_keyboard_handler_exists: string;
img_alt_decorative: string;
aria_search_label_unique: string;
aria_application_label_unique: string;
aria_application_labelled: string;
aria_document_label_unique: string;
WCAG20_Label_TargetInvisible: string;
caption_track_exists: string;
media_keyboard_controllable: string;
HAAC_Input_HasRequired: string;
aria_img_labelled: string;
img_alt_background: string;
element_accesskey_labelled: string;
aria_attribute_conflict: string;
canvas_content_described: string;
figure_label_exists: string;
input_placeholder_label_visible: string;
form_submit_review: string;
text_contrast_sufficient: string;
text_contrast_sufficient_PV: string;
skip_main_exists: string;
skip_main_described: string;
aria_child_valid: string;
aria_parent_required: string;
aria_eventhandler_role_valid: string;
aria_widget_labelled: string;
aria_content_in_landmark: string;
aria_region_labelled: string;
aria_main_label_visible: string;
aria_banner_label_unique: string;
aria_complementary_label_unique: string;
aria_contentinfo_label_unique: string;
aria_form_label_unique: string;
aria_navigation_label_unique: string;
aria_complementary_label_visible: string;
aria_article_label_unique: string;
Rpt_Aria_ArticleRoleLabel_Implicit: string;
Rpt_Aria_MultipleGroupRoles_Implicit: string;
Rpt_Aria_GroupRoleLabel_Implicit: string;
aria_contentinfo_single: string;
aria_banner_single: string;
aria_contentinfo_misuse: string;
aria_complementary_labelled: string;
aria_region_label_unique: string;
widget_tabbable_exists: string;
widget_tabbable_single: string;
style_highcontrast_visible: string;
aria_main_label_unique: string;
download_keyboard_controllable: string;
error_message_exists: string;
list_children_valid: string;
aria_activedescendant_valid: string;
application_content_accessible: string;
aria_toolbar_label_unique: string;
HAAC_Combobox_ARIA_11_Guideline: string;
HAAC_Combobox_Must_Have_Text_Input: string;
HAAC_Combobox_DOM_Focus: string;
HAAC_Combobox_Autocomplete: string;
HAAC_Combobox_Autocomplete_Invalid: string;
HAAC_Combobox_Expanded: string;
HAAC_Combobox_Popup: string;
style_viewport_resizable: string;
label_name_visible: string;
input_autocomplete_valid: string;
input_label_visible: string;
};