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
- JDK 1.5, to run selenium rc server
- Visual Studio 2008 (obviously)
- Selenium RC, and
- Nunit
Steps
- Create a sample C# class library, say SeleniumSample
- 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
- Remove the non .Net Framework 2.0 references, namely Linq etc.
- Clean and Rebuild the solution, fix the using errors
- 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()); } } }
- Rebuild the solution
- Now open Nunit-Gui, Program Files > Nunit X.Y.Z > Nunit Gui (.Net 2.0)
- Do File > Open Project and select the SeleniumSample.dll which should be in projects bin directory
- Now you should see the test class GoogleTest with GoogleSearch test case under it.
- Open an command window and cd to directory where you downloaded and extracted selenium rc
- cd to selenium-server-1.0-beta-1
- run java -jar selenium-server.jar, check that the server is running and listening on port 4444
- 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
- Feel free to add more test cases and then back in Nunit-gui do File > Reload Project and re-run the tests
Happy Testing
Nice website. I look forward to reading your articles.
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
@Test123test
for ruby you can see the screencast http://railscasts.com/episodes/116-selenium from awesome Ryan Bates