In previous tutorials you would have seen how to create your Selenium Scripts in Selenese and then run them using Selenium Remote Control. You would have noticed how good Selenium Remote Control is for running tests against your web application using any browser without having to move your test scripts onto the webserver.
In this tutorial we are going to learn how to create your first test script using the language that I most commonly use, c#. Since most languages are semantically the same, if you do not use c# it shouldn't be too difficult to translate the tutorial into your language of choice. You will to download NUnit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
[TestFixture]
public class
TheAutomatedTester
{
private
ISelenium selenium;
private
StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
`
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost");
selenium.Start();
verificationErrors = new StringBuilder();
}
[Test]
public void AutomatedTester_Test()
{
selenium.Open("/index.htm");
selenium.Click("buttonName");
selenium.WaitForPageToLoad("30000");
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{ // Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
If you would like to make your test data driven put all the code to pull the data in the SetUp.