API Reference for Cucumber
API reference for the AxeWorld class in Axe DevTools for Web Java
This document is a reference for the AxeWorld class in the com.deque.html.axedevtools.cucumber package. Unlike the Selenium and Hamcrest packages, the Cucumber package has no builder or matcher class for scoping and rule configuration. Those options are instead expressed directly in the Gherkin step text, as described in Write Cucumber Tests. The AxeWorld class only holds the state and configuration that Gherkin steps can't express, such as the page to check, analytics settings, custom reporting options, and the axe-core timeout.
com.deque.html.axedevtools.cucumber.AxeWorld
Holds the page and configuration used by the Cucumber accessibility steps when checking accessibility. Your dependency injection framework creates the AxeWorld (PicoContainer, for example, creates one per scenario) and passes it to both your step definitions and the Axe DevTools steps, so anything you set on it in a @Before hook or an earlier step applies to the accessibility steps in the same scenario.
The settings are read each time an accessibility step runs. Nothing is checked or sent when you call the setters.
public StepDefinitions(AxeWorld axeWorld) {
this.axeWorld = axeWorld;
}
@Before
public void setup() {
webDriver = new ChromeDriver();
axeWorld.setPage(new AxeDriver(webDriver));
}AxeWorld()
Creates an AxeWorld with no page and no configuration. You don't normally call it yourself: declare an AxeWorld parameter on your step definition class's constructor, and your dependency injection framework creates and shares the instance.
public AxeWorld();getPage()
Returns the page that the accessibility steps check, or null if setPage hasn't been called.
public AxeDriver getPage();Returns
The AxeDriver set on this world.
setPage(AxeDriver)
Sets the page that the accessibility steps check. Call it before any accessibility step runs, usually in a @Before hook. The steps check whatever page the wrapped WebDriver is showing when the step runs, so navigate with your WebDriver in earlier steps as usual.
public void setPage(AxeDriver page);Parameters
| Name | Type | Description |
|---|---|---|
page |
AxeDriver |
The page to check, wrapping your Selenium WebDriver. |
Example
@Before
public void setup() {
webDriver = new ChromeDriver();
axeWorld.setPage(new AxeDriver(webDriver));
}enableAnalytics(boolean)
Turns the usage service on or off for the accessibility steps. When you don't call it, the usage service is on. When the AXE_TRACK_USAGE environment variable is set, it takes precedence and this method has no effect: true turns the service on and any other value turns it off.
public void enableAnalytics(boolean state);Parameters
| Name | Type | Description |
|---|---|---|
state |
boolean |
true to send usage data, false to stop sending it. |
Example
@Before
public void setup() {
axeWorld.enableAnalytics(false);
}setAnalyticsUrl(String)
Sets the URL that usage data is sent to. The default is the AXE_METRICS_URL environment variable, or https://usage.deque.com when that isn't set. When AXE_METRICS_URL is set, this method has no effect.
public void setAnalyticsUrl(String url);Parameters
| Name | Type | Description |
|---|---|---|
url |
String |
The usage service URL. |
Example
axeWorld.setAnalyticsUrl("https://usage.example.com");setAnalyticsDistinctId(String)
Sets the distinct ID sent with usage data, which lets the usage service group the events from one user or machine. The ID is saved to ~/.deque/distinct_id, so later runs on the same machine keep using it. When the ID came from the AXE_DISTINCT_ID environment variable, this method has no effect.
public void setAnalyticsDistinctId(String did);Parameters
| Name | Type | Description |
|---|---|---|
did |
String |
The distinct ID. |
Example
axeWorld.setAnalyticsDistinctId(System.getenv("CI_RUNNER_ID"));setAnalyticsComponentName(String)
Sets the project name sent with usage data.
The accessibility steps apply the component name after the other analytics settings, and setting it resets the URL and enableAnalytics value to their defaults. So when you set a component name, any setAnalyticsUrl or enableAnalytics value on the same AxeWorld has no effect. A setAnalyticsDistinctId value is kept, because the distinct ID is saved to a file.
public void setAnalyticsComponentName(String name);Parameters
| Name | Type | Description |
|---|---|---|
name |
String |
The project name. |
Example
axeWorld.setAnalyticsComponentName("storefront-features");setReportingOptions(AxeReportingOptions)
Sets where the Then the page should be audited for accessibility step writes its report, and how it describes the test. Without it, that step writes to target/axe-report/accessibility-check.log and .json. See AxeReportingOptions for the options. The options you pass replace the defaults entirely: any value you don't set falls back to AxeConfiguration (reports go to axe-reports unless you set outputDirectory), and you must set uiState.
It has no effect on the Then the page should be axe clean step, which doesn't write a report.
public void setReportingOptions(AxeReportingOptions reportingOptions);Parameters
| Name | Type | Description |
|---|---|---|
reportingOptions |
AxeReportingOptions |
The reporting options to use. |
Example
@Before
public void setup(Scenario scenario) {
axeWorld.setReportingOptions(new AxeReportingOptions()
.outputDirectory("target/axe-report")
.testSuiteName("checkout")
.uiState(scenario.getName().replaceAll("\\W+", "-")));
}setTimeout(int)
Sets how long, in seconds, axe-core may analyze the page before the step fails with a timeout. The default is 30 seconds. Raise it for very large pages.
public void setTimeout(int timeout);Parameters
| Name | Type | Description |
|---|---|---|
timeout |
int |
The timeout, in seconds. |
Example
axeWorld.setTimeout(120);