This example demonstrates how to use axe to run web accessibility tests in Java projects with the Selenium browser automation tool and Java development tools.
Selenium integration enables testing of full pages and sites.
- Chrome must be installed; follow the directions at https://www.google.com/chrome/ to install it. On Unix, ensure that Chrome is on your path.
- The Java SE Development Kit must be installed; follow the directions at http://www.oracle.com/technetwork/java/javase/downloads/index.html to install it.
- Maven must be installed; follow the directions at http://maven.apache.org/ to install it. Ensure that it is on your path.
- Move to the
axe-core-maven-htmldirectory. node src/test/resources/test-app.jsto start the fixture server.mvn testto build and run the JUnit tests that drive Selenium against the fixture.
This should launch an automated Chrome window, load and analyze the configured web pages, and then pass/fail a JUnit test depending on whether there are any accessibility violations detected.
To run the example tests on your own web page, change the URL passed to driver.get in ExampleTest.setUp().
Include this library as a test-scoped dependency in your POM. Ensure the version matches the one in [pom.xml](./pom.xml):
<dependency>
<groupId>com.deque.html.axe-core</groupId>
<artifactId>selenium</artifactId>
<version>3.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>The AxeBuilder type is the main interface. Pass it a Selenium WebDriver instance, configure it,
and run the analyze method to get results.
optionswires a JSON string to axe, allowing rules to be toggled on or off. See thetestAccessibilityWithOptionsunit test for a sample single-rule execution, and the axe-core API documentation for full documentation on the options object. The runOnly option with tags may be of particular interest, allowing axe to execute all rules with the specified tag(s).includeadds to the list of included selectors. If you do not callincludeat all, axe will run against the entire document.excludeadds to the list of excluded selectors. Exclusions allow you to focus scope exactly where you need it, ignoring child elements you don't want to test.withOptionstakes an options object to be passed to theaxe.runcall.withTagslimits rules run to those that match specified tags.withOnlyRuleslimites rules run to those specified.disabledRulesdisables rules.analyzeexecutes axe with any configuration you have previously defined. If you want to test one or moreWebElements, you may pass them intoanalyzeinstead of usingincludeandexclude.
In order to contribute, you must accept the contributor licence agreement (CLA). Acceptance of this agreement will be checked automatically and pull requests without a CLA cannot be merged.
This package is deployed to Maven Central via OSSRH. To deploy this package, follow these instructions on StackOverflow.
Additionally add your OSSRH credentials to your ~/.m2/settings.xml file as such:
<servers>
<server>
<id>ossrh</id>
<username>YOUR_OSSRH_JIRA_USERNAME</username>
<password>YOUR_OSSRH_JIRA_PASSWORD</password>
</server>
</servers>