Giter Site home page Giter Site logo

kaelig / axe-webdriverjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dequelabs/axe-webdriverjs

0.0 2.0 0.0 39 KB

Provides a chainable aXe API for Selenium's WebDriverJS and automatically injects into all frames.

License: Mozilla Public License 2.0

JavaScript 100.00%

axe-webdriverjs's Introduction

axe-webdriverjs

Provides a chainable aXe API for Selenium's WebDriverJS and automatically injects into all frames.

Getting Started

Install Node.js and Selenium Webdriver if you haven't already. For running axe-webdriverjs tests read more about setting up your environment.

Install aXe-core: npm install axe-core

Install the module and its dependencies: npm install axe-webdriverjs

Usage

This module uses a chainable API to assist in injecting, configuring and analyzing using aXe with Selenium WebDriverJS. As such, it is required to pass an instance of WebDriver.

Here is an example of a script that will drive Selenium to this repository, perform analysis and then log results to the console.

var AxeBuilder = require('axe-webdriverjs'),
  WebDriver = require('selenium-webdriver');

var driver = new WebDriver.Builder()
  .forBrowser('firefox')
  .build();

driver
  .get('https://github.com/dequelabs/axe-webdriverjs')
  .then(function () {
    AxeBuilder(driver)
      .analyze(function (results) {
        console.log(results);
      });
  });

AxeBuilder(driver:WebDriver[, axeSource:string])

Constructor for the AxeBuilder helper. You must pass an instance of selenium-webdriver as the first and only argument. Can be called with or without the new keyword.

var builder = AxeBuilder(driver);

If you wish to run a specific version of axe-core, you can pass the source axe-core source file in as a string. Doing so will mean axe-webdriverjs runs this version of axe-core, instead of the one installed as a dependency of axe-webdriverjs.

var axeSource = fs.readFileSync('./axe-1.0.js', 'utf8');
var builder = AxeBuilder(driver, axeSource);

AxeBuilder#include(selector:String)

Adds a CSS selector to the list of elements to include in analysis

AxeBuilder(driver)
  .include('.results-panel');

AxeBuilder#exclude(selector:String)

Add a CSS selector to the list of elements to exclude from analysis

AxeBuilder(driver)
  .include('.results-panel')
  .exclude('.results-panel h2');

AxeBuilder#options(options:Object)

Specifies options to be used by axe.a11yCheck. Will override any other configured options, including calls to withRules and withTags. See axe-core API documentation for information on its structure.

AxeBuilder(driver)
  .options({ checks: { "valid-lang": ["orcish"] }});

AxeBuilder#withRules(rules:Mixed)

Limits analysis to only those with the specified rule IDs. Accepts a String of a single rule ID or an Array of multiple rule IDs. Subsequent calls to AxeBuilder#options, AxeBuilder#withRules or AxeBuilder#withRules will override specified options.

AxeBuilder(driver)
  .withRules('html-lang');
AxeBuilder(driver)
  .withRules(['html-lang', 'image-alt']);

AxeBuilder#withTags(tags:Mixed)

Limits analysis to only those with the specified rule IDs. Accepts a String of a single tag or an Array of multiple tags. Subsequent calls to AxeBuilder#options, AxeBuilder#withRules or AxeBuilder#withRules will override specified options.

AxeBuilder(driver)
  .withTags('wcag2a');
AxeBuilder(driver)
  .withTags(['wcag2a', 'wcag2aa']);

AxeBuilder#configure(config:Object)

Inject an aXe configuration object to modify the ruleset before running Analyze. Subsequent calls to this method will invalidate previous ones by calling axe.configure and replacing the config object. See axe-core API documentation for documentation on the object structure.

var config = {
  'rules': {
    'id': 'angular-ng-click'
  }
}
AxeBuilder(driver)
  .configure(config)
  .analyze(function (results) {
    console.log(results);
  });

AxeBuilder#analyze(callback:Function)

Performs analysis and passes the result object to the provided function. Does not chain as the operation is asynchronous

AxeBuilder(driver)
  .analyze(function (results) {
    console.log(results);
  });

Examples

This project has a couple integrations that demonstrate the ability and use of this module:

  1. Running a single rule
  2. Running against a page with frames
  3. SauceLabs example

Contributing

Read the documentation on contributing

axe-webdriverjs's People

Contributors

arschmitz avatar dmfay avatar dsturley avatar dylanb avatar felixzapata avatar marcysutton avatar wilcofiers avatar

Watchers

 avatar  avatar

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.