API Reference for Selenium

Link to API Reference for Selenium copied to clipboard

This document is a reference for types provided by the selenium package. The AxeSelenium class should cover most use cases, and AxeConfiguration should cover the rest.

com.deque.html.axedevtools.selenium.AxeSelenium

Configures how axe is run and actually runs axe.

Results = new AxeSelenium()
    .include(".my-css-class")
    .skipping("aria-required-parent")
    .run(driver);

AxeSelenium()

Create a new AxeSelenium accessibility check for an axe Driver.

AxeSelenium(final AxeBuilder axeBuilder, final AxeConfiguration axeConfiguration, final ResultsFilter resultsFilter, final AxeDevtoolsReporter reporter)

Create a new AxeSelenium accessibility check for an axe Driver.

Results run(final AxeDriver page)

Run axe against the page using axe.run.

page: AxeDevTools Driver representing the page to perform an a11y check on.

Returns a results document.

AxeSelenium include(final String cssSelector)

Include a selector.

cssSelector: Any valid CSS selector.

Returns AxeSelenium for method chaining.

AxeSelenium include(final List<String> selector)

Include an iFrame selector.

selector: A list of nested iFrame selectors. Each selector will represent a CSS selector for a level of nesting. The last will represent a CSS selector for the web element within the innermost iFrame for checking.

Returns AxeSelenium for method chaining.

AxeSelenium exclude(final String cssSelector)

Exclude a selector.

cssSelector: Any valid CSS selector. Returns AxeSelenium for method chaining.

AxeSelenium exclude(final List<String> selector)

Exclude a selector.

selector: A list of nested iFrame selectors. Each selector will represent a CSS selector for a level of nesting. The last will represent a CSS selector for the web element within the innermost iFrame for checking.

Returns AxeSelenium for method chaining.

AxeSelenium accordingTo(final String... tags)

According to accessibility tags. Check only specified accessibility tags. This option is incompatible with AxeSelenium::checkingOnly See Rule Descriptions.

tags: List of tags for checking.

Returns AxeSelenium for method chaining.

AxeSelenium checkingOnly(final String... rules)

Checking only accessibility rules. This option is incompatible with AxeSelenium::accordingTo See Rule Descriptions.

rules: List of rules for checking.

Returns AxeSelenium for method chaining.

AxeSelenium checking(final String... rules)

Check accessibility rules. In addition to given tags, also check certain rules. See Rule Descriptions.

rules: List of rules for checking.

Returns AxeSelenium for method chaining.

AxeSelenium skipping(final String... rules)

Skipping accessibility rules. From within the given tags, skip checking of certain rules. See Rule Descriptions.

rules: List of rules for checking.

Returns AxeSelenium for method chaining.

AxeSelenium forConfig(final URL auditConfigPath)

Provide an audit suite by it's URL.

auditConfigPath: the URL associated with the audit suite.

Returns AxeSelenium for method chaining.

AxeSelenium forConfig(final String auditConfigPath) throws MalformedURLException

Provide an audit suite by it's location on the file system.

auditConfigPath: The absolute file path of the audit suite.

Returns AxeSelenium for method chaining.

Throws MalformedURLException if audit path is an invalid filesystem path.

AxeSelenium forRuleset(final String rulesetId)

Specify a ruleset for the accessibility check. Configuring an audit suite will modify the specified ruleset. See Rulesets.

rulesetId: The id of the ruleset for configuration.

Returns AxeSelenium for method chaining.

AxeSelenium forRuleset(final String rulesetId, final boolean enableBestPractices)

Specify a ruleset for the accessibility check. Configuring an audit suite will modify the specified ruleset. See Rulesets.

rulesetId: The id of the ruleset for configuration.

enableBestPractices: Whether or not to turn on "best-practice" rules.

AxeSelenium: for method chaining.

AxeSelenium ignoring(final String selector, final String ruleId)

Ignore violations for a selector and a given rule id.

selector: Selector produced by axe DevTools Accessibility/Audit suite.

ruleId: Rule Id to ignore for the given selector.

Returns AxeSelenium for method chaining.

AxeSelenium logResults(final AxeReportingOptions reportingOptions)

Log results of the accessibility check upon completion.

reportingOptions: Options defining serialization and persistence of the accessibility check. Returns AxeSelenium for method chaining.

boolean loggingConfigured()

Whether or not logging has been configured.

Returns Whether or not logging has been configured.

com.deque.html.axedevtools.selenium.AxeDriver

Interact with a page using AxeDriver.

Wraps selenium web driver to provide axe-DevTools-specific functionality.

AxeDriver(final WebDriver webDriver)

Create an AxeDriver from a Selenium WebDriver.

webDriver: A Selenium WebDriver for the page that should be checked.

com.deque.html.axedevtools.selenium.AxeConfiguration

Configure axe script properties such as file location and config. Singleton class, use AxeConfiguration.configure() to access.

// Code runs once before any tests are run
public void setupOnce() {
  AxeConfiguration.configure()
    .withAxeScript(axeURL)
    .forAuditPath(auditURL)
    .forRuleset("508")
    .outputDirectory("my-axe-results");
}

static AxeConfiguration configure()

Configure an axe accessibility check. The only way to obtain an AxeConfiguration instance.

Returns A configuration object to configure the audit suite globally.

static void reset()

Resets to default preferences.

AxeConfiguration forAuditSuite(final URL auditConfigPath)

Provide an audit suite by it's URL.

auditConfigPath: the URL associated with the audit suite.

Returns AxeConfiguration for method chaining.

AxeConfiguration forAuditSuite(final String auditConfigPath) throws MalformedURLException

Provide an audit suite by it's location on the file system.

auditConfigPath: The absolute file path of the audit suite.

Returns AxeConfiguration for method chaining.

Throws MalformedURLException if audit path is an invalid filesystem path.

AxeConfiguration withAxeScript(URL axeScript)

Provide an axe core script to be used for performing the Accessibility Check.

axeScript: The URL associated with the axe Core script to be used for the Accessibility Check.

Returns AxeConfiguration for method chaining.

AxeConfiguration forRuleset(final String rulesetId)

Choose what ruleset to run

rulesetId: One of:

  • wcag2
  • wcag2.1
  • wcag2.2
  • wcag2aaa
  • wcag2.1aaa
  • wcag2.2aaa
  • 508
  • ttv5
  • en301549

Returns AxeConfiguration for method chaining.

AxeConfiguration forRuleset(final String rulesetId, final boolean enableBestPractices)

Choose what ruleset to run

rulesetId: See above for possible values.

enableBestPractices: Whether or not to turn on "best-practice" rules.

Returns AxeConfiguration for method chaining.

String getTestSuiteName()

Gets the test suite name.

Returns The test suite name.

AxeConfiguration testSuiteName(final String testSuiteName)

Sets the test suite name. Used in generating reports.

testSuiteName: The name of the test suite.

Returns AxeConfiguration for method chaining.

String getOutputDirectory()

Gets the report output directory.

Returns The output directory path.

AxeConfiguration outputDirectory(final String outputDirectory)

Set the directory to save reports in.

outputDirectory: The path to the directory.

Returns AxeConfiguration for method chaining.

String getUserAgent()

Gets the value used as the user agent.

Returns The user agent used in report generation.

AxeConfiguration userAgent(final String userAgent)

Sets the value used as a user agent when generating a report. Does not affect the actual user agent used when running axe.

userAgent: The value of the user agent.

Returns AxeConfiguration for method chaining.

String getTestMachine()

Gets the name of the test machine.

Returns The test machine name.

AxeConfiguration testMachine(final String testMachine)

Sets the name of the test machine. Used in report generation.

testMachine: The name of the test machine.

Returns AxeConfiguration for method chaining.

com.deque.html.axedevtools.selenium.results.IgnoredViolation

IgnoredViolation(final String cssSelector, final String ruleId)

Create an violation to ignore.

cssSelector: Selector of the node to ignore. Compares against each node's target.

ruleId: ID of the rule to ignore

com.deque.html.axedevtools.selenium.reporter.AxeReportingOptions implements ReportingOptions

Configures reporting options. Takes defaults from AxeConfiguration.

AxeReportingOptions()

Creates an AxeReportingOptions

static AxeReportingOptions defaultAuditReportingOptions()

Gets the default options.

Returns defaulted options object.

String getSuiteTestName()

Gets the configured test suite name.

Returns the name.

AxeReportingOptions testSuiteName(final String testSuiteName)

Describe the test suite.

testSuiteName: Name of the test suite.

Returns ReportingOptions for method chaining.

String getUiState()

Gets the configured UI state.

Returns the state.

AxeReportingOptions uiState(final String uiState)

Describe the state of the UI during the accessibility check.

uiState: State of the UI.

Returns ReportingOptions for method chaining.

String getOutputDirectory()

Gets configured output directory.

Returns the directory.

AxeReportingOptions outputDirectory(final String outputDirectory)

Set the root outputDirectory to output the accessibility report.

outputDirectory: Directory path.

Returns ReportingOptions for method chaining.

String getFileName()

Calculated filename from configured values.

Retuns the filename

String getFilePath(final String extension)

Calculates file path from configured values.

Returns the path.

String getUserAgent()

Gets configured user agent.

Returns the user agent.

AxeReportingOptions userAgent(final String userAgent)

Describe the user agent used to perform the accessibility test.

userAgent: User agent name.

Returns ReportingOptions for method chaining.

String getTestMachine()

Gets configured test machine.

Returns the test machine.

AxeReportingOptions testMachine(final String testMachine)

Describe the machine used to perform the accessibility test.

testMachine: Machine name.

Returns ReportingOptions for method chaining.

AxeReportingOptions lineNum(final String lineNum)

Specify the line number of the current test.

lineNum: Line Number of the current test.

Returns ReportingOptions for method chaining.

ReportingOptions lineNumIfEmpty(final String lineNum)

Specify the line number, if it hasn't already been set.

lineNum: Line Number of the current test.

Returns ReportingOptions for method chaining.

com.deque.html.axedevtools.selenium.reporter.MissingUIStateException

Exception for when UI state is missing.

com.deque.html.axedevtools.selenium.results.ResultsFilter

Sets violations to ignore.

ResultsFilter filter = new ResultsFilter()
    .ignoring(".third-party-iframe", "label");
Results results = new AxeSelenium(axe, configuration, filter, reporter)
    .run(driver);

Results filterIgnoredViolations(final Results results)

Filter results to remove ignored violations.

results: results to filter.

Returns Incoming results, filtered for ignored CSS Selectors + Rule Ids.

ResultsFilter ignoring(final String cssSelector, final String ruleId)

Add an ignored violation.

cssSelector: CSS selector produced by running Accessibility/Audit suite.

ruleId: Rule ID produced by running Accessibility/Audit suite.

Returns ResultsFilter for method chaining.

com.deque.html.axedevtools.reporter.AxeDevtoolsReporter

Configure reporting options when using hamcrest matchers.

AxeDevtoolsReporter reporter = new AxeDevtoolsReporter();
assertThat(axeDevtoolsSelenium, isAxeClean(axeSelenium, reporter));

AxeDevtoolsReporter()

Construct an AxeDevtoolsReporter

String generateReport(final Results results, final String executedCommand)

Create a string representation of the accessibility check.

results: Results from audit check.

executedCommand: Command executed to produce audit results.

Returns A readable report of accessibility violations found.

void report(final ReportingOptions reportingOptions, final Results results, final String executedCommand)

Report on accessibility check. Append report to results log file by date. Store full results as JSON file.

reportingOptions: Options for logging the report.

results: Results from audit check.

executedCommand: Command executed to produce audit results.

com.deque.html.axedevtools.reporter.TestResultsGenerator

Generates a TestResults from a Results and ReportingOptions. Used with the AxeDevtoolsReporter

TestResults generate(final ReportingOptions reportingOptions, final Results results)

Generates the {@link TestResults}.

reportingOptions: Options from which we create our results.

results: Results from running axe.

Returns The test

com.deque.html.axedevtools.reporter.ViolationsReporter

Reports on only violations.

com.deque.html.axedevtools.utils.FileUtils

File utilities for internal use.