Selenium Java SDK

The Evinced Selenium Java SDK integrates with new or existing Selenium WebDriver tests to automatically detect accessibility issues. By adding a few lines of code to your Selenium WebDriver project, you can begin analyzing all the web pages and DOM changes to provide a dynamic view of how your site can become more accessible. As a result of the test, a rich and comprehensive report is generated to easily track issues to resolution.

Interested in seeing this in action? Contact us to get started!

Prerequisites

  • Selenium version 3.141.59 or higher
  • Java Version 11 or higher
  • ChromeDriver or FirefoxDriver

Get Started

Installation

Install Selenium Java SDK from a local ZIP archive

You can perform installation right from the standalone .jar distribution. In this case, you need to do the following:

  1. Download the .jar file.
  2. Unpack the provided selenium-sdk.zip to any desirable location
  3. Add the following dependencies entries pointing to selenium-sdk.jar
    1. Gradle:
      1 implementation files('/Users/<path-to-your-upacked-folder>/selenium-sdk.jar')
    2. Maven:
      1. First, install the “all“ jar into your local Maven repository by the following command:
        1mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file –Dfile=selenium-sdk-<version>.jar -DpomFile=selenium-sdk-<version>.pom
        Example:
        1mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=selenium-sdk-1.30.1.jar -DpomFile=selenium-sdk-1.30.1.pom
      2. Add the corresponding dependency into your pom.xml:
        1 <dependency>
        2 <groupId>com.evinced</groupId>
        3 <artifactId>selenium-sdk</artifactId>
        4 <version>1.30.1</version>
        5 </dependency>

Your First Test

SDK Initialization

To work with Selenium Java SDK you need to have authentication token. Please refer to licensing section for details.

Add the import statement to the beginning of your test file.

1import com.evinced.EvincedWebDriver;

Under the hood, the Evinced SDK utilizes several Selenium commands in order to get accessibility data. For this reason, we need to initialize EvincedWebDriver with the ChromeDriver instance in the following way:

1EvincedWebDriver driver = new EvincedWebDriver(new ChromeDriver());

Add Evinced accessibility checks (Single Run Mode)

This is a simple example of how to add an Evinced accessibility scan to a test. Please note the inline comments that give detail on each test step. This is a simple JUnit example of how to add a single Evinced accessibility scan to a test. Please note the inline comments that give detail on each test step.

1@Test
2public void evAnalyzeSimpleTest() {
3 // Initialize EvincedWebDriver which wraps a ChromeDriver instance
4 EvincedWebDriver driver = new EvincedWebDriver(new ChromeDriver());
5
6 // Navigate to the site under test
7 driver.get("https://www.google.com");
8
9 // Run analysis and get the accessibility report
10 Report report = driver.evAnalyze();
11
12 // Assert that there are no accessibility issues
13 assertTrue(report.getIssues().size() == 0);
14}

Add Evinced accessibility checks (Continuous Mode)

This is an example of how to add a continuous Evinced accessibility scan to a test. Using the evStart() and evStop() methods, the Evinced engine will continually scan in the background capturing all DOM changes and page navigations as the test is executed. This will capture all accessibility issues as clicking on drop-downs or similar interactions reveals more of the page. The advantage of continuous mode is that no interaction with the actual test code is needed. This is a simple JUnit example of how to add a continuous Evinced accessibility scan to a test. Using the evStart and evStop methods, the Evinced engine will continually scan in the background capturing all DOM changes as the test is executed. This will capture all accessibility issues as clicking on dropdowns or similar interactions reveals more of the page. The advantage of continuous mode is that no interaction with the actual test code is needed.

1@BeforeClass
2public static void setUp() throws MalformedURLException, IOException {
3 driver = new EvincedWebDriver(new ChromeDriver());
4 driver.setCredentials(<your service account ID>, <your API key>);
5 // Start the Evinced engine scanning for accessibility issues
6 driver.evStart();
7 //... the rest of our setup code
8}
9
10@AfterClass
11public static void tearDown() throws MalformedURLException, IOException {
12 // Stop the Evinced engine
13 Report report = driver.evStop();
14 //Output the Evinced report in either JSON or HTML format
15 EvincedReporter.evSaveFile("test-results", report, EvincedReporter.FileFormat.HTML);
16 EvincedReporter.evSaveFile("test-results", report, EvincedReporter.FileFormat.JSON);
17 driver.quit();
18}
19
20@Test
21public void evAnalyzeSimpleTest() {
22 // Navigate to the site under test
23 driver.get("https://www.google.com");
24 // More test code...
25}

API

global initialization

Initializes the Evinced object within the project.

Example

The EvincedWebDriver constructor expects an instance of ChromeWebDriver. It is possible to pass an instance of a class that inherits or extends WebDriver.

1ChromeDriver chromeDriver = new ChromeDriver();
2EvincedWebDriver driver = new EvincedWebDriver(chromeDriver);

Please refer to configuration to see examples of using init with options.

evAnalyze(options)

Scans the current page and returns a list of accessibility issues.

Note: This method is not supported if evStart() is already running.

Please refer to configuration to see examples of using init with options.

Example

1Report report = evincedWebDriver.evAnalyze();

Return value

1Report

A Report object is returned containing accessibility issues. This is the recommended method for static page analysis. For more information regarding reports as well as the Report object itself, please refer to our detailed Web Reports page.

evStart(options)

Continually watches for DOM mutations and page navigation and records all accessibility issues until the evStop() method is called. This method is recommended for dynamic page flows.

Example

1evincedWebDriver.evStart();

Return value

1void

evStop(options)

Stops the process of issue gathering started by evStart() command.

Example

1evincedWebDriver.evStart();
2Report report = evincedWebDriver.evStop();

Return value

1Report

Returns an object containing recorded accessibility issues from the point in time at which the evStart() method was instantiated. For more information regarding reports as well as the returned object itself, please refer to detailed Web Reports page.

evSaveFile(destination, issues, format)

Saves list of the issues in a file, with the specified format and location. For example, format could be ‘json', 'html, 'sarif' or 'csv'. Please find detailed information on Web Reports page.

Example

1Report report = evincedWebDriver.evStop();
2 -- or --
3Report report = evincedWebDriver.evAnalyze();
4
5// create a JSON file named jsonReport.json
6EvincedReporter.evSaveFile("jsonReport", report, EvincedReporter.FileFormat.JSON);
7
8// create an HTML file named htmlReport.html
9EvincedReporter.evSaveFile("htmlReport", report, EvincedReporter.FileFormat.HTML);
10
11// create an SARIF file named sarifReport.sarif.json
12EvincedReporter.evSaveFile("sarifReport", report, EvincedReporter.FileFormat.SARIF);
13
14// create an CSV file named csvReport.csv
15EvincedReporter.evSaveFile("csvReport", report, EvincedReporter.FileFormat.CSV);

Note: To generate a report in the specific format (but JSON) we are running some code on the browser side. If you are using custom WebDriver or there are some environmental issues with starting browser or driver during report generation, please use the command where you can provide the WebDriver object.

1WebDriver driver = yourCustomMethodToInstaantiateDriver();
2// Generates aggregated report using custom WebDriver object
3EvincedReporter.evSaveFile("htmlReport", EvincedReporter.FileFormat.HTML, driver);
4driver.quit();

FileFormat

Defines the file type of the report. Options are JSON, HTML, SARIF and CSV.

Return value

1Path

The Path object representing the location where the result file was stored.

Aggregated Report

The aggregated report feature allows you to have a general aggregated report for the whole run (not only for one test or suite). This report will contain all the issues found by the tests where evStart() and evStop() commands were called. It is still possible to use the evSaveFile() command in any place of your code along with this Aggregated Report feature.

Example

1Path htmlAggregatedReport = EvincedReporter.evSaveFile("evinced-html-report", EvincedReporter.FileFormat.HTML);

Licensing

To work with Selenium Java SDK you need to have Authentication token. There are two methods to provide the token: offline mode and online mode. The difference is if you use online mode the request to obtain the token will be sent to Evinced Licencing Server. You need to provide Service ID and Secret API key in such a case. They are available via the Evinced Product Hub.

Offline mode assumes that you already have token and can provide it directly. If an offline token is required please reach out to your account team or support@evinced.com.

We encourage to use environment variables to store credentials and read them in code

1# Offline mode
2export AUTH_SERVICE_ID=<serviceId>
3export AUTH_TOKEN=<token>
4
5# Online mode
6export AUTH_SERVICE_ID=<serviceId>
7export AUTH_SECRET=<secret>

Example

Add this code either in some static initializer section or into BeforeAll clause, so it should be called once before the first test.

1// Offline mode
2EvincedSDK.setOfflineCredentials(System.getenv("AUTH_SERVICE_ID"), System.getenv("AUTH_TOKEN"));
3// OR
4// Online mode
5EvincedSDK.setCredentials(System.getenv("AUTH_SERVICE_ID"), System.getenv("AUTH_SECRET"));

Configuration

The same configuration object can be used in global initialization, evStart() and evAnalyze() methods but with a bit different consequences. By providing some options in global initialization method you define a global configuration for all calls of evStart() or evAnalyze() methods. Please note that global configuration is not intended to be altered from tests due to it will affect all the rest tests as well as tests running in parallel threads. To alter configuration in specific tests you can provide config on the method's level, for instance with evStart() it defines local configuration for this particular session until evStop() is called. If provided in both levels, the command's level config will override the global one.

Engines configuration

Evinced uses two separate engines when scanning for accessibility issues, one is the aXe engine and the other is the Evinced engine. By default, Evinced disables the aXe Needs Review and Best Practices issues based on customer request and due to the fact they are mostly false positives. Please note this setting when comparing issue counts directly. See an example of how to enable Needs Review and Best practices issues in our toggles section.

Configuration object type

EvincedWebDriver has an optional second parameter is an EvincedConfiguration. When configurations are passed via the constructor, they are set as a default for all future actions.

1ChromeDriver chromeDriver = new ChromeDriver();
2EvincedConfiguration configuration = new EvincedConfiguration();
3EvincedWebDriver driver = new EvincedWebDriver(chromeDriver, configuration);

The configurations can be passed to a specific command, such as evAnalyze() or evStart(), it will override the constructor configurations for that specific command's call.

1EvincedConfiguration configuration = new EvincedConfiguration();
2configuration.setUseGlobalPersistentData(true);
3Report report = evincedWebDriver.evAnalyze(configuration);

Root Selector

Instructs engine to return issues which belong to or which are nested to element with the specified selector. By default the issues for all elements from document root will be returned.

null by default.

Example

1EvincedConfiguration configuration = new EvincedConfiguration();
2configuration.setRootSelector(".some-selector"); // css selector

AXE Configuration

Evinced leverages Axe open-source accessibility toolkit as part of its own accessibility detection engine. The Evinced engine is able to pinpoint far more issues than Axe alone.

For the full Axe config options, see Axe Core API.

Example

1EvincedConfiguration configuration = new EvincedConfiguration();
2AxeConfiguration axeConfig = new AxeConfiguration();
3
4// Axe's syntax to make `html-has-lang` validation disabled
5axeConfig.setRules(Collections.singletonMap("html-has-lang", Collections.singletonMap("enabled", false)));
6configuration.setAxeConfig(axeConfig);

Errors Strict Mode

When set to true it switches SDK in mode when Evinced SDK errors are thrown as runtime errors and stops current test execution. Otherwise errors are printed into console except critical ones.

false by default.

Example

The feature **is not yet implemented** in this SDK. If you'd like to increase the priority of it, please contact support@evinced.com.

Engine Logging

Switches logging on for engine. Log messages from the engine will be printed to console.

Levels are: debug, info, warn, error

null by default.

error is a default level on engine side.

EvincedConfiguration globalConfig = new EvincedConfiguration();

1Logging enginesLogging = getEnginesConfig(globalConfig).getLogging();
2
3Logging logging = new Logging();
4logging.setLoggingLevel("debug");
5logging.setAddLoggingContext(false);
6
7globalConfig.setLogging(logging);

Reports Screenshots

The Screenshots feature allows to include screenshots to the Evinced reports. When the feature is enabled, Evinced will take screenshots of the page, highlight an element with a specific accessibility issue, and include them to the report.

screenshots_feature

false by default.

Note: The Screenshots feature may affect the test run performance.

Enabling the Screenshots feature

1// On global level
2ChromeDriver chromeDriver = new ChromeDriver();
3EvincedConfiguration configuration = new EvincedConfiguration();
4configuration.enableScreenshots(true);
5EvincedWebDriver driver = new EvincedWebDriver(chromeDriver, configuration);
6
7
8// OR
9
10// On command level
11EvincedConfiguration configuration = new EvincedConfiguration();
12configuration.enableScreenshots(true);
13driver.evAnalyze(configuration);
14

Toggles

Toggles are feature flags which controls SDK and Engine behavior. With toggles we introduce experimental features or manage the way how accessibility issues are gathered. The list of toggles is not specified so we suggest not to rely on specific toggle name or value and use them in investigation purposes only.

Example enabling aXe Best Practices and Needs Review Issues

1// Globally
2EvincedConfiguration globalConfig = new EvincedConfiguration();
3Map<String, Boolean> toggles = new HashMap<String, Boolean>(){{
4 put(FLAG_NAME_1, false);
5 put(FLAG_NAME_2, true);
6}};
7globalConfig.setExperimentalFlags(toggles);
8
9// Example enabling aXe Needs Review and Best Practices Issues
10EvincedConfiguration globalConfig = new EvincedConfiguration();
11globalConfig.addExperimentalFlag(USE_AXE_NEEDS_REVIEW, true);
12globalConfig.addExperimentalFlag(USE_AXE_BEST_PRACTICES, true);

Skip Validations

Skips specific validations for the given URL pattern and the selector.

SkipValidation[] by default.

Example

1EvincedConfiguration globalConfig = new EvincedConfiguration();
2String selector1 = "test.1--selector";
3String selector2 = "test.2--selector";
4String type1 = "NO_DESCRIPTIVE_TEXT";
5String type2 = "NOT_FOCUSABLE";
6String type3 = "ONE_MORE_TYPE_TO_EXCLUDE";
7
8globalConfig.skipValidation(selector1, "http://url.to.skip/path1",
9 type1, type2);
10globalConfig.skipValidation(selector2, "http://url.to.skip/path2",
11 type2, type3, type1);

How to identify ID for the specific issue type is described in web reports section.

Knowledge Base Link overrides

This custom parameter helps to customize knowledge base links in the reports. Those links are displayed in the reports as follows:

kb_links

The knowledge base link can be overridden for every issue type ID.

Example

1EvincedConfiguration configuration = new EvincedConfiguration();
2configuration
3 .setKnowledgeBaseLink("WRONG_SEMANTIC_ROLE", "http://custom.kb.link/wrong_semantic_role")
4 .setKnowledgeBaseLink("WRONG_TAB_ORDER", "http://custom.kb.link/wrong_tab_order");

Where WRONG_SEMANTIC_ROLE is ID of the type of the specific issue. In this example, the corresponding issue type for this ID is Interactable Role. How to identify ID for the specific issue type is described in web reports section. After passing the type ID and a custom knowledge base link we are set to see it in the reports.

Shadow DOM support

Example

1EvincedConfiguration configuration = new EvincedConfiguration();
2configuration.setIncludeShadowDOM(true);

IFrames support

When set to true, the accessibility tests run analysis on iframes that exist inside the page. Default is false.

1EvincedConfiguration configuration = new EvincedConfiguration();
2configuration.setIncludeIframes(true);

Global Switch

Global Switch allows to disable or enable Evinced functionality. It could be needed, for example, while working on functional tests in your local environment or for running some CI jobs that are not intended to gather information regarding accessibility issues.

When switched off

  • evStart() and evSaveFile() will be bypassed.
  • evStop() and evAnalyze() will return an empty report.
  • evValid() will never fail.

true by default.

Important! Global Switch environment variable overrides the global configuration option.

Switch on/off Evinced functionality in config

1EvincedSDK.switchOn(false);

Switching off Evinced functionality with environment variable

1export EV_SWITCH_ON=false

Tutorials

You can find fully functional example projects on our GitHub

Tutorial 1

Generating a comprehensive accessibility report for your application

In this tutorial, we will enhance our existing Selenium UI test with the Evinced Selenium SDK in order to check our application for accessibility issues. In order to get started you will need the following:

  1. All of the prerequisites for the Evinced Selenium SDK should be met
  2. Evinced Selenium SDK should be added to your project

Preface - existing UI test overview

Let’s consider the following basic UI test as our starting point.

1import com.evinced.EvincedReporter;
2import com.evinced.EvincedWebDriver;
3import com.evinced.dto.results.Issue;
4import com.evinced.dto.results.Report;
5import org.junit.Assert;
6import org.junit.Test;
7import org.openqa.selenium.By;
8import org.openqa.selenium.WebElement;
9import org.openqa.selenium.chrome.ChromeDriver;
10import java.util.List;
11
12public class AccessibilityTests {
13 @Test
14 public void evAnalyzeWithAnOpenDropdownTest() {
15 ChromeDriver driver = new ChromeDriver();
16 driver.get("https://demo.evinced.com/");
17 WebElement firstDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(1) > div > div.dropdown.line"));
18 firstDropdown.click();
19 WebElement secondDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(2) > div > div.dropdown.line"));
20 secondDropdown.click();
21 driver.findElement(By.cssSelector(".react-date-picker")).click();
22 }
23}

We wrote this test for a demo travel site called TRVL that has a few known accessibility issues.

The purpose of this test is to check the functionality of the main application screen and ensure a user can successfully select their desired trip. For now, this test is only concerned with the functional testing of the app. However, with the help of the Evinced Selenium SDK, we can also check it for accessibility issues along the way. Let’s go through this process with the following step-by-step instructions.

Step #1 - Initialize the Evinced Selenium SDK

Before making any assertions against our app, we need to initialize EvincedWebDriver object. This object is used primarily as an entry point to all of the accessibility scanning features. Since we are going to use it scan throughout our test, the best place for its initialization will be our setUp method which gets executed first.

1import com.evinced.EvincedReporter;
2import com.evinced.EvincedWebDriver;
3import com.evinced.dto.results.Issue;
4import com.evinced.dto.results.Report;
5import org.junit.Assert;
6import org.junit.Test;
7import org.openqa.selenium.By;
8import org.openqa.selenium.WebElement;
9import org.openqa.selenium.chrome.ChromeDriver;
10import com.evinced.EvincedWebDriver;
11import java.util.List;
12
13public class AccessibilityTests {
14 private EvincedWebDriver driver;
15
16 @Before
17 public void setUp() {
18 driver = new EvincedWebDriver(new ChromeDriver());
19 }
20
21 @Test
22 public void evAnalyzeWithAnOpenDropdownTest() {
23 driver.get("https://demo.evinced.com/");
24 WebElement firstDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(1) > div > div.dropdown.line"));
25 firstDropdown.click();
26 WebElement secondDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(2) > div > div.dropdown.line"));
27 secondDropdown.click();
28 driver.findElement(By.cssSelector(".react-date-picker")).click();
29 }
30}

The EvincedWebDriver requires only an instance of ChromeDriver.

Step #2 - Start the Evinced engine

Now that we have initiated the Selenium driver and added the capabilities needed to scan for accessibility issues, let’s start the Evinced engine. Since we are going to use it scan throughout our test, the best place for its initialization will be our setUp method after our Selenium driver is configured.

1import com.evinced.EvincedReporter;
2import com.evinced.EvincedWebDriver;
3import com.evinced.dto.results.Issue;
4import com.evinced.dto.results.Report;
5import org.junit.Assert;
6import org.junit.Test;
7import org.openqa.selenium.By;
8import org.openqa.selenium.WebElement;
9import org.openqa.selenium.chrome.ChromeDriver;
10import com.evinced.EvincedWebDriver;
11import java.util.List;
12
13public class AccessibilityTests {
14 private EvincedWebDriver driver;
15
16 @Before
17 public void setUp() {
18 driver = new EvincedWebDriver(new ChromeDriver());
19 // Start the Evinced Engine
20 driver.evStart();
21 }
22
23 @Test
24 public void evAnalyzeWithAnOpenDropdownTest() {
25 driver.get("https://demo.evinced.com/");
26 WebElement firstDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(1) > div > div.dropdown.line"));
27 firstDropdown.click();
28 WebElement secondDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(2) > div > div.dropdown.line"));
29 secondDropdown.click();
30 driver.findElement(By.cssSelector(".react-date-picker")).click();
31 }
32}

There are additional configuration options that can be included as well. More information can be found in the API section of this documentation.

Step #3 - Stop the Evinced engine and create reports

As our test was executed we collected a lot of accessibility information. We can now perform accessibility assertions at the end of our test suite. Referring back again to our UI test the best place for this assertion will be the method that gets invoked last - tearDown. To stop the Evinced engine and generate the actual object representation of your accessibility report simply call the evStop() method. We can then output the report files in either HTML or JSON format (or both!).

1import com.evinced.EvincedReporter;
2import com.evinced.EvincedWebDriver;
3import com.evinced.dto.results.Issue;
4import com.evinced.dto.results.Report;
5import org.junit.Assert;
6import org.junit.Test;
7import org.openqa.selenium.By;
8import org.openqa.selenium.WebElement;
9import org.openqa.selenium.chrome.ChromeDriver;
10import com.evinced.EvincedWebDriver;
11import java.util.List;
12
13public class AccessibilityTests {
14 private EvincedWebDriver driver;
15
16 @Before
17 public void setUp() {
18 driver = new EvincedWebDriver(new ChromeDriver());
19 // Start the Evinced Engine
20 driver.evStart();
21 }
22
23 @After
24 public void tearDown() {
25 // Stop the Evinced Engine
26 Report report = driver.evStop();
27 // Output the Accessibility results in JSON or HTML
28 EvincedReporter.evSaveFile(testName.getMethodName(), report, EvincedReporter.FileFormat.HTML);
29 EvincedReporter.evSaveFile(testName.getMethodName(), report, EvincedReporter.FileFormat.JSON);
30 driver.quit();
31 }
32
33 @Test
34 public void evAnalyzeWithAnOpenDropdownTest() {
35 driver.get("https://demo.evinced.com/");
36 WebElement firstDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(1) > div > div.dropdown.line"));
37 firstDropdown.click();
38 WebElement secondDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(2) > div > div.dropdown.line"));
39 secondDropdown.click();
40 driver.findElement(By.cssSelector(".react-date-picker")).click();
41 }
42}

For the sake of simplicity of this tutorial let’s simply assume that our application is accessible as long as it has no accessibility issues found. Thus, if we have at least one accessibility issue detected - we want our tests to be failed. Let’s add the corresponding assertion to our tearDown method

1@After
2public void tearDown() {
3 // Stop the Evinced Engine
4 Report report = driver.evStop();
5 // Output the Accessibility results in JSON or HTML
6 EvincedReporter.evSaveFile(testName.getMethodName(), report, EvincedReporter.FileFormat.HTML);
7 EvincedReporter.evSaveFile(testName.getMethodName(), report, EvincedReporter.FileFormat.JSON);
8
9 // Optional assertion for gating purposes
10 List<Issue> issues = report.getIssues();
11 Assert.assertEquals(0, issues.size());
12
13 driver.quit();
14}

You are now set to run the test and ensure the accessibility of your application! So, go ahead and run it via your IDE or any other tooling you use for Java development.

Tutorial 2

Additional Configuration Examples

Testing accessibility in a specific state of the application

In this example, we are going to test the accessibility of a page in a specific state. This test navigates to a page, opens a dropdown, and only then runs the accessibility engines to identify issues.

1import com.evinced.EvincedReporter;
2import com.evinced.EvincedWebDriver;
3import com.evinced.dto.results.Issue;
4import com.evinced.dto.results.Report;
5import org.junit.Assert;
6import org.junit.Test;
7import org.openqa.selenium.By;
8import org.openqa.selenium.WebElement;
9import org.openqa.selenium.chrome.ChromeDriver;
10
11import java.util.List;
12
13public class AccessibilityTests {
14
15 @Test
16 public void evAnalyzeWithAnOpenDropdownTest() {
17 EvincedWebDriver driver = new EvincedWebDriver(new ChromeDriver());
18 driver.get("https://demo.evinced.com/");
19
20 // interacting with the page - opening all dropdown
21 WebElement firstDropdown = driver.findElement(By.cssSelector("div.filter-container > div:nth-child(1) > div > div.dropdown.line"));
22 firstDropdown.click();
23
24 Report report = driver.evAnalyze();
25 List<Issue> issues = report.getIssues();
26 Assert.assertEquals(8, issues.size());
27
28 // write the report to HTML format to a file named: "test-results.html"
29 EvincedReporter.evSaveFile("test-results", report, EvincedReporter.FileFormat.HTML);
30 }
31}
Running evAnalyze on multiple tabs

The evAnalyze command will works as expected on the primary tab. When testing on an additional browser tab, simply switch the driver from the primary Selenium “window handle” to the “window handle” of the new tab and then run evAnalyze. This code is shown on lines 14-15 of the example below.

Example In the example below, page1.html has a link that opens in a new tab.

1// navigate to page1
2driver.get("page1.html");
3
4// get report for page1
5Report report = driver.evAnalyze();
6List<Issue> issues = report.getIssues();
7// run some assertions
8assertEquals(1, issues.size());
9
10// perform an action that opens a new tab
11driver.findElement(new By.ById("open-tab-link")).click();
12
13// switch to new tab
14String tabWindowHandle = driver.getWindowHandles().toArray()[1].toString();
15driver.switchTo().window(tabWindowHandle);
16
17// get report for the new tab,
18// the issues for page1 won't appear here, only ones found on the new tab
19report = driver.evAnalyze();
20issues = report.getIssues();
21assertEquals(3, issues.size());

Running evStart and evStop on multiple tabs

The evStart and evStop method scopes are limited to a single tab or Selenium “window handle”. This means that if you have more than one tab, you will need to call evStop and then switch to the window handle of the new tab. Once the “window handle” switch has occurred, run a new instance of evStart followed evStop at the appropriate time.evStop must be called on the tab that evStart command was called on, before starting evStart on a new tab.

In the example below, page1.html has a link that opens in a new tab.

1 // navigate to page1
2 driver.get("page1.html");
3
4 driver.evStart();
5
6 // perform actions on page1, clicks, etc...
7
8 // the evStart and evStop scopes are limited to a single window handle.
9 // this means that if you have more than one tab, you need to switch it's window and only then run `evStart` and `evStop`
10 // The `evStop` must be called on the tab that `evStart` command was called on, before starting `evStart` on a new tab
11 Report report = driver.evStop();
12 List<Issue> issues = report.getIssues();
13 assertEquals(1, issues.size());
14
15 // perform an action that opens a new tab
16 driver.findElement(new By.ById("open-tab-link")).click();
17
18 // move to tab
19 String tabWindowHandle = driver.getWindowHandles().toArray()[1].toString();
20 driver.switchTo().window(tabWindowHandle);
21
22 // get report for the new tab,
23 // the issues for page1 won't appear here, only ones found on the new tab
24 driver.evStart();
25 report = driver.evStop();
26 issues = report.getIssues();
27 assertEquals(3, issues.size());

Running evStart and evStop on a different TargetLocator (frame / iframe)

In case the evStart command is called on a different context, for example - after switching WebDriver’s context into an iframe, the Evinced engines will be injected into that iframe only. In order to get the results back you will need to switch to the same context evStart was called on, before calling evStop. In case you are using a website that relies deeply on iframes, we suggest using the IncludeIframes API configuration.

In the example below, page1.html has an iframe in it, with id iframe1.

1 // navigate to page1
2 driver.get("page1.html");
3
4 // switch to the iframe
5 driver.switchTo().frame(driver.findElement(By.id("iframe1")));
6
7 // start recording
8 driver.evStart();
9
10 // perform actions on iframe1 inside page1, clicks, etc...
11
12 // if you go back to the defaultContent (the iframe parent)
13 // the `evStop` method will fail
14 driver.switchTo().defaultContent();
15
16 // don't do that, it will fail
17 driver.evStop();
18
19 // but you can get the results when inside the iframe
20 // switch to the iframe
21 driver.switchTo().frame(driver.findElement(By.id("iframe1")));
22
23 // now evStop returns all the issues recorded inside the iframe
24 Report report = driver.evStop();
25 List<Issue> issues = report.getIssues();
26 assertEquals(1, issues.size());

Add accessibility testing to existing tests

It is possible to configure EvincedWebDriver to be called also used in @Before and @After methods. In the example below, evStart starts recording before the test starts, and evStop is called after each test.

1import com.evinced.dto.results.Report;
2import io.github.bonigarcia.wdm.WebDriverManager;
3import org.junit.*;
4import org.junit.rules.TestName;
5import org.openqa.selenium.chrome.ChromeDriver;
6
7public class BeforeAfterTest {
8
9 @Rule
10 public TestName testName = new TestName();
11
12 private EvincedWebDriver driver;
13
14 /**
15 * Instantiate the WebDriver
16 */
17 @BeforeClass
18 public void setupClass() {
19 WebDriverManager.chromedriver().setup();
20 driver = new EvincedWebDriver(new ChromeDriver());
21 driver.manage().window().maximize();
22 }
23
24 /**
25 * Start recording before each test
26 */
27 @Before
28 public void setUp() {
29 driver.evStart();
30 }
31
32 /**
33 * Ensure we close the WebDriver after finishing
34 */
35 @After
36 public void after() {
37 // write an HTML report to file
38 Report report = driver.evStop();
39 EvincedReporter.evSaveFile(testName.getMethodName(), report, EvincedReporter.FileFormat.HTML);
40 }
41
42 @Test
43 public void visitDemoPage() {
44 driver.get("https://demo.evinced.com");
45 }
46
47 @Test
48 public void visitGoogle() {
49 driver.get("https://www.google.com");
50 }
51}

Support

Please feel free to reach out to support@evinced.com with any questions.

FAQ

  1. Can I configure which validations to run?

Yes, see the configuration section for details on how to configure Axe validations to your needs.

  1. Can I run tests with Evinced using cloud-based services like Sauce Labs, Perfecto, or BrowserStack?

Yes, we have tested the Evinced SDK on many of these types of cloud-based services and expect no issues.