Giter Site home page Giter Site logo

girishmanyam / webdriver-accessibility Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nikulkarni/webdriver-accessibility

0.0 2.0 0.0 10.34 MB

A Java library to run accessibility audits with Selenium WebDriver

License: Other

Java 89.98% Gherkin 1.48% HTML 8.55%

webdriver-accessibility's Introduction

webdriver-accessibility

Ever wanted to do accessibility scanning in your WebDriver tests in Java? webdriver-accessibility is a Java tool that helps you run accessibility audits using selenium webdriver and GoogleChrome accessibility-developer-tools. It relies on GoogleChrome accessibility-developer-tools to run the audit. Once the audit is run, the tool returns a meaningful Java object which can be used for reporting later. The tool also takes a screenshot of your webpage and marks errors & warnings. Currently errors are bordered with red and warnings with yellow. This project is decoupled from Webdriver project in the sense that user would need to pass along a WebDriver object.

As of today, this library is not published in maven repo, so you would need to clone this project and deploy locally by running mvn clean install or deploy a snapshot in your own repository like mvn clean -B deploy. Currently there is an open issue to fix this.

Once the library is available in your local/internal maven repository, please add dependency like,

<dependency>
   <groupId>com.accessibility</groupId>
   <artifactId>webdriver-accessibility</artifactId>
   <version>1.1.0-SNAPSHOT</version>
</dependency>

It is assumed that the user is already on the page where accessibility scan is required to be run. This is what you would do,

   AccessibilityScanner scanner = new AccessibilityScanner(driver);
   Map<String, Object> audit_report = scanner.runAccessibilityAudit();

You could do this in your tests,

if (audit_report.containsKey("error")) {
 List<Result> errors = (List<Result>) audit_report.get("error");
 assertThat("No accessibility errors expected", errors.size(),equalTo(0));
}

If you want specific details of the error, you could scan through the List of errors like below. Similarly you could scan all warnings for details.

List<Result> errors = (List<Result>) audit_report.get("error"); 
for (Result error : errors) {
 log.info(error.getRule());//e.g. AX_TEXT_01
 log.info(error.getUrl());//e.g. [GoogleChrome accessibility-developer-tools][2] audit rules URL
 for (String element : error.getElements()) //violated elements
  log.info(element);//e.g. #myForm > P > INPUT
}

Interpreting audit report

Once you run runAccessibilityAudit() method it returns a Map<String, Object> audit_report and it contains following keys,

  /** @type {List<Result>} */
  error, //contains all errors
  /** @type {List<Result>} */
  warning, //contains all warnings
  /** @type {String} */
  plain_report, //contains plain report
  /** @type {byte[]} */
  screenshot, //contains screenshot with bordered elements (red:errors, yellow:warnings)

Result object is made of following,

 /** @type {String} */
  rule, //contains specific rule information
  /** @type {List<String>} */
  elements, //contains all element locators with errors/warnings
  /** @type {String} */
  information_link, //link to [GoogleChrome accessibility-developer-tools][3] audit rules wiki for more details

Reporting in your Tests

webdriver-accessibility tool is agonistic any test framework. It can be used with JUNIT, TestNG, Cucumber-JVM etc.

In TestNG or JUNIT you could use it as below,

@Test
public void testAccessibility() {
   AccessibilityScanner scanner = new AccessibilityScanner(driver);
   Map<String, Object> audit_report = scanner.runAccessibilityAudit();
   
   if (audit_report.containsKey("error")) {
    List<Result> errors = (List<Result>) audit_report.get("error");
    assertThat("No accessibility errors expected", errors.size(),equalTo(0));
   }
}

In this project, you can find two examples of how to use this library in JUnit and Cucumber-JVM under src/test/java/com/accessibility/examples. Tests by default run on Firefox, please make sure your Firefox version is supported by selenium used in webdriver-accessibility

While JUnit example is little straight forward, Cucumber-JVM example is little more sophisticated, check under src/test/java/com/accessibility/example for code. Here is a sample cucumber report (test included in the project) that demonstrates how to embed details of the output of webdriver-accessibility tool in test reports. Here you can notice that I embedded plain audit report and screenshot. In the screenshot, you can notice that input text boxes violated missing label rule and are threfore marked with red border. There are infact 24 violations of missing label rule, in my example below however GoogleChrome accessibility-developer-tools at most provides 5 errors/warnings of each type. Therefore only 5 input boxes with this certain violation are marked with red border. Also the small pizza image violated missing ALT attribute rule as a warning and therefore marked as yellow.

test report

Contributing:

Fork the project and submit pull request if you like to add a feature/fix bugs etc. Disclaimer: I am no accessibility expert. I am open for suggestions.

Issues

Please provide necessary details to reproduce the issue and open them as appropriate

Contact

Twitter: [@nileshdk] 4

Email: [email protected]

Update As of July 18, 2016

I have had very little time to spend on this project recently, but I'm planning to be more active now. Also looking for more contributors

webdriver-accessibility's People

Contributors

nikulkarni avatar selametaydogdu avatar

Watchers

James Cloos 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.