Import and Initialize with Java

Link to Import and Initialize with Java copied to clipboard

Importing and initializing axe DevTools HTML with Java

Once you've installed axe DevTools HTML, you need to import it into your testing file and initialize the tool in conjunction with its webdriver.


In order to import and initialize axe DevTools HTML, it needs to be installed first. If you haven't yet, read the guide on how to install it from a bundle, from your artifact repository, or from Deque's Agora. You also need a downloaded and configured Selenium WebDriver of your choice.


In order to use axe DevTools several packages need to be imported. Depending on your configuration, these packages may vary. Deque offers four Java integrations:

Selenium Configuration Import Statements

To use axe DevTools with Selenium follow this portion of the guide. Use this configuration if you aren't coupling axe DevTools with an existing assertion library and instead write your own tests. In addition, import statements will be required for the webdriver of your choice.

The only package that is explicitly required to be imported is the axe DevTools Selenium package. This is what communicates between axe DevTools and the Selenium WebDriver to run the scans.

import com.deque.html.axedevtools.selenium.*;

For the this configuration, two more packages are recommended to allow you to generate and interpret results. The results package generates a JSON object containing the scan results, and the reporter package allows generation of HTML, JUnit XML, or CSV reports of the scan results.

import com.deque.html.axedevtools.selenium.results.*;
import com.deque.html.axedevtools.selenium.reporter.*;

Hamcrest Import Statements

For testing environments that make use of Hamcrest, there are only two packages that must be imported. The first package contains everything needed for standard scans.

import com.deque.html.axedevtools.matchers.*;

The second package adds the ability to scope the scans by selectors. To use this functionality, the additional import of this package is required.

import com.deque.html.axedevtools.matchers.selectors;

Cucumber Import Statements

In order to pair axe DevTools with Cucumber, only one import package is required.

import com.deque.html.axedevtools.cucumber.*;

Playwright Import Statements

You need to import two packages to use the Playwright integration.

import com.deque.html.maven.axedevtools.playwright.AxePlaywrightBuilder;
import com.deque.html.maven.axedevtools.utility.axeresults.AxeResults; 

You also need to import Microsoft's Playwright packages.


Initializing (non-Playwright)

After the required package import statements have been added to your test file, you will need to initialize axe DevTools with its web driver in order to run accessibility scans. Using the standard configuration, this code will initialize axe DevTools. This example uses ChromeDriver, but other browser drivers like GeckoDriver work equally well.

WebDriver webdriver = new ChromeDriver();
AxeDriver axedriver = new AxeDriver(webdriver);

Additionally, if you need a generated results object and/or a report, an axe Selenium object must be imported, as described above, and initialized

AxeSelenium axeSelenium = new AxeSelenium();

Initializing Playwright

To initialize Playwright, you construct a new Playwright object, use it to create a new Browser object, and finally use the Browser object to create a Page object.

Playwright playwright = Playwright.create();
Browser browser = playwright.chromium()
    .launch(new BrowserType.LaunchOptions().setHeadless(true));
Page page = browser.newPage();

Next Steps

Once you've installed, imported, and initialized axe DevTools, you're ready to move on to scanning for accessibility and writing accessibility tests. To do that, see the guide on writing tests with Selenium, writing tests with Hamcrest, writing tests with Cucumber, or writing tests with Playwright.


If you have trouble with any of the importing or initializing of axe DevTools, contact your Deque representative directly, reach us via our support desk, or send us an email. We'll be happy to help.