Skip to content

Latest commit

 

History

History

csharp-selenium-webdriver-sample

CSharpSeleniumWebdriverSample

This sample demonstrates how you might set up a C# Project with an Azure Pipelines build that runs end to end accessibility tests in a browser.

Getting Started

The individual files in the sample contain comments that explain the important parts of each file in context.

Some good places to start reading are:

Tools and libraries used

The key tools and libraries this sample demonstrates are:

  • Selenium.WebDriver, the .NET library for Selenium, a tool for automating interactions with different web browsers.
  • Selenium.Axe, a .NET library for running accessibility scans on web pages by using Selenium.WebDriver to run the axe-core accessibility scanning engine.
  • Azure Pipelines to run the tests in a CI build with every Pull Request.

This sample also uses a few other tools and libraries which are less important; if you use a different test framework or a different version of .NET, you can still follow along with most of the sample.

  • .NET Core to build/run the code.
    • None of the libraries or C# code in the sample are specific to .NET Core; if your project uses the full .NET Framework, you can still follow along with the sample!
  • MSTest as our test framework.
    • None of the other libraries we're using require this particular framework; you can still follow along with the sample using NUnit, xUnit, or any other test framework you like.
  • Chrome (with Selenium.WebDriver.ChromeDriver) and Firefox (with Selenium.WebDriver.GeckoDriver) as our test browsers
    • Selenium supports many different browsers and operating systems; use whichever combination is most important for your product!
  • FluentAssertions to write test assertions
    • We like FluentAssertions because it gives great error messages out-of-the-box with Selenium.Axe. But you can still follow the rest of the sample if you prefer a different assertion style!

See it in action on your local machine

  1. Install the .NET Core SDK

  2. Install the stable version of Chrome

  3. Install the stable version of Firefox

  4. Clone this sample repository

    git clone https://github.com/microsoft/axe-pipelines-samples
  5. Run the tests

    Filter to only run passing tests:

    cd ./axe-pipelines-samples/csharp-selenium-webdriver-sample
    dotnet test --filter TestCategory!=IntentionallyFailsAsAnExample

    Screenshot of 'dotnet test' command showing all tests passing

    Run all tests (both passing and failing):

    cd ./axe-pipelines-samples/csharp-selenium-webdriver-sample
    dotnet test

    Screenshot of 'dotnet test' command showing some accessibility violations

See it in action in Azure Pipelines

  • Example build with failures: Azure Pipelines Build Status for failing example build
  • Example build without failures: Azure Pipelines Build Status for passing example build

The accessibility tests run as part of the dotnet test build step:

Screenshot of "dotnet test" build logs in sample build

The test pass/fail results display in the Tests tab of the build logs:

Screenshot of Tests tab in sample build