Last Updated on 2022-07-15 by James Croft

You’ve built your suite of automated Selenium UI tests, and now you want to automate how they’re run. Did you know that Azure DevOps pipeline agents have everything you need to get going? This article walks you through how to take your .NET Selenium UI test project and running them in a scheduled pipeline.

What you need to run Selenium UI tests on Azure DevOps

Before you start setting up your Azure DevOps pipeline, you’ll need a .NET Selenium UI test project.

If you’re new to the UI test journey, check out my ToDoer UI test example project on GitHub. The example showcases how to write maintainable UI tests using Selenium and the Legerity framework.

Creating a YAML pipeline for .NET test projects

To run your Selenium UI tests on Azure DevOps, you’ll need to create a YAML pipeline within your repository.

In this example, the pipeline is setup using a schedule trigger. It runs Tuesday through Saturday at midnight on each day. The purpose of this is to ensure that the UI tests don’t run during working hours, taking up valuable build time for pull requests.

In order to run your Selenium UI tests, you need to provide a web driver for the web browser you are running your tests against. There are multiple ways you can set and use the web driver with your .NET UI test project. The approach we are showing here is the most maintainable with minimal setup required.

Using the Azure DevOps installed web drivers

The recommended solution to running your Selenium UI tests on an Azure DevOps pipeline is to use the pre-installed web drivers on the hosted agent. The benefit to this approach is that the installed browser versions correspond with the installed driver version.

To configure your Selenium UI test project to use the web driver, you will need to provide a settings file. This settings file is read by your project to setup the tests. In the example above, we are using an appsettings.json file that provides the file path to the web driver.

Using the Microsoft.Extensions.Configuration NuGet package, you can import the JSON settings file and configure your Selenium driver as follows.

With your UI test project ready to run tests with path to a driver, you’ll want to ensure that your settings are setup during the Azure DevOps pipeline run. You can do that using this simple PowerShell script.

In the Azure DevOps YAML pipeline in the above section, lines 36 to 44 outline how you can use this script to update the settings with the preset variables for web browser drivers installed on the hosted agent. The preset variables are not in the Microsoft documentation. However, they include ChromeWebDriver (Google Chrome), IEWebDriver (Internet Explorer), and GeckoWebDriver (Firefox).

Running your Selenium UI tests in Azure DevOps

Now it is time to run your UI tests within Azure DevOps! With everything now setup, you can run your UI tests manually, or wait for the schedule trigger to run them for you.

Once the pipeline has run your UI tests, you’ll be able to view the results of the tests from the pipeline output.

Found this article useful?

Thank you for taking the time to read this article. I’m committing to sharing more of my knowledge through my blog and open-source projects! You’ll also catch me in casual conversation on Bluesky and LinkedIn too.

If you enjoy what you see, please consider subscribing to get a notification when new articles go live!


Discover more from James Croft

Subscribe to get the latest posts sent to your email.

James Croft

James is a senior software engineer at Microsoft with over 10 years experience designing and building large-scale, distributed, cloud-native systems. He's deeply experienced in C#, Python, and TypeScript, with specialization in AI agent architectures, retrieval-augmented generation (RAG), and production-grade Azure systems.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.