Start and stop Selenium Server with NUnit

I want to have our Selenium tests to run automatically the same way as our other NUnit tests does. This means that I want to have the Selenium Server started automatically before running the test cases.

  1. I started by downloading the Selenium RC and unzipped it to C:SeleniumSelenium-RC
  2. I created a .NET project where I referenced the ThoughtWorks DLLs in C:SeleniumSelenium-RCselenium-dotnet-client-driver-1.0.1
  3. I added a new class to where I copied the Selenium getting started C# class
  4. I added my own TestFixtureSetup and a TestFixtureTeardown to this class. TestFixtureSetup launches the Selenium Server and TestFixtureTeardown closes it

Here is the class for starting the Selenium Server and the example Selenium test.

using System;
using System.Diagnostics;
using System.Text;
using NUnit.Framework;
using Selenium;

namespace Test.UI.Web.Selenium
	public class SeleniumGoogleTest
		private ISelenium selenium;
		private StringBuilder verificationErrors;

		private Process seleniumServer;
		private readonly ProcessStartInfo seleniumServerProcessStartInfo = new ProcessStartInfo("java", @"-jar C:SeleniumSelenium-RCselenium-server-1.0.1selenium-server.jar");

		public void TestFixtureSetup() {
			seleniumServer = Process.Start(seleniumServerProcessStartInfo);

		public void TestFixtureTearDown() {

		public void SetupTest()
			selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://localhost:4444");
			verificationErrors = new StringBuilder();

		public void TeardownTest()
			} catch (Exception)
				//Ignore errors if unable to close the browser
			Assert.AreEqual("", verificationErrors.ToString());

		public void OpenGoogleWebSite()


Running WatiN tests in SharpDevelop

I tried to run my WatiN tests in the test runner in SharpDevelop and got stuck on the following error:

System.Threading.ThreadStateException : The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

If you are running your tests with MBUnit you can add the following to your TestFixture:

[TestFixture(ApartmentState = ApartmentState.STA)]

But I couldn’t find any similar for NUnit. Instead I changed how SharpDevelop launches it’s tests. Click; Tools / Options / Tools / Unit Tests and deselect Run tests on separate thread. Run the tests again.

And I got the following error:

System.InvalidOperationException : Process has exited, so the requested information is not available.

I tried to disable Protected Mode in Internet Explorer and the tests ran fine.

How to dissable Protected Mode in IE
How to disable Protected Mode in IE