Selenium C# SDK

The Evinced Selenium C# 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

The C# support for this SDK is currently limited to projects built using .NET Standard or .NET Core. It does not support projects built on .NET Framework 4.8 or below.

  • Selenium.WebDriver version 4.10.0 or higher
  • .Net Core version 7 or higher
  • ChromeDriver

Get started

Installation

To install Selenium C# SDK you will need either a file provided by Evinced Support or access to a remote repository that provides it. If you have neither, contact us to get started.

Installation with a locally provided file

  1. Download the Selenium.CS.SDK.version.nupkg file.
  2. Add it to the project
1# To install the SDK.
2dotnet add package Selenium.CS.SDK -v <version> -s <path-to-folder-with-nupkg-file>
3
4# To restore all needed .NET dependencies.dotnet add reference <path-to-dll>Selenium.CS.SDK.dll
5dotnet restore

Installation from a remote repository

Evinced Customers have the option of accessing Selenium C# SDK from a remote repository — the Evinced Jfrog Artifactory — to keep their SDK version up-to-date and to share the SDK internally at their organization.

Contact us for help.

Authentication

To launch Selenium C# SDK, you need to have a Service ID and an API Key.

Where to find your Evinced SDK credentials

These credentials are available via the Evinced Product Hub in the “Automation for Web” or “Automation for Mobile” product areas. Click the “Get SDK” button to see the Service Account ID and API Key at the bottom of the page.

Authenticate for Offline Testing

There are two methods to provide the token: online mode and offline mode. Online mode contacts the Evinced Licensing Server. Offline mode assumes that an Evinced employee has supplied a JSON Web Token (JWT). If an offline token is required, please reach out to your account team or support@evinced.com.

Please set credentials in environment variables and reference the environment variables in code.

1# Online mode
2export EVINCED_SERVICE_ID=<serviceId>
3export EVINCED_API_KEY=<apiKey>
4
5# Offline mode, when a JWT has been provided by Evinced
6export EVINCED_SERVICE_ID=<serviceId>
7export EVINCED_AUTH_TOKEN=<token>

Setting credentials, an example:

1using Evinced.SDK;
2
3// Online mode (not yet implemented)
4EvincedSDK.SetCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_API_KEY"));
5
6// Offline mode
7EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));

Your First Test

SDK Initialization

To use Selenium C# SDK, you first need to authenticate. Please refer to Authentication for details.

The only command you need to add is to wrap the existing WebDriver object

1using Evinced.SDK;
2
3IEvincedDriver driver = EvincedDriverFactory.Create(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.

1[Test]
2public void EvAnalyzeTest() {
3 EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));
4
5 // Initialize EvincedWebDriver which wraps a ChromeDriver instance
6 IEvincedDriver driver = EvincedDriverFactory.Create(new ChromeDriver());
7
8 try {
9 // Navigate to the site under test
10 driver.Navigate().GoToUrl("https://www.google.com");
11
12 // Run analysis and get the accessibility report
13 IReport result = driver.EvAnalyze();
14
15 // Assert that there are no accessibility issues
16 Assert.That(result.GetIssues(), Has.Count.EqualTo(0));
17 } finally {
18 driver.Quit();
19 }
20}

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 navigation 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.

1[Test]
2public void StartStopSimpleTest() {
3 EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));
4
5 // Initialize EvincedWebDriver which wraps a ChromeDriver instance
6 IEvincedDriver driver = EvincedDriverFactory.Create(new ChromeDriver());
7
8 try {
9 // Navigate to the site under test
10 driver.Navigate().GoToUrl("https://www.google.com");
11 // Start the Evinced engine scanning for accessibility issues
12 driver.EvStart();
13
14 // More test code to interact with the page
15
16 // Stop the Evinced engine
17 IReport report = driver.EvStop();
18 // Output the Evinced report in either JSON or HTML format
19 EvincedSDK.EvSaveFile("test-results", report, FileFormat.JSON);
20 EvincedSDK.EvSaveFile("test-results", report, FileFormat.HTML, driver);
21
22 // Reports will be stored in the current directory
23 Console.WriteLine(Directory.GetCurrentDirectory());
24
25 } finally {
26 driver.Quit();
27 }
28}

API


EvincedDriverFactory.Create(chromeDriver)

Prepares the Evinced object for use in the project.

The EvincedDriverFactory.Create method expects an instance of ChromeDriver. It is possible to pass an instance of a class that implements a IWebDriver interface.

1ChromeDriver chromeDriver = new ChromeDriver();
2IEvincedDriver evincedWebDriver = EvincedDriverFactory.Create(chromeDriver);

Refer to Configuration to see examples of initializing with options.


EvAnalyze(options)

Scans the current page and returns a list of accessibility issues. This is the recommended method for static page analysis.

Note: This method is not supported if EvStart is already running.

1IReport result = evincedWebDriver.EvAnalyze();

Returns IReport.

The returned report object contains a list of accessibility issues.

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, recording accessibility issues until the EvStop method is called. This method is recommended for dynamic page flows.

1evincedWebDriver.EvStart();

Returns void.


EvStop

Stops the issue-gathering process started by EvStart.

1evincedWebDriver.EvStart();
2IReport report = evincedWebDriver.EvStop();

Returns IReport.

The returned report object includes all accessibility issues detected between the EvStart and EvStop method calls.

For more information regarding reports as well as the report object itself, please refer to our detailed Web Reports page.


EvSaveFile(destination, format, issues)

Saves issues in a file with the specified format and location. Supported formats are json, html, sarif, and csv. Find detailed information in the Web Reports page.

1IReport report = evincedWebDriver.EvStop();
2 -- or --
3IReport report = evincedWebDriver.EvAnalyze();
4
5// create a JSON file named jsonReport.json
6EvincedSDK.EvSaveFile.EvSaveFile("jsonReport", report, EvincedReporter.FileFormat.JSON);
7
8// create an HTML file named htmlReport.html
9EvincedSDK.EvSaveFile("htmlReport", report, EvincedReporter.FileFormat.HTML);
10
11// create an SARIF file named sarifReport.sarif.json
12EvincedSDK.EvSaveFile("sarifReport", report, EvincedReporter.FileFormat.SARIF);
13
14// create an CSV file named csvReport.csv
15EvincedSDK.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();
2EvincedSDK.EvSaveFile("sarifReport", report, EvincedReporter.FileFormat.SARIF, driver);
3driver.Quit();

FileFormat

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

Returns string.

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.

1EvincedSDK.EvSaveFile("evinced-html-report-json", FileFormat.JSON);

Configuration

The same configuration object can be used when initializing the Evinced object using Global.Config and when calling the EvStart and EvAnalyze methods but with a bit different consequences. Providing options when initializing defines a global configuration for all calls of EvAnalyze and EvStart, while providing options to either of those methods affect only the test in which they are called.

Options provided in either EvAnalyze or EvStart override those set in Evinced engine initialization.

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 the Toggles section.

Configuration Object

Global.Config is a global configuration of type EvincedConfig that will be used with all commands by default.

1Global.Config.RootSelector = "#some-selector";

The configurations can be passed to a specific command, such as EvAnalyze or EvStart, it will override the global configuration for a single run.

1EvincedConfig config = new EvConfig();
2config.RootSelector = "#some-selector";
3driver.EvStart(config);

Root Selector

Sets a CSS selector to limit the Evinced Engine to scan only the selected element and its children. Must be a valid CSS selector. If not set, the Evinced Engine will scan the entire document.

Default: no value

1EvincedConfig config = new();
2config.RootSelector = ".some-selector";

Reports Screenshots

When true, the Evinced SDK will include screenshots in its reports that highlight elements with accessibility issues.

Default: false.

Note: Enabling screenshots may affect test run performance.

screenshot of a demo.evinced.com page with an issue highlighted

1// On global level
2Global.Config.EnableScreenshots = true;
3
4// OR
5
6// On command level
7EvincedConfig config = new() {
8 EnableScreenshots = false
9};
10evincedWebDriver.EvAnalyze(config);

Toggles

Enables experimental features. Feature names and values may vary from release to release.

Example:

1// Globally
2Global.Config.AddToggle(USE_AXE_NEEDS_REVIEW, true)
3 .AddToggle(USE_AXE_BEST_PRACTICES, true);

Skip Validations

Sets validation types to be skipped for specified URL pattern and CSS selector. Issue type IDs can be found by inspecting a JSON report as described in Web Reports.

Default: no validations skipped.

1string selector1 = "test.1--selector";
2string type1 = "NO_DESCRIPTIVE_TEXT";
3string type2 = "NOT_FOCUSABLE";
4Global.Config.AddSkipValidation(selector1, "http://url.to.skip/path1", new List<string> { type1, type2 });

Shadow DOM Support

Shadow DOM is now supported by default. No additional configuration is needed.

IFrames Support

When true, accessibility analysis includes iframe that exist inside the page.

Default: false.

1EvincedConfig configuration = new EvincedConfig();
2configuration.IFramesInclude = true;

Proxy

Configures proxy server access settings. Needed to enable outbound communication to the Evinced Platform through a proxy server.

1...
2string proxyString = "ip:port";
3Proxy proxy = new(){
4 Kind = ProxyKind.Manual,
5 IsAutoDetect = false,
6 HttpProxy = proxyString,
7 SslProxy = proxyString,
8};
9options.Proxy = proxy;
10ChromeDriver chromeDriver = new(options);
11IEvincedDriver evincedWebDriver = EvincedDriverFactory.Create(chromeDriver);
12...

Global Switch

When false, disables Evinced functionality. Enabled by default, use this setting to disable Evinced accessibility analysis when not needed during test development or when running CI jobs where accessibility testing is not intended.

Default: true.

When switched off:

  • EvStart and EvSaveFile will be bypassed.
  • EvStop and EvAnalyze will return an empty report.

Switching Evinced Functionality Off in Configuration

1EvincedSDK.SwitchOn(false);

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

Switching Evinced Functionality Off in Environment

1export EV_SWITCH_ON=false

Uploading Reports to Evinced Platform

Introduction

Evinced Platform allows you to seamlessly collect, organize, visualize and monitor Evinced accessibility reports in one place. In this section, we will guide you through the key functionalities of the upload methods of the accessibility reports from the Evinced SDK to the Evinced Platform, which was introduced in version 2.2.2. This upload method is fully compatible with the previous versions of the Evinced SDK API, and is disabled by default.

Enable Upload Report to Platform

To enable the uploading functionality of accessibility reports to the Evinced Platform you will need to set the UploadToPlatform method to "true":

1EvincedSDK.UploadToPlatform = true;

Automatic Report Upload

Once the UploadToPlatform method is set to true, then by default all generated reports will be uploaded to the Platform upon calling the EvStop command. If you want to change this behavior, set the PlatformUploadByDefault feature flag to false.

1EvincedSDK.PlatfomUploadByDefult = false;

If the PlatformUploadByDefault is disabled, you can still upload selected reports to the platform. For that, use the following parameter in the EvStop command:

1driver.EvStop(PlatformUpload.Enabled);

Test Names

To facilitate report management and be able to distinguish between different reports on the Platform, use the SetTestInfo method to inform the test name and test class. It’s recommended to do that in the “beforeEach” hook.

NUnit

1[SetUp]
2public virtual void BeforeTestMethod() {
3 driver.SetTestInfo(TestContext.CurrentContext.Test.Name, TestContext.CurrentContext.Test.FullName);
4}

Labels and Custom Fields

You can attach labels and custom fields to your report to enhance readability in the platform. The labels will be added to the uploaded reports. See the following code example of how to set that up:

1EvincedSDK.TestRunInfo()
2 .AddLabel(Label.GIT_BRANCH, "main")
3 .AddLabel(Label.GIT_USERNAME, "testUser")
4 .CustomLabel("ProductVersion", "1.2.3")
5 .CustomLabel("TestRunType", "Demo c# selenium test run");

Use of beforeEach and afterEach Hooks

We recommend using the beforeEach and afterEach hooks to control analysis sessions and upload reports to the platform. This way, each test will be uploaded separately with its own report.

In beforeEach hook use EvStart to start Evinced analysis and set any labels you want for the report to contain when uploading to the platform. In the afterEach hook call EvStop to stop analysis and upload reports to the platform. See this code example:

NUnit

1[SetUp]
2public virtual void BeforeTestMethod() {
3 driver.SetTestInfo(TestContext.CurrentContext.Test.Name, TestContext.CurrentContext.Test.FullName);
4 driver.EvStart();
5}
6
7[TearDown]
8public virtual void AfterTestMethod() => _driver.EvStop();

Putting All of This Together

Here is a complete code snippet of how to perform uploads to the platform on a per-test basis.

1using Evinced.SDK.Implementation.ResultsUpload;
2using OpenQA.Selenium;
3
4namespace Test {
5 [SetUpFixture]
6 public class OneTimeSetup {
7 [OneTimeSetUp]
8 public void BeforSuite() {
9 EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));
10 EvincedSDK.UploadToPlatform = true;
11 EvincedSDK.TestRunInfo()
12 .AddLabel(Label.GIT_BRANCH, "main")
13 .AddLabel(Label.GIT_USERNAME, "testUser")
14 .CustomLabel("ProductVersion", "1.2.3")
15 .CustomLabel("TestRunType", "test example run");
16 }
17 }
18
19 public class BaseTest {
20
21 internal static protected IEvincedDriver _driver;
22
23 [OneTimeSetUp]
24 public void BeforeTest() => _driver = getDriver();
25
26 private static IEvincedDriver getDriver() {
27 ChromeOptions options = new();
28 return EvincedDriverFactory.Create(new ChromeDriver(options));
29 }
30
31 [SetUp]
32 public virtual void BeforeTestMethod() {
33 _driver.SetTestInfo(TestContext.CurrentContext.Test.Name, TestContext.CurrentContext.Test.FullName);
34 _driver.EvStart();
35 }
36
37 [TearDown]
38 public virtual void AfterTestMethod() => _driver.EvStop();
39
40 [OneTimeTearDown]
41 public void AfterTest() {
42 _driver.Quit();
43 }
44
45 [Test]
46 public void testUrl() {
47 _driver.Navigate().GoToUrl("https://demo.evinced.com");
48 }
49 }
50}

Tutorials

You can find fully functional example projects on our GitHub.

Step-by-step adding Evinced to existing test suite.

Preface: Existing test suite

1using Evinced.SDK;
2using NUnit.Framework;
3using OpenQA.Selenium;
4using OpenQA.Selenium.Chrome;
5using OpenQA.Selenium.Support.UI;
6using SeleniumExtras.WaitHelpers;
7
8
9namespace Tests {
10 public static class Locators {
11 public const string HOUSE_DROPDOWN = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(1) > div > div.dropdown.line";
12 public const string TENT_OPTION = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(1) > div > ul > li:nth-child(4)";
13 public const string LOCATION_DROPDOWN = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(2) > div > div.dropdown.line";
14 public const string CANADA_OPTION = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(2) > div > ul > li:nth-child(1)";
15 public const string SEARCH_BUTTON = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > a";
16 public const string SEARCH_RESULTS = "#gatsby-focus-wrapper > main > h1";
17 }
18
19 public class AccessibilityTests {
20 private IEvincedDriver driver;
21
22 [OneTimeSetUp]
23 public void OneTimeSetUp() {
24 EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));
25 this.driver = new ChromeDriver();
26 }
27
28 [OneTimeTearDown]
29 public void OneTimeTearDown() {
30 driver.Quit();
31 }
32
33 [Test]
34 public void TutorialTest1() {
35 driver.Navigate().GoToUrl("https://demo.evinced.com");
36 Assert.That(driver.FindElement(By.CssSelector(Locators.SEARCH_BUTTON)).Displayed, Is.True);
37 }
38
39 [Test]
40 public void TutorialTest2() {
41 driver.Navigate().GoToUrl("https://demo.evinced.com");
42 driver.FindElement(By.CssSelector(Locators.HOUSE_DROPDOWN)).Click();
43 driver.FindElement(By.CssSelector(Locators.TENT_OPTION)).Click();
44 driver.FindElement(By.CssSelector(Locators.LOCATION_DROPDOWN)).Click();
45 driver.FindElement(By.CssSelector(Locators.CANADA_OPTION)).Click();
46 driver.FindElement(By.CssSelector(Locators.SEARCH_BUTTON)).Click();
47 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
48 wait.Until(ExpectedConditions.ElementExists(By.TagName("body")));
49 Assert.That(driver.FindElement(By.CssSelector(Locators.SEARCH_RESULTS)).Displayed, Is.True);
50 }
51 }
52}

Step 1: Add Evinced, use snapshot scan and partial report

1using Evinced.SDK;
2using NUnit.Framework;
3using OpenQA.Selenium;
4using OpenQA.Selenium.Chrome;
5using OpenQA.Selenium.Support.UI;
6using SeleniumExtras.WaitHelpers;
7
8
9namespace Tests {
10 public static class Locators {
11 public const string HOUSE_DROPDOWN = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(1) > div > div.dropdown.line";
12 public const string TENT_OPTION = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(1) > div > ul > li:nth-child(4)";
13 public const string LOCATION_DROPDOWN = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(2) > div > div.dropdown.line";
14 public const string CANADA_OPTION = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(2) > div > ul > li:nth-child(1)";
15 public const string SEARCH_BUTTON = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > a";
16 public const string SEARCH_RESULTS = "#gatsby-focus-wrapper > main > h1";
17 }
18
19 public class AccessibilityTests {
20 private IEvincedDriver driver;
21
22 [OneTimeSetUp]
23 public void OneTimeSetUp() {
24 EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));
25 this.driver = EvincedDriverFactory.Create(new ChromeDriver());
26 }
27
28 [OneTimeTearDown]
29 public void OneTimeTearDown() {
30 driver.Quit();
31 }
32
33 [Test]
34 public void TutorialTest1() {
35 driver.Navigate().GoToUrl("https://demo.evinced.com");
36 Assert.That(driver.FindElement(By.CssSelector(Locators.SEARCH_BUTTON)).Displayed, Is.True);
37 IReport report = driver.EvAnalyze();
38 EvincedSDK.EvSaveFile(TestContext.CurrentContext.Test.Name, report, FileFormat.JSON);
39 }
40
41 [Test]
42 public void TutorialTest2() {
43 driver.Navigate().GoToUrl("https://demo.evinced.com");
44 driver.FindElement(By.CssSelector(Locators.HOUSE_DROPDOWN)).Click();
45 driver.FindElement(By.CssSelector(Locators.TENT_OPTION)).Click();
46 driver.FindElement(By.CssSelector(Locators.LOCATION_DROPDOWN)).Click();
47 driver.FindElement(By.CssSelector(Locators.CANADA_OPTION)).Click();
48 driver.FindElement(By.CssSelector(Locators.SEARCH_BUTTON)).Click();
49 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
50 wait.Until(ExpectedConditions.ElementExists(By.TagName("body")));
51 Assert.That(driver.FindElement(By.CssSelector(Locators.SEARCH_RESULTS)).Displayed, Is.True);
52 // Get issues snapshot on the result page
53 IReport report = driver.EvAnalyze();
54 // Assert page does not contain accessibility issues
55 Assert.That(result.GetIssues(), Has.Count.EqualTo(0));
56 }
57 }
58}

Step 2: Use continuous mode

Let's do a step back to the original test and start modifying it again. Some steps will be similar.

1using Evinced.SDK;
2using NUnit.Framework;
3using OpenQA.Selenium;
4using OpenQA.Selenium.Chrome;
5using OpenQA.Selenium.Support.UI;
6using SeleniumExtras.WaitHelpers;
7
8
9namespace Tests {
10 public static class Locators {
11 public const string HOUSE_DROPDOWN = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(1) > div > div.dropdown.line";
12 public const string TENT_OPTION = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(1) > div > ul > li:nth-child(4)";
13 public const string LOCATION_DROPDOWN = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(2) > div > div.dropdown.line";
14 public const string CANADA_OPTION = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > div:nth-child(2) > div > ul > li:nth-child(1)";
15 public const string SEARCH_BUTTON = "#gatsby-focus-wrapper > main > div.wrapper-banner > div.filter-container > a";
16 public const string SEARCH_RESULTS = "#gatsby-focus-wrapper > main > h1";
17 }
18
19 public class AccessibilityTests {
20 private IEvincedDriver driver;
21
22 [OneTimeSetUp]
23 public void OneTimeSetUp() {
24 EvincedSDK.SetOfflineCredentials(Environment.GetEnvironmentVariable("EVINCED_SERVICE_ID"), Environment.GetEnvironmentVariable("EVINCED_AUTH_TOKEN"));
25 this.driver = EvincedDriverFactory.Create(new ChromeDriver());
26 }
27
28 [OneTimeTearDown]
29 public void OneTimeTearDown() {
30 driver.Quit();
31 }
32
33 [SetUp]
34 public void SetUp() {
35 // Start the Evinced Engine
36 driver.EvStart();
37 }
38
39 [TearDown]
40 public void TearDown() {
41 // Stop the Evinced Engine
42 IReport report = driver.EvStop();
43 EvincedSDK.EvSaveFile(TestContext.CurrentContext.Test.Name, report, FileFormat.HTML, driver);
44 }
45
46 [Test]
47 public void TutorialTest1() {
48 driver.Navigate().GoToUrl("https://demo.evinced.com");
49 Assert.That(driver.FindElement(By.CssSelector(Locators.SEARCH_BUTTON)).Displayed, Is.True);
50 }
51
52 [Test]
53 public void TutorialTest2() {
54 driver.Navigate().GoToUrl("https://demo.evinced.com");
55 driver.FindElement(By.CssSelector(Locators.HOUSE_DROPDOWN)).Click();
56 driver.FindElement(By.CssSelector(Locators.TENT_OPTION)).Click();
57 driver.FindElement(By.CssSelector(Locators.LOCATION_DROPDOWN)).Click();
58 driver.FindElement(By.CssSelector(Locators.CANADA_OPTION)).Click();
59 driver.FindElement(By.CssSelector(Locators.SEARCH_BUTTON)).Click();
60 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
61 wait.Until(ExpectedConditions.ElementExists(By.TagName("body")));
62 Assert.That(driver.FindElement(By.CssSelector(Locators.SEARCH_RESULTS)).Displayed, Is.True);
63 }
64 }
65}

Fail the test if critical issues are found

Here you can see a way of failing your test if critical accessibility issues are found using the Selenium C# SDK.

Using evAnalyze:

1IReport result = driver.EvAnalyze();
2
3List<Issue> criticalIssues = report.GetIssues()
4 .Where(issue => issue.Severity.Name == "Critical")
5 .ToList();
6
7Assert.That(criticalIssues, Is.Empty, "Critical issues found");

Using evStart/evStop:

1driver.EvStart();
2
3IReport report = driver.EvStop();
4
5List<Issue> criticalIssues = report.GetIssues()
6 .Where(issue => issue.Severity.Name == "Critical")
7 .ToList();
8
9Assert.That(criticalIssues, Is.Empty, "Critical issues found");

The criticalIssues array will contain all the critical issues found during the scan. If the array is not empty, the test will fail on the assertion.

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.