index.js
function runChromeDevTools(context) {

  var data = fs.readFileSync(AUDIT_FILE, 'utf-8');
  data = data + ' var configuration = new axs.AuditConfiguration(' + JSON.stringify(context.config.chromeA11YDevTools.auditConfiguration) + '); return axs.Audit.run(configuration);';

  var elementPromises = [],
      elementStringLength = 200;

  function trimText(text) {
    if (text.length > elementStringLength) {
      return text.substring(0, elementStringLength / 2) + ' ... '
          + text.substring(text.length - elementStringLength / 2);
    } else {
      return text;
    }
  }

  var testHeader = 'Chrome A11Y - ';

  return browser.executeScriptWithDescription(data, 'a11y developer tool rules').then(function(results) {

    var audit = results.map(function(result) {
      var DOMElements = result.elements;
      if (DOMElements !== undefined) {

        DOMElements.forEach(function(elem) {
          // get elements from WebDriver, add to promises array
          elementPromises.push(
            elem.getAttribute('outerHTML').then(function(text) {
              return {
                code: result.rule.code,
                list: trimText(text)
              };
            },
            function(reason){
              return {
                code: result.rule.code,
                list: reason
              };
            })
          );
        });
        result.elementCount = DOMElements.length;
      }
      return result;
    });

    // Wait for element names to be fetched
    return q.all(elementPromises).then(function(elementFailures) {

      return audit.forEach(function(result, index) {
        if (result.result === 'FAIL') {
          var label = result.elementCount === 1 ? ' element ' : ' elements ';
          if (result.rule.severity !== 'Warning'
              || context.config.chromeA11YDevTools.treatWarningsAsFailures) {
            result.warning = false;
          } else {
            result.warning = true;
            result.rule.heading = '\x1b[33m(WARNING) '
                + result.rule.heading + ' (' + result.elementCount
                + label + 'failed)';
          }
          result.output = '\n\t\t' + result.elementCount + label + 'failed:';

          // match elements returned via promises
          // by their failure codes
          elementFailures.forEach(function(element, index) {
            if (element.code === result.rule.code) {
              result.output += '\n\t\t' + elementFailures[index].list;
            }
          });
          result.output += '\n\n\t\t' + result.rule.url;
          (result.warning ? context.addWarning : context.addFailure)(
              result.output, {specName: testHeader + result.rule.heading});
        }
        else {
          context.addSuccess({specName: testHeader + result.rule.heading});
        }
      });
    });
  });

}
function runChromeDevTools(context) {

  var data = fs.readFileSync(AUDIT_FILE, 'utf-8');
  data = data + ' var configuration = new axs.AuditConfiguration(' + JSON.stringify(context.config.chromeA11YDevTools.auditConfiguration) + '); return axs.Audit.run(configuration);';

  var elementPromises = [],
      elementStringLength = 200;

  function trimText(text) {
    if (text.length > elementStringLength) {
      return text.substring(0, elementStringLength / 2) + ' ... '
          + text.substring(text.length - elementStringLength / 2);
    } else {
      return text;
    }
  }

  var testHeader = 'Chrome A11Y - ';

  return browser.executeScriptWithDescription(data, 'a11y developer tool rules').then(function(results) {

    var audit = results.map(function(result) {
      var DOMElements = result.elements;
      if (DOMElements !== undefined) {

        DOMElements.forEach(function(elem) {
          // get elements from WebDriver, add to promises array
          elementPromises.push(
            elem.getAttribute('outerHTML').then(function(text) {
              return {
                code: result.rule.code,
                list: trimText(text)
              };
            },
            function(reason){
              return {
                code: result.rule.code,
                list: reason
              };
            })
          );
        });
        result.elementCount = DOMElements.length;
      }
      return result;
    });

    // Wait for element names to be fetched
    return q.all(elementPromises).then(function(elementFailures) {

      return audit.forEach(function(result, index) {
        if (result.result === 'FAIL') {
          var label = result.elementCount === 1 ? ' element ' : ' elements ';
          if (result.rule.severity !== 'Warning'
              || context.config.chromeA11YDevTools.treatWarningsAsFailures) {
            result.warning = false;
          } else {
            result.warning = true;
            result.rule.heading = '\x1b[33m(WARNING) '
                + result.rule.heading + ' (' + result.elementCount
                + label + 'failed)';
          }
          result.output = '\n\t\t' + result.elementCount + label + 'failed:';

          // match elements returned via promises
          // by their failure codes
          elementFailures.forEach(function(element, index) {
            if (element.code === result.rule.code) {
              result.output += '\n\t\t' + elementFailures[index].list;
            }
          });
          result.output += '\n\n\t\t' + result.rule.url;
          (result.warning ? context.addWarning : context.addFailure)(
              result.output, {specName: testHeader + result.rule.heading});
        }
        else {
          context.addSuccess({specName: testHeader + result.rule.heading});
        }
      });
    });
  });

}
function runChromeDevTools ( context ) { var data = fs . readFileSync ( AUDIT_FILE , 'utf-8' ) ; data = data + ' var configuration = new axs.AuditConfiguration(' + JSON . stringify ( context . config . chromeA11YDevTools . auditConfiguration ) + '); return axs.Audit.run(configuration);' ; var elementPromises = [ ] , elementStringLength = 200 ; function trimText ( text ) { if ( text . length > elementStringLength ) { return text . substring ( 0 , elementStringLength / 2 ) + ' ... ' + text . substring ( text . length - elementStringLength / 2 ) ; } else { return text ; } } var testHeader = 'Chrome A11Y - ' ; return browser . executeScriptWithDescription ( data , 'a11y developer tool rules' ) . then ( function ( results ) { var audit = results . map ( function ( result ) { var DOMElements = result . elements ; if ( DOMElements !== undefined ) { DOMElements . forEach ( function ( elem ) { // get elements from WebDriver, add to promises array elementPromises . push ( elem . getAttribute ( 'outerHTML' ) . then ( function ( text ) { return { code : result . rule . code , list : trimText ( text ) } ; } , function ( reason ) { return { code : result . rule . code , list : reason } ; } ) ) ; } ) ; result . elementCount = DOMElements . length ; } return result ; } ) ; // Wait for element names to be fetched return q . all ( elementPromises ) . then ( function ( elementFailures ) { return audit . forEach ( function ( result , index ) { if ( result . result === 'FAIL' ) { var label = result . elementCount === 1 ? ' element ' : ' elements ' ; if ( result . rule . severity !== 'Warning' || context . config . chromeA11YDevTools . treatWarningsAsFailures ) { result . warning = false ; } else { result . warning = true ; result . rule . heading = '\x1b[33m(WARNING) ' + result . rule . heading + ' (' + result . elementCount + label + 'failed)' ; } result . output = '\n\t\t' + result . elementCount + label + 'failed:' ; // match elements returned via promises // by their failure codes elementFailures . forEach ( function ( element , index ) { if ( element . code === result . rule . code ) { result . output += '\n\t\t' + elementFailures [ index ] . list ; } } ) ; result . output += '\n\n\t\t' + result . rule . url ; ( result . warning ? context . addWarning : context . addFailure ) ( result . output , { specName : testHeader + result . rule . heading } ) ; } else { context . addSuccess ( { specName : testHeader + result . rule . heading } ) ; } } ) ; } ) ; } ) ; }
Audits page source against the Chrome Accessibility Developer Tools, if configured.

@param {Object} context The plugin context object
@return {q.Promise} A promise which resolves when the audit is finished
@private
Audits page source against the Chrome Accessibility Developer Tools if configured .