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()


Ett svar på “Start and stop Selenium Server with NUnit”

  1. Nice! I no longer work with ASP.Net but Selenium could be useful for my colleagues and ex-colleagues in Thailand. Thanks for the article.

Kommentarer kan inte lämnas på detta inlägg.