Los Techies : Blogs about software and anything tech!

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 http://java.sun.com/ and install
    • Create a folder named Selenium under your jdk or jre bin file (example: C:\Program Files\Java\jre1.6.0_05\bin\).
    • 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 Files\Java\jre1.6.0_05\bin\).
      • java -jar .\Selenium\selenium-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)
  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 Files\Java\jre1.6.0_05\bin\Selenium\selenium-remote-control-1.0-beta-2\selenium-dotnet-client-driver-1.0-beta-2\ThoughtWorks.Selenium.Core.dll)

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#:

SeleniumExport

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]

Kick It on DotNetKicks.com
Posted Feb 10 2009, 07:24 AM by Chris Taylor

Comments

jdn wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 02-10-2009 10:55 AM

MooseButt?

DotNetShoutout wrote How to Configure Selenium RC for Use In C# NUnit Tests - Chris Taylor's Blog -
on 02-10-2009 11:14 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Chris Taylor wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 02-10-2009 11:44 AM

@jdn I wrote that after seeing the Monster Superbowl commercial (superbowlads.fanhouse.com/.../2409762).  I thought it was too funny to pass up.  :D

jdn wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 02-10-2009 2:49 PM

Nice.

Igor Brejc wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 02-18-2009 2:06 PM

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: code.google.com/.../SeleniumTesterBase.cs

moreno wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 10-01-2009 2:41 PM

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

anitha wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 11-23-2009 1:24 AM

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

ASP.NET MVC Archived Buzz, Page 1 wrote ASP.NET MVC Archived Buzz, Page 1
on 11-25-2009 1:13 AM

Pingback from  ASP.NET MVC Archived Buzz, Page 1

brian wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 01-18-2010 5:43 PM

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

paradoxy wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 02-05-2010 1:09 AM

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

Joshua Roudney wrote re: How to Configure Selenium RC for Use In C# NUnit Tests
on 02-06-2010 5:08 PM

lol.  Get 'er done! :D  

Good stuff.  thanks for the information.  

I tried this: www.youtube.com/watch but not sure if it will help me that much.  

Selenium for vb.net | Things of the web wrote Selenium for vb.net | Things of the web
on 03-04-2010 5:49 PM

Pingback from  Selenium for vb.net | Things of the web

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems