Selenium RC Tutorial
From DojoWiki
Selenium RC
Download the Selenium RC package (from http://www.openqa.org/selenium-rc/download.action)
Extract the zip file.
Change directories to selenium-remote-control-0.9.0/server
From a command line execute
java -jar selenium-server.jar -interactive
Execute the following command from the interactive prompt (notice that it's using Internet Explorer; you can replace *iexplore with *firefox, but I had troubles with Firefox 2.0.0.1)
cmd=getNewBrowserSession&1=*iexplore&2=http://pghcodingdojo.org
You'll have seen a Browser window open. Now, type
cmd=open&1=http://pghcodingdojo.org
This will cause PghCodingDojo to appear in the previously opened browser session.
Type 'exit' to close the interactive session (and the browser window).
| We ran into a JVM BindException when trying to run the Selenium RC server while the Selenium IDE was running. This might not be the cause of the problem, but after shutting down the IDE and rebooting the machine, everything was fine. |
Unit Testing
For NUnit tests to work from NAnt using .Net 2.0, I had to use NUnit 2.2.7 and NAnt 0.85. Maybe there are work-arounds that allow a more recent version, but I didn't find any information after a cursory glance.
using System;
using NUnit.Framework; //reference C:\NUnit-2.2.7\bin
using Selenium; //reference C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll
namespace ConsoleApplication1
{
[TestFixture]
public class TestPghCodingDojo
{
private ISelenium selenium;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "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("30000");
Assert.IsTrue(selenium.IsTextPresent("www.openqa.org"));
Assert.AreEqual("Selenium OpenQA - Google Search", selenium.GetTitle());
}
}
}
Build File
<project name="SeleniumDotNet" default="test" basedir=".">
<property name="dir.output" value=".\bin"/>
<target name="clean" >
<delete dir="${dir.output}" failonerror="false" />
<mkdir dir="${dir.output}" />
<copy file="C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll" todir="${dir.output}" />
</target>
<target name="compile" depends="clean" >
<echo>Starting the build</echo>
<csc target="exe" output="${dir.output}\SeleniumDotNetTest.exe" debug="true">
<sources>
<include name="**/*.cs" />
</sources>
<references>
<include name="C:\NUnit-2.2.7\bin\nunit.framework.dll" />
<include name="C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll" />
</references>
</csc>
</target>
<target name="test" depends="compile" >
<nunit2>
<formatter type="Plain" />
<test assemblyname="${dir.output}\SeleniumDotNetTest.exe" >
<assemblies>
<include name="C:\NUnit-2.2.7\bin\nunit.framework.dll" />
<include name="C:\selenium-remote-control-0.9.0\dotnet\ThoughtWorks.Selenium.Core.dll" />
</assemblies>
</test>
</nunit2>
</target>
</project>
