Archive

Archive for the ‘testing’ Category

Selenium RC with .Net 3.0

May 27th, 2008

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