Home > .net, testing > Selenium RC with .Net 3.0

Selenium RC with .Net 3.0

Seems like a sidetrack from my work. I was helping out my wife in setting up Selenium-RC with C# client driver. However the documentation assumes everyone is using .Net 2.0. So I wanted to share what I have done to achieve the same with C# 3.0. Here are the steps,

Requirements

  1. JDK 1.5, to run selenium rc server
  2. Visual Studio 2008 (obviously)
  3. Selenium RC, and
  4. Nunit

Steps

  1. Create a sample C# class library, say SeleniumSample
  2. Change the build target framework to .Net 2.0. To do that go to Project > SeleniumSample Properties and select .Net Framework 2.0 under Target Framework drop down
  3. Remove the non .Net Framework 2.0 references, namely Linq etc.
  4. Clean and Rebuild the solution, fix the using errors
  5. Add the following class (GoogleTest) to test selenium
    using System;
    using NUnit.Framework;
    using Selenium;
    
    namespace SeleniumSample
    {
        [TestFixture]
    	public class GoogleTest
    	{
    		private ISelenium selenium;
    
    		[SetUp]
    		public void SetupTest()
    		{
    			selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com");
    			selenium.Start();
    		}
    
    		[TearDown]
    		public void TeardownTest()
    		{
    			selenium.Stop();
    		}
    
    		[Test]
    		public void GoogleSearch()
    		{
    			selenium.Open("http://www.google.com/webhp");
    			Assert.AreEqual("Google", selenium.GetTitle());
    			selenium.Type("q", "Selenium OpenQA");
    			Assert.AreEqual("Selenium OpenQA", selenium.GetValue("q"));
    			selenium.Click("btnG");
    			selenium.WaitForPageToLoad("5000");
    			Assert.IsTrue(selenium.IsTextPresent("www.openqa.org"));
    			Assert.AreEqual("Selenium OpenQA - Google Search", selenium.GetTitle());
    		}
    	}
    }
    
  6. Rebuild the solution
  7. Now open Nunit-Gui, Program Files > Nunit X.Y.Z > Nunit Gui (.Net 2.0)
  8. Do File > Open Project and select the SeleniumSample.dll which should be in projects bin directory
  9. Now you should see the test class GoogleTest with GoogleSearch test case under it.
  10. Open an command window and cd to directory where you downloaded and extracted selenium rc
  11. cd to selenium-server-1.0-beta-1
  12. run java -jar selenium-server.jar, check that the server is running and listening on port 4444
  13. Now back to Nunit-GUI, start the tests by clicking on run. This should launch internet explorer and run the steps/checks mentioned in the above code
  14. Feel free to add more test cases and then back in Nunit-gui do File > Reload Project and re-run the tests

Happy Testing

.net, testing

  1. May 28th, 2008 at 13:19 | #1

    Nice website. I look forward to reading your articles.

  2. Test123test
    December 5th, 2008 at 08:49 | #2

    Hi

    I am searching for the website which can help me for setting up Selenium Rc with Ruby client( which gives complete and brief information), If you have any idea on this kindly revert me back to tester123tester@gmail.com

    Regards
    Test

  3. kiran
    December 17th, 2008 at 16:01 | #3

    @Test123test
    for ruby you can see the screencast http://railscasts.com/episodes/116-selenium from awesome Ryan Bates

  4. Nitin
    March 3rd, 2009 at 05:09 | #4

    i need to study the functions used in selenium to understand the selenium with c#, can u provide ny tutorial for that,
    i m finding functions with perl but not with c#..

  5. Nitin
    March 3rd, 2009 at 05:10 | #5

    i need to study the functions used in selenium to understand the selenium with c#, can u provide ny tutorial for that,
    i m finding functions with perl but not with c#..
    contact me: nownitin@gmail.com

  6. kiran
    March 3rd, 2009 at 13:05 | #6

    @Nitin
    Best way to learn selenium is to use Selenium IDE http://seleniumhq.org/projects/ide/. Using that you can record your actions and this IDE can generate equivalent C# code for you. Look through the documentation.

  7. Paul Harley
    August 4th, 2009 at 18:13 | #7

    Thank you very much. Your thoughtful posting of this information saved me much painful experimentation. I had to hunt for a few minutes to find the needed reference assemblies for using Selenium and NUnit.Framework, so here they are just in case it’s helpful to anyone else…

    Selenium : selenium-remote-control-1.0.1-dist\selenium-remote-control-1.0.1\selenium-dotnet-client-driver-1.0.1\ThoughtWorks.Selenium.Core.dll

    NUnit.Framework : C:\Program Files\NUnit 2.5.1\bin\net-2.0\framework\nunit.framework.dll

  8. daya
    August 26th, 2009 at 13:38 | #8

    Can any body help me how to convert the generated xml result file into html report.
    I am using NUNIT for running the selinium scripts.

  1. No trackbacks yet.