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.
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:
- SamplePageTests.cs: C# test file that opens SamplePage.html in a browser with Selenium and runs accessibility scans against it
- azure-pipelines.yml: Azure Pipelines config file that sets up our Continuous Integration and Pull Request builds
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!
-
Install the .NET Core SDK
-
Install the stable version of Chrome
-
Install the stable version of Firefox
-
Clone this sample repository
git clone https://github.com/microsoft/axe-pipelines-samples
-
Run the tests
Filter to only run passing tests:
cd ./axe-pipelines-samples/csharp-selenium-webdriver-sample dotnet test --filter TestCategory!=IntentionallyFailsAsAnExample
Run all tests (both passing and failing):
cd ./axe-pipelines-samples/csharp-selenium-webdriver-sample dotnet test
The accessibility tests run as part of the dotnet test
build step:
The test pass/fail results display in the Tests tab of the build logs: