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.
- Java8 or higher should be installed.
- Set JAVA_HOME
- Install maven and set MAVEN_HOME
- Add JAVA_HOME and MAVEN_HOME in your Path variable.
- Chrome/FireFox browsers must be installed.
inject
will inject the required script into the page under test and any iframes. This only needs to be run against a given page once, andBuilder
will take care of it for you if you use that.report
will pretty-print a list of violations.writeResults
will write the JSON violations list out to a file with the specified name in the current working directory.
The 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
options()
, include()
and exclude()
selectors, skipFrames()
, and finally,
analyze()
the page.
options
wires a JSON string to aXe, allowing rules to be toggled on or off. See thetestAccessibilityWithOptions
unit 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).include
adds to the list of included selectors. If you do not callinclude
at all, aXe will run against the entire document.exclude
adds 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.skipFrames
prevents aXe to be recursively injected into all iframes.analyze
executes aXe with any configuration you have previously defined. If you want to test a singleWebElement
, you may pass it intoanalyze
instead of usinginclude
andexclude
.
-
Project is a maven project.
-
Our framework code lies mainly in src/test folder.
-
Project has three layer approach or calling: feature -> stepdefinitions -> businessflows -> screens
-
feature -> It is test/resources. It will contain all feature files (.feature).
-
stepdefinitions -> This folder has java files which contains step definitions corresponding in feature file.
-
businessflows -> This folder has java files which contains which contains business logic or assertions
-
screens -> This folder has java files which perform actual actions on the web browser.
-
-
In resources there are couple of more files like .exe, .properties.
-
In CommonProperties.properties we are passing browser name it will have more keys as framework expands.
-
We have utilities package which contains utilities for driver, reporting and maintaing session state of objects(ThisRun.java)
-
Call flows are as follows:
-
run commands: a. mvn clean b. mvn install or mvn test
-
Now execution will begin
Call hierarchy are as follows:
Runcuckes -> Hooks: -> features -> stepdefinitions -> businessflows -> screens
-
- We should not call screens directly from stepdefinitions call hierarchy should be maintained (stepdefinitions -> businessflows -> screens).
- All assertions should be done in businessflows only
- Mutiple businessflows can be called from stepdefinitions
- To run specific scenarios use command : run=@foo mvn test -PRunTest (For MAC)
For Windows you might need to use
- set run=@foo
- mvn test -PRunTest
- To run all scenarios use command : mvn test -PRunTest
https://www.deque.com/axe/axe-for-web/documentation/api-documentation/#api-name-axegetrules