Class AxeBuilder


  • public class AxeBuilder
    extends Object
    Fluent style builder for invoking aXe. Instantiate a new Builder and configure testing with the include(), exclude(), and options() methods before calling analyze() to run.
    • Constructor Detail

      • AxeBuilder

        public AxeBuilder()
        Initialize an instance of AxeBuilder.
      • AxeBuilder

        public AxeBuilder​(AxeBuilderOptions builderOptions)
        Initialize an instance of AxeBuilder.
        Parameters:
        builderOptions - Builder options
      • AxeBuilder

        public AxeBuilder​(AxeBuilderOptions builderOptions,
                          com.fasterxml.jackson.databind.ObjectMapper objectMapper)
        Initialize an instance of AxeBuilder.
        Parameters:
        builderOptions - Builder options
        objectMapper - Mapper to use when converting JSON
    • Method Detail

      • getDefaultAxeBuilderOptions

        public AxeBuilderOptions getDefaultAxeBuilderOptions()
        get the default axe builder options.
        Returns:
        the Axe Builder Options
      • setAxeScriptProvider

        public AxeBuilder setAxeScriptProvider​(IAxeScriptProvider axeProvider)
        sets the where we get the axe script from.
        Parameters:
        axeProvider - the source of the axe script
        Returns:
        an Axe Builder object
      • setTimeout

        public AxeBuilder setTimeout​(int newTimeout)
        sets the timeout.
        Parameters:
        newTimeout - the int value to be set
        Returns:
        an Axe Builder object
      • getOptions

        public String getOptions()
        gets the options.
        Returns:
        the options
      • setOptions

        public void setOptions​(String newOptions)
        sets the options.
        Parameters:
        newOptions - the options to be set
      • withoutIframeSandboxes

        public AxeBuilder withoutIframeSandboxes()
        Remove the "sandbox" attribute from iframes on the page.
        Returns:
        an Axe Builder
      • withOptions

        public AxeBuilder withOptions​(AxeRunOptions newRunOptions)
        Run configuration data that is passed to axe for scanning the web page. This will override the value set by WithRules(string[]), WithTags(string[]) & DisableRules(string[])
        Parameters:
        newRunOptions - run options to be used for scanning.
        Returns:
        an Axe Builder
      • withTags

        public AxeBuilder withTags​(List<String> tags)
        Limit analysis to only the specified tags. Refer https://www.deque.com/axe/axe-for-web/ documentation/api-documentation/#api-name-axegetrules to get the list of supported tag names. Cannot be used with WithRules(string[]) & Options
        Parameters:
        tags - tags to be used for scanning
        Returns:
        an Axe Builder
      • withOnlyRules

        public AxeBuilder withOnlyRules​(List<String> rules)
        Limit analysis to only the specified rules. Refer https://dequeuniversity.com/rules/axe/ to get the complete listing of available rule IDs. Cannot be used with WithTags(List<String>) & Options
        Parameters:
        rules - rule IDs to be used for scanning
        Returns:
        an Axe Builder
      • withRules

        public AxeBuilder withRules​(List<String> rules)
        Limit analysis to only the specified rules. Refer https://dequeuniversity.com/rules/axe/ to get the complete listing of available rule IDs. Cannot be used with WithTags(List<String>) & Options
        Parameters:
        rules - rule IDs to be used for scanning
        Returns:
        an Axe Builder
      • disableRules

        public AxeBuilder disableRules​(List<String> rules)
        Set the list of rules to skip when running an analysis. Refer https://dequeuniversity.com/rules/axe/ to get the complete listing of available rule IDs. Cannot be used with Options
        Parameters:
        rules - rule IDs to be skipped from analysis
        Returns:
        an Axe Builder
      • include

        public AxeBuilder include​(List<String> selectors)
        Selectors to include in the validation. Note that the selectors array uniquely identifies one element in the page, Valid usage: axeBuilder.Include("#parent-iframe1", "#element-inside-iframe"); => to select #element-inside-iframe under #parent-iframe1 axeBuilder.Include("#element-inside-main-frame1"); Invalid usage: axeBuilder.Include("#element-inside-main-frame1", "#element-inside-main-frame2");
        Parameters:
        selectors - Any valid CSS selectors
        Returns:
        an Axe Builder
      • exclude

        public AxeBuilder exclude​(List<String> selectors)
        Selectors to exclude in the validation. Note that the selectors array uniquely identifies one element in the page. Refer include(string[]) for more information on the usage
        Parameters:
        selectors - Any valid CSS selectors
        Returns:
        an Axe Builder
      • withOutputFile

        public AxeBuilder withOutputFile​(String path)
        Causes analyze() to write the axe results as a JSON file, in addition to returning it in object format as usual.
        Parameters:
        path - Path to the output file. Will be passed as-is to the System.IO APIs.
        Returns:
        an Axe builder
      • analyze

        public Results analyze​(org.openqa.selenium.WebDriver webDriver,
                               org.openqa.selenium.WebElement... context)
        Run axe against a specific WebElement or webElements (including its descendants).
        Parameters:
        webDriver - for the page to be scanned
        context - WebElement(s) to test
        Returns:
        An axe results document
      • analyze

        public Results analyze​(org.openqa.selenium.WebDriver webDriver)
        Run axe against the entire page.
        Parameters:
        webDriver - for the page to be scanned
        Returns:
        An axe results document
      • analyze

        public Results analyze​(org.openqa.selenium.WebDriver webDriver,
                               boolean injectAxe)
        Run axe against the entire page.
        Parameters:
        webDriver - for the page to be scanned
        injectAxe - whether or not to inject axe into the page
        Returns:
        An axe results document