Unit Tests in Visual Studio are great for testing backend functionality, but it does not help if you want to test websites. Searching around, there are several tools to fill this gap. My favorite is Selenium. It has a Firefox plugin for fast and easy web tests. And it has a WebDriver Version. Using the WebDriver is a powerful option. You could simulate (nearly) everything you do in a browser from your backend code by creating a unit test in C# or Visual Basic.net!
In current post I first want to summarize the steps to install and setup Selenium WebDriver version in Visual Studio.
So these steps are necessary to install Selenium WebDriver: (My favorite browser is Mozilla Firefox. Of course you could use any other browser (like Internet Explorer or Google Chrome) but for easier explanation I’ll just use Firefox here)
- Download the latest .net Selenium drivers from their Google Code Page. Current release is “selenium-dotnet-2.25.1.zip”. Extract the files to your hard disk.
- Open Visual Studio and create a new Test Project. Or add a new Test Project to your existing solution (Add –> New Project –> Testproject)
- Add the following DLLs from the extracted Selenium drivers directory (see step 1):
- Add the following imports to your Test.vb (or Test.cs of course) for easier usage:
- Imports OpenQA.Selenium
- Imports OpenQA.Selenium.Firefox
- Imports OpenQA.Selenium.Support.UI
- Start writing your tests