aXe Selenium (Java) Integration README
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.
- Firefox must be installed; follow the directions at http://getfirefox.com to install it. On Unix, ensure that Firefox 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.
To run the example
- Move to the
- Ensure that
axe.min.jsis located in
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 Firefox 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 modify the example
To run the example tests on your own web page, change the URL passed to
To use the AXE helper library in your own tests
Include this library as a test-scoped dependency in your POM:
<dependency> <groupId>com.deque</groupId> <artifactId>axe-selenium</artifactId> <version>2.0</version> <scope>test</scope> </dependency>
axe.min.js must be available to your test fixtures as a
java.net.URL. The simplest way to do this is to include it in your own
src.test.resources and pass
MyTest.class.getResource("/axe.min.js") to the
Builder constructor as demonstrated in the
AXE helper defines three public methods and a nested
Builder class for
your unit tests.
injectwill inject the required script into the page under test and any iframes. This only needs to be run against a given page once, and
Builderwill take care of it for you if you use that.
reportwill pretty-print a list of violations.
writeResultswill write the JSON violations list out to a file with the specified name in the current working directory.
Builder class allows tests to chain configuration and analyze pages. The
constructor takes in a
WebDriver that has already navigated to the page under
test and a
java.net.URL pointing to the aXe script; from there, you can set
exclude() selectors, and finally,
optionswires a JSON string to aXe, allowing rules to be toggled on or off. See the
testAccessibilityWithOptionsunit 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 call
includeat 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.
analyzeexecutes aXe with any configuration you have previously defined. If you want to test a single
WebElement, you may pass it into
analyzeinstead of using
The aXe documentation should be consulted for more details on customizing and
analyzing calls to
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.