Over a million developers have joined DZone.

How to Run C# Selenium Tests With NUnit and Taurus

DZone's Guide to

How to Run C# Selenium Tests With NUnit and Taurus

We take a look at Taurus, an open source framework for performing continuous testing, especially as it pertains to running NUnit and Selenium tests done in C#!

· DevOps Zone ·
Free Resource

DevOps involves integrating development, testing, deployment and release cycles into a collaborative process. Learn more about the 4 steps to an effective DevSecOps infrastructure.

Are you a .NET developer who wants to utilize Open Source tools for continuous testing? No problem! Now, Taurus, an automation-friendly open source framework for Continuous Testing, can run NUnit C# scripts. Selenium C# users can now utilize the advantages of continuous testing and continuous integration.

This is possible now that Taurus 1.9.5 supports NUnit, through a dedicated executor. With NUnit (a unit-testing framework for all .Net languages) and Mono (an open source implementation of Microsoft's .NET Framework), orchestrated by Taurus, you can now easily build and execute C# Selenium scripts. Nuget and XBuild (Mono) compile the script into binaries, and then these binaries are run by Taurus through Mono. This whole process can be run through one YAML file! Then, you can integrate the test with Jenkins or another CI tool.

This blog post will show how to run a C# script through Taurus. The complete example is available at the Taurus GitHub Repository.

Here is the complete YAML file:

- module: shellexec
  - nuget restore SeleniumSuite/packages.config -SolutionDirectory .
  - xbuild /p:Configuration=Release SeleniumSuite.sln

- executor: selenium
  iterations: 10
script: SeleniumSuite/bin/Release/SeleniumSuite.dll  # assembly containing test suites  

 The first part tells Taurus to run external tools. This is done through the ShellExec module, which prepares Nuget and XBuild to compile the C# script. You can use this script part as-is if you download the example we provided from GitHub. Please note that using this Taurus ability requires Mono 4 and Nuget to be installed, and of course Taurus.

The second part tells Taurus to execute the binaries created in the first step by Mono and Nuget, for 10 times, from the path SeleniumSuite/bin/Release/SeleniumSuite.dll.

When running C# scripts, set the executor as Selenium. When doing so, the Selenium executor automatically detects the test types and runs them by using one of the test runners JUnit, NUnit, TestNG, Mocha, etc. You can configure the number of iterations according to your needs.

Now let’s take a look at the source code of our script. The C# script has four simple steps:

  1. Initialize – Creates a new ChromeDriver object.
  2. IndexPage – Browse to blazedemo.com and Assert page title.
  3. ReservePage – Browse to reservation page and Assert page title.
  4. AfterTest – Tear down ChromeDriver.
using System;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;

namespace SeleniumSuite {
 public class Test {
  IWebDriver driver = null;

  public void Initialize() {
   driver = new ChromeDriver();

  public void IndexPage() {
   Assert.AreEqual(driver.Title, "BlazeDemo");

  public void ReservePage() {
   Assert.AreEqual(driver.Title, "BlazeDemo - reserve");

  public void AfterTest() {
   if (this.driver != null)

 Change the C# script according to your needs. Make sure you save it in the Selenium Suite folder (in this example).

That’s it! You can now run your tests with Taurus. Once your tests are run through Taurus, they can be automated and integrated with Jenkins or any other CI tool, like Bamboo or TeamCity. Then they can be run with all of your other tests, including load tests, enabling you to shift left while developing.

Learn more Taurus from this free webinar “Using Taurus to Automate JMeter and Selenium Tests“.

Read the 4-part DevOps testing eBook to learn how to detect problems earlier in your DevOps testing processes.

ci ,testing ,continuous testing ,selenium ,c# ,nunit ,devops

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}