First step is to download the necessary software NUnit and WebDriver:
Download Nunit from and install it.

NUnit download

And download the newest Webdriver library from page

Selenium WebDriver

Open up a new Class Library Project in Visual Studio and add the downloaded Webdriver and NUnit library files to the project.

Add Reference

Add Reference

Add Reference

When all of this is done we can start to write some simple test code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using NUnit.Framework;
using OpenQA.Selenium.Firefox;

namespace ClassLibrary2
    public class UnitTest1

        IWebDriver driver;

        public void TestSetUp()
            // the same way we can setup webDriver to use other browsers
            driver = new FirefoxDriver();

            // set the timeout after page load to 30seconds
            driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));


        public void TestMethod1()


            Assert.AreEqual("WeDoQA", driver.Title);

        public void FixtureTearDown()
            // closes every window associated with this driver

This code will initialize Webdriver using a Firefox Driver, which means that Firefox will be used to run the test. And it will set the default timeout after a page load request. The timeout should be between 30-60 seconds, depending on your internet connection and on how much js/flash is used on the page.

The testMethod will only check if we are on the correct page by testing the page title. It is a good practice to check this before any other tests take place, this way you can spare some time during test debugging.

To test the code open NUnit. Click “Open Project” in the File menu, and choose the projects dll file. By default it can be found C:\Users\Username\Documents\Visual Studio 2010\Projects\ProjectName\Projectname\bin\Debug\ProjectName.dll
(Replace ProjectName with your project’s name :) )
Click Run, and if everything went fine you will get the following screen:


And voila the testbase is ready for creating some more advanced tests.

Posted By Tihomir Turzai

    3 Responses to “How to setup Selenium WebDriver with Visual Studio and NUnit”

  1. RON says:

    Thank you for the above article, It really helped me ..!

  2. poo says:

    Can we run this test on iphone real device.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>