dotnetco.de

Use Selenium for WebTests with Visual Studio

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)

  1. 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.
  2. Open Visual Studio and create a new Test Project. Or add a new Test Project to your existing solution (Add –> New Project –> Testproject)
  3. Add the following DLLs from the extracted Selenium drivers directory (see step 1):
      1. WebDriver
      2. WebDriver.Support
  4. Add the following imports to your Test.vb (or Test.cs of course) for easier usage:
    1. Imports OpenQA.Selenium
    2. Imports OpenQA.Selenium.Firefox
    3. Imports OpenQA.Selenium.Support.UI
  5. Start writing your tests

Leave a Comment