项目作者: racchouhan12
项目描述 :
Cucumber - Selenium - Java - Axe Integration
高级语言: Java
项目地址: git://github.com/racchouhan12/AccessibilityTestWithAxe.git
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.
Requirements
- 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.
To use the AXE helper library in your own tests
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, and Builder
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 the testAccessibilityWithOptions
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 call
include
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 single WebElement
, you may pass it into
analyze
instead of using include
and exclude
.
Framework structure:
- 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
Note: ThisRun.java will be called in Hooks itself and driver intialization and other Keys are setup here
Rules to be followed:
- 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
How to run Test:
- 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