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:
- Set up Selenium RC server in Windows
- Download latest Java SE from http://java.sun.com/ 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 http://seleniumhq.org/download/ 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:/
/www.yahoo.com)
- 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
FilesJavajre1.6.0_05binSeleniumselenium-remote-control-1.0-beta-2selenium-dotnet-client-driver-1.0-beta-2ThoughtWorks.Selenium.Core.dll)
- This
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
{
[TestFixture]
public class NewTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://sparkystestserver:48/”);
selenium.Start();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual(“”, verificationErrors.ToString());}
[Test]
public void TheNewTest()
{
selenium.Open(“/Home”);
selenium.Type(“loginname“, “sparky“);
selenium.Type(“password”, “mooseButt“);
selenium.Click(“ctl00_MainContent_loginButton”);
Assert.AreEqual(“burp”, selenium.GetValue(“burpField”));
}
}
}
Hope that helps!
[Originally posted on 2/3/2009 at http://agilecruz.blogspot.com]
Post Footer automatically generated by Add Post Footer Plugin for wordpress.

MooseButt?
@jdn I wrote that after seeing the Monster Superbowl commercial (http://superbowlads.fanhouse.com/quarter3/Monster-Moose/2409762). I thought it was too funny to pass up.
Nice.
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: http://code.google.com/p/projectpilot/source/browse/trunk/Accipio/TestFramework/SeleniumTesterBase.cs
what do you mean by: Place a reference to the ThoughtWorks.Selenium.Core.dll into your .NET test assembly
hi,can any one tel me how to convert testresult.xml into html in selenium RC-nunit
do you know a way around the “Suite export not implemented for the cs-rc formatter” when trying to export a suite for c#?
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
selenium.SelectWindow(“null”);
thanks in advance
lol. Get ‘er done!
Good stuff. thanks for the information.
I tried this: http://www.youtube.com/watch?v=wzvZBv_Fekg&feature=youtube_gdata but not sure if it will help me that much.
I would suggest using Sauce RC, it is a nice GUI for Selenium RC
@brian
You can find a solution for the “Suite export not implemented for the cs-rc formatter” Selenium IDE problem here:
http://blog.wedoqa.com/2010/07/solution-for-selenium-ide-export-to-c-sharp-problem/