Friday, January 23, 2009

Selenium Rc

I was using selenium rc and ruby a few months back.
Today when I tried using it, there are a lot of changes and there is no documentation.

Let me go through the differences between old and new.

Old

Download selenium remote control. It is a zip file. Unzip the file.
Now you will find the selenium server ( a jar file which u have to run from the command prompt) and the selenium client for ruby ( a driver file in the respective language, ie for ruby, u may expect selenium.rb)


Just copy selenium.rb to the project . In Netbeans IDE, u have to right click project, select properties, add to project ( jar or folder) and select the appropriate client driver.

New
In the ruby client folder, no selenium.rb exists. A doc folder is present which asks us to install the selenium gem.

Great, now it is a gem, but what am i supposed to do after that. I installed the gem.
When i run the ruby tests, a lot of errors come up. When i google for these errors, no help comes up.

Dot net to the rescue

I created a "test project" in visual studio 2008. Added the references, (by right clicking references and selecting browse -> selecting all the dlls inside the dot net client driver folder (inside remote control) ) and then copy pasted the code from selenium ide. Wonder of wonders! it works!!

From the code window, here is a sample test which verifies some basic test on the application ui.

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 verificationErrorsa;

[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://buytickets.thetrainline.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}

[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("/");
try
{
Assert.IsTrue(selenium.IsTextPresent("Buy train tickets"));
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
}
selenium.Click("dnn_ctr24339_TissipGenericForm_LoginStatusAndRedirector.LoginStatus");
selenium.WaitForPageToLoad("30000");
try
{
Assert.IsTrue(selenium.IsTextPresent("Log in"));
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
}
selenium.Click("//a[@id='dnn_ctr24339_TissipGenericForm_LoginStatusAndRedirector.Home']/span");
selenium.WaitForPageToLoad("30000");
try
{
Assert.IsTrue(selenium.IsTextPresent("Buy train tickets"));
}
catch (AssertionException e)
{
verificationErrors.Append(e.Message);
}
}//end of new test




}
}

Wednesday, January 21, 2009

Trying to run selenium with ruby

I had run with selenium.rb
Now they have converted it into a gem. Have to figure out how to use gem (if possible) with netbeans.

The selenium remote control download contains different folders for each language. Previously the ruby folder contained selenium.rb

Now the ruby folder contains only documentation. No ruby files. The documentations says to install selenium gem.

I wil give it a try and update this blog