How to Run C# Selenium Tests with NUnit and Taurus
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:
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:
- Initialize – Creates a new ChromeDriver object.
- IndexPage – Browse to blazedemo.com and Assert page title
- ReservePage – Browse to reservation page and Assert page title
- AfterTest – Tear down ChromeDriver
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“.