Thursday, September 10, 2009

Automatically start and stop SeleniumRC with NUnit

You can use NUnit and SeleniumRC to run automated functional tests of your website. This is a simple class that starts selenium at the beginning of a unit test suite and shuts it down when done.


using System.Diagnostics;
using System.Net;
using NUnit.Framework;

[SetUpFixture]
public class SeleniumRcSetup
{
private readonly Process SeleniumRC = new Process();
[SetUp]
public void StartSelniumRc()
{
const string pathRelativeToProjBinDebug = @"path to your selenium installation";
SeleniumRC.StartInfo.FileName = "java";
SeleniumRC.StartInfo.Arguments = string.Format("-jar {0}selenium-server.jar", pathRelativeToProjBinDebug);
SeleniumRC.Start();
}
[TearDown]
public void StopSeleniumRc()
{
var r = WebRequest.Create("http://localhost:4444/selenium-server/driver/?cmd=shutDown");
r.GetResponse();
SeleniumRC.WaitForExit(5000);
SeleniumRC.Close();
}
}

No comments:

Post a Comment