Leveraging Selenium, NUnit and C# for UI tests - Part 1

Starting today, we initiate a series of articles dedicated to conducting UI tests with Selenium and C#. Our aim is to provide an introduction to this often overlooked topic and demonstrate how it can save a considerable amount of time when executed correctly.

Test-driven development (TDD) is currently widely embraced and is acknowledged for enhancing productivity by automating arduous tests and preventing regression issues. However, tests are typically carried out solely on backend servers and occasionally on the frontend to verify simple features. On the other hand, genuine UI tests are manually conducted by a QA team (or often disregarded), and this manual process can consume a significant amount of time, impeding development and deployment speed. An interesting point to note is that Gerard Meszaros, in his renowned book "xUnit Test Patterns" (which spans 900 pages), only briefly address this subject.

We must acknowledge that conducting UI tests is a challenging task: faithfully reproducing human behavior on a screen becomes particularly difficult, especially considering the myriad possible configurations (Firefox with Linux, Edge with Windows 10, and so forth). While it may not be feasible to simulate all these configurations, we can still check basic conditions when a deployment is completed just to ensure that no regression has been introduced. For example, we can verify that a button is still present and clickable or that a form is correctly filled when submitted.

Important

This doesn't involve checking the precise arrangement of elements or the correctness of the layout. Automating such checks is a highly sophisticated problem that likely requires a significant amount of artificial intelligence.

In this series of articles, we aim to offer a partial solution to this issue by utilizing Selenium and NUnit. We will demonstrate how it is relatively simple to automate some smoke tests to swiftly verify that the UI functions correctly after a deployment. Our approach will be practical in nature: we will quickly introduce Selenium features, guide on setting up an environment with Visual Studio and C#, and provide a few practical examples.

Without further ado and as usual, let's begin with a quick overview of Selenium. Continue here.