Giter VIP home page Giter VIP logo

forsti0506 / a11y-sitechecker Goto Github PK

View Code? Open in Web Editor NEW
47.0 2.0 7.0 3.64 MB

Automatic accessibility checker with website crawling + screenshots for easy use

License: GNU Affero General Public License v3.0

JavaScript 3.12% TypeScript 96.76% Shell 0.12%
axe accessibility-criteria accessibility-testing accessibility puppeteer crawler typescript typescript-library open-source hacktoberfest

a11y-sitechecker's Introduction

a11y-sitechecker

npm version Codacy Badge Commits since last release Libraries.io dependency status for GitHub repo Downloads per month

A11y-sitecheker is a tool to check a site against accessibility criteria. It uses axe-core with the option to combine results of multiple sites. On the one hand there is the option to let the tool crawl your whole site and on the other site you can provide urls which should be checked by the tool. The results are printed to the console, saved as JSONs or returned. The tool can be called by javascript or directly by command line. Additionally there are Images created which indicates the errors, shows the tab-order and other features.

Features

  • Crawls Websites automatically for accessibility issues
    • In addition clicking all Clickable Items (Alpha Status)
  • Analyze a Set of URLs agains accessibility criteria
  • Provide Images for
    • Tab-Order (A C means you have to check if there are click and key interaction is possible!)
    • Errors highlighted
    • View of site in general
  • Results for different viewports

Test Coverage

Statements Branches Functions Lines
Statements Branches Functions Lines

Install

npm install a11y-sitechecker | yarn add a11y-sitechecker

Usage

Commandline

You can use it in your package.json or in your console like the following:

a11y-sitechecker --config=config.json -T=1000

The available options on the commandline are:

-j | --json: "Output results as JSON. Otherwise output is displayed on the console"
--config <string>: "Provide a config.json"
-T, --threshold <number> "permit this number of errors, warnings, or notices, otherwise fail with exit code 2"

Typescript

Call the entry function in your code and use the provided interfaces. The result is an array which contains a result for every specified viewport. Only return defined if there is console output or not.

export async function entry(
    config: Config,
    axeSpecs: Spec,
    url: string,
    onlyReturn?: boolean,
): Promise<A11ySitecheckerResult[]>;

Configuration File Options

Every option can be inserted in a json Format and wil be parsed at startup. Examples are below, how to define it in a json file!

Overview

export interface Config {
    json: boolean;
    resultsPath: string;
    resultsPathPerUrl: string;
    axeConfig?: AxeConfig;
    login?: Login;
    saveImages?: boolean;
    imagesPath?: string;
    launchOptions?: LaunchOptions;
    ignoreElementAttributeValues?: string[];
    urlsToAnalyze: string[];
    clickableItemSelector?: string;
    analyzeClicks?: boolean;
    analyzeClicksWithoutNavigation?: boolean;
    threshold: number;
    timeout: number;
    debugMode: boolean;
    viewports: SitecheckerViewport[];
    resultTypes: resultGroups[];
    idTags?: IdTag;
    runOnly: RunOnly | TagValue[] | string[];
    crawl: boolean;
    name: string;
    cookieSelector?: string; // provide a selector for clicking cookie consent button (example: "[id*=cookie] a, [class*=cookie] a, [id*=cookie] button, [class*=cookie] button, [id*=didomi] button")
    cookieText?: string; //provides a text for cookie consent text (example: "^(Alle akzeptieren|Akzeptieren|Verstanden|Zustimmen|Okay|OK|Alle Cookies akzeptieren)$")
    screenshotPadding?: number; //padding for making screenshots (Standardvalue is 10). Sometime you like to see more of the element, because you are using small elements, like icon Buttons to check
}

Config Option Details

Every configuration which is not inserted in the config file is by default false or undefined if not explicitly mentioned!

Name

The name is the major element to identify your run! You have to provide it

{
  "name": "MyName"
}
JSON Output

Define if output should be to a json file. You can additionally add a path to store the results.json file!

{
  "json": true,
  "resultsPath": "to a folder, starting with the folder where the script is executed"
}
Axe-core Language

If you like to choose your own language for the axe-core results, you can define a locale from the standard locales your you can provide your own locale with a path!

{
  "axeConfig": {
    "locale": "de",
    "localePath": "path to locale"
  }
}
Login steps

If your site need some login steps you can define it here! The input array defines the elements with css-selectors where you like to input the value! In the end you have to define the button which is clicked after the form is filled! You can repeat this steps if needed!

{
  "login": {
    "url": "http://myloginurl.at",
    "steps": [
      {
        "input": [
          {
            "selector": "#user_login",
            "value": "user"
          },
          {
            "selector": "#user_pass",
            "value": "passwort"
          }
        ],
        "submit": "#wp-submit"
      }
    ]
  }
}
Images

If you like to take Screenshots during the evaluation, define it here! The images are saved in a folder images under the results path!

{
  "saveImages": true
}
Launch Options

You can define launch Options for puppeteer. Please see the documentation here

{
  "launchOptions": {}
}
Ignoring Elements

You can define string which should lead to ignored links and button clicks. Usually if you a are in a logged in context the crawle should not do a logout!

{
  "ignoreElementAttributeValues": [
    "logout"
  ]
}
Links to Analyze

You have to define the links you like to analyze. If you specify 1 link, you can use the crawl function, which crawls then the url. If you provide more then 1 url, you are not allowed to set crawl to true. It is by default false!

{
  "urlsToAnalyze": [
    "www.test.at"
  ],
  "crawl": true
}
Analyzing Clicks

It is possible to analyze clickable Items, which are not links (buttons who change the view,...). By default it searches by this selector : "button, select, details, [tabindex]:not([tabindex="-1"])" You can activate this by:

{
  "analyzeClicks": true,
  "clickableItemSelector": "button, details"
}
Clicks without Navigation

It is possible to analyze button clicks which does not affect the url. If you like to use this feature activate it here!

{
  "analyzeClicksWithoutNavigation": true
}
Deactive analyze of clicks

You can activate/deactive the analyze of clicks (alpha status). Standard is false!

{
  "analyzeClicks": true
}
Threshold and Timeout

You can specify a timeout in ms for operations which can lead to errors (for example a selector is not found). To cause the console to end with an error if there are more errors than allowed (for example in build pipelines) you can specifiy a threshold (same like in the command line). Standard: threshold 0, timeout 30000

{
  "threshold": 100,
  "timeout": 1000
}
DebugMode

Activating the debugMode leads to more logs presented in the console output. By default it is false

{
  "debugMode": true
}
Specifiying viewport

Viewports are used for different devices. Sometimes there are different elements which can cause new or other accessibility problems! Standard viewport ist 1920*1080!

{
  "viewports": [
    {
      "width": 1920,
      "height": 1080
    }
  ]
}
Result types

Result types are used to reduce effort for axe-core (Documentation) Standard is violations and incomplete!

{
  "resultTypes": [
    "violations",
    "incomplete"
  ]
}
ID-Tags

ID-Tags are used to mark axe-core rules with own Tags (for example if someone wants to know only these results)

{
  "idTags": {
    "aria-required-attr": [
      "XYZ"
    ],
    "meta-viewport": [
      "XYZ"
    ]
  }
}

a11y-sitechecker's People

Contributors

actions-user avatar dependabot-preview[bot] avatar dependabot[bot] avatar forsti0506 avatar semantic-release-bot avatar tyler-ham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

a11y-sitechecker's Issues

devDependencies cannot be satisfied

I want to compile a11y-sitechecker from TypeScript to JavaScript and for that purpose tried to installed the devDependencies as listed in package.json. However, to my interpretation the required specific versions of packages pulled in as direct or indirect dependencies are in conflict and cannot be resolved:

$ npm install a11y-sitechecker '@axe-core/puppeteer@^4.4.0' 'chalk@^4.0.0' 'commander@^9.0.0' 'jsdom@^19.0.0' 'puppeteer@^13.3.2' 'rxjs@^7.5.4' 'uuid@^8.3.2' '@commitlint/cli@^16.2.1' '@commitlint/config-conventional@^16.2.1' '@semantic-release/changelog@^6.0.1' '@semantic-release/git@^10.0.1' '@semantic-release/github@^8.0.2' '@semantic-release/npm@^9.0.0' '@semantic-release/release-notes-generator@^10.0.3' '@types/jest@^27.4.0' '@types/jsdom@^16.2.14' '@types/node@^17.0.18' '@types/prettyjson@^0.0.30' '@types/puppeteer@^5.4.4' '@types/uuid@^8.3.4' '@typescript-eslint/eslint-plugin@^5.12.0' '@typescript-eslint/parser@^5.12.0' 'copyfiles@^2.4.1' 'eslint@^8.9.0' 'eslint-config-prettier@^8.3.0' 'eslint-config-standard@^16.0.3' 'eslint-plugin-import@^2.25.4' 'eslint-plugin-node@^11.1.0' 'eslint-plugin-prettier@^4.0.0' 'eslint-plugin-promise@^5.0.0' 'husky@^7.0.4' 'istanbul-badges-readme@^1.8.1' 'jest@^27.5.1' 'jest-puppeteer@^6.1.0' 'prettier@^2.5.1' 'semantic-release@^19.0.2' 'ts-jest@^27.1.3' 'ts-node@^10.5.0'
npm notice 
npm notice New minor version of npm available! 8.15.0 -> 8.19.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.19.1>
npm notice Run `npm install -g [email protected]` to update!
npm notice 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: [email protected]
npm ERR! node_modules/eslint
npm ERR!   eslint@"^8.9.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^7.12.1" from [email protected]
npm ERR! node_modules/eslint-config-standard
npm ERR!   eslint-config-standard@"^16.0.3" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/ubuntu/.npm/eresolve-report.txt for a full report.

The command is execute as a RUN statement inside a Dockerfile extending image andrewmackrodt/nodejs-chromium.

The conflict is as follows:

Do I miss anything or is there a real problem to be fixed?

Request for a simple user guide for a novice user

Hi,

Is there any simple user guide for a blackbpox tester (who has limited to no coding knowledge but can follow the user guide to make the full use of the application) to use this to generate an accessibility report, please?

Could you help with this, please?

basic config file

Would love an example config file, with all defaults on. Just finding the config how to a little confusing.

I have tried


          File: config.json                           

{
 "name": "DRN1",
  "urlsToAnalyze": "google.com"
}


and get this error

############################################################################################# 
Start accessibility Test for GOOGLE 
############################################################################################# 
ProtocolError: Protocol error (Page.navigate): Cannot navigate to invalid URL 


The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch main on the remote Git repository with URL https://x-access-token:[secure]@github.com/forsti0506/a11y-sitechecker.git.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Error on load.

I'm not sure why I would be getting this error when attempting to instal this.

$ a11y-sitechecker --config=config.json -T=1000
SyntaxError: Unexpected token e in JSON at position 0 
undefined:1
export interface Config {
^

SyntaxError: Unexpected token e in JSON at position 0
    at JSON.parse (<anonymous>)
    at setupConfig (/home/mike/a11y-sitechecker/node_modules/a11y-sitechecker/lib/utils/setup-config.js:40:35)
    at defaultFunction (/home/mike/a11y-sitechecker/node_modules/a11y-sitechecker/bin/a11y-sitechecker_code.js:22:51)
    at /home/mike/a11y-sitechecker/node_modules/a11y-sitechecker/bin/a11y-sitechecker.js:5:64
    at Object.<anonymous> (/home/mike/a11y-sitechecker/node_modules/a11y-sitechecker/bin/a11y-sitechecker.js:5:67)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

DOMException is thrown when a data attribute contains dots

When a web page declares data attributes with dots the accessibility checker fails and throws an uncaught DOMException.

Example for such a data attribute:

<body data-keydown.tabguard="1" />

I looked around the code base and I think I've found the reason causing the exception:

a.substring(0, a.indexOf('.')) + "[class='" + a.substring(a.indexOf('.') + 1, a.length) + "']",

As I understand the above mentioned line of code correctly, everything after the dot and inclusive the dot is replaced with
class=[${everything-after-dot}]. The reason why the error happens at this point, is that in the following line, data attribute names are not escaped properly, which then results in invalid selectors:

aSel[0] = sSel += '[' + aDataAttr[j].name + '="' + aDataAttr[j].value + '"]';

This causes the above selector to be turned into

body[data-keydown[class='tabguard="1"]']

instead of an escaped version

body[data-keydown\\.tabguard="1"]

If desired, I am willing to provide a PR.

Question: -bash: a11y-sitechecker: command not found

Hello
Sorry, I'm a newbie with npm.
I pulled the code in this repo and run npm install and yarn add.
But when I wanted to run a11y-sitechecker through command line it throws me the following message:
-bash: a11y-sitechecker: command not found
Please advice.
Thanks,
M

DOMException: Failed to execute 'querySelector' on 'Document': '#1FDA5B64-3D65-493B-9C45-2B72F7A25B64' is not a valid selector.

I received the following error:

Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': '#1FDA5B64-3D65-493B-9C45-2B72F7A25B64' is not a valid selector.
    at __puppeteer_evaluation_script__:2:38

The cause appears to be a webpage containing a tabable element with an ID that starts with a number. See this Stack Overflow post: Using querySelector with IDs that are numbers.

The solution seems to be using a querySelector like [id='#1234'] instead of #1234 at lib/utils/mark-all-tabbale-items.ts:78.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.