How to Configure Selenium RC for Use In C# NUnit Tests

When I set about integrating Selenium into my test suites, I found all the information I needed to do that with but had to hunt and peck through my google searches to find it.  So, as a point of reference, I figured I’d put what I needed to do all in one place:

Two main activities:

  1. Set up Selenium RC server in Windows
    • Download latest Java SE from and install
    • Create a folder named Selenium under your jdk or jre bin file (example: C:Program FilesJavajre1.6.0_05bin).
    • Download latest version of Selenium RC from and extract into your newly created folder
    • From the Command prompt run the following commands:
      • cd [your jdk/jre bin directory] (example: C:Program FilesJavajre1.6.0_05bin).
      • java -jar .Seleniumselenium-server.jar -interactive
      • If you see the following messages your Selenium server is alive and kickin’:
        Entering interactive mode… type Selenium commands here (e.g: cmd=open&1=http:/
  2. Place a reference to the ThoughtWorks.Selenium.Core.dll into your .NET test assembly
    • This
      can be found under the Selenium install directory (example: C:Program

Git ‘Er Done With Some Tests

Now, you’re up and ready to start writing NUnit tests using Selenium in C#.  By the way, you can record your tests using the Selenium IDE and export the tests to a number of languages, including C#:


Example Test Suite as Exported using the above:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
    public class NewTest
        private ISelenium selenium;
        private StringBuilder verificationErrors;
        public void SetupTest()
            selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://sparkystestserver:48/”);
        public void TeardownTest()
            catch (Exception)
                // Ignore errors if unable to close the browser
           Assert.AreEqual(“”, verificationErrors.ToString());

        public void TheNewTest()
            selenium.Type(“loginname, sparky);
            selenium.Type(“password”, “mooseButt);
            Assert.AreEqual(“burp”, selenium.GetValue(“burpField”));

Hope that helps!


[Originally posted on 2/3/2009 at]

This entry was posted in .NET, C#, Configuration, TDD, Tools, Unit Testing. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

11 Responses to How to Configure Selenium RC for Use In C# NUnit Tests

  1. Chris Taylor says:

    @jdn I wrote that after seeing the Monster Superbowl commercial ( I thought it was too funny to pass up. :D

  2. Igor Brejc says:

    Nice introduction. I would however recommend “hiding” the Selenium object behind a facade. Why? After using Selenium for more than a year now, we came to the conclusion that it’s better to create some standard usage patterns in a facade because there are quite a few “tricks” which are needed to make the tests run stably. By using facade we enforced the common usage policy and saved time when developing tests (we write them manually in C#, not using the IDE, since they are more flexible not so much sensitive to changes in the tested GUI).

    Here’s an example of a facade we used on one of our projects:

  3. moreno says:

    what do you mean by: Place a reference to the ThoughtWorks.Selenium.Core.dll into your .NET test assembly

  4. anitha says:

    hi,can any one tel me how to convert testresult.xml into html in selenium RC-nunit

  5. brian says:

    do you know a way around the “Suite export not implemented for the cs-rc formatter” when trying to export a suite for c#?

  6. paradoxy says:

    hi all,
    Can anybody tell whts wrong with my code.
    i am using SeleniumRC1.0-beta-2 (selenium-dotnet-client-driver is 1.0.1). i want to run my automated test cases with Nunit 2.5.3.

    but it always give error.
    System.NullReferenceException : Object reference not set to an instance of an object
    at command

    thanks in advance

  7. Joshua Roudney says:

    lol. Get ‘er done! :D

    Good stuff. thanks for the information.

    I tried this: but not sure if it will help me that much.

  8. Robert says:

    I would suggest using Sauce RC, it is a nice GUI for Selenium RC

  9. Tibor says:


    You can find a solution for the “Suite export not implemented for the cs-rc formatter” Selenium IDE problem here: