Archive for the 'Automation' Category
Running Functional Web Application Tests with Selenium

One of the best things any developer can do is to automate regular tasks as much as possible. On the quality control side, this includes running regular functional tests to check to make sure that everything still works exactly as it’s supposed to. Selenium is a project which lets developers write tests for browsers to “drive themselves”. This basically means you develop a script which selenium can then read and interpret into mouse clicks. Scripts can be written by hand, but it is usually easiest to start by having the Selenium IDE watch you click around and then use the script it generates as a starting point. The best part about this project is Seleneium-RC which lets you take the scripts and run them directly from .NET, Java, Ruby, PHP, and others. Having this capability also lets us integrate these scripts into unit testing, which we can run regularly with tools like CruiseControl.

For example, if I launch Firefox, and open up the Selenium IDE, and then open google and search for “Billy Bob Thorton”, then click pages 2,3,4, Next, and Back, Selenium IDE will look like this:

ss-1

We can then export this script to code. C#, for Example:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;namespace SeleniumTests
{
    [TestFixture]
    public class google
    {
        private ISelenium selenium;
        private StringBuilder verificationErrors;

        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://localhost:4444″);
            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 TheGoogleTest()
        {
            selenium.Open(“/”);
            selenium.Type(“q”, “billy bob thorton”);
            selenium.Click(“btnG”);
            selenium.WaitForPageToLoad(“30000″);
            selenium.Click(“link=2″);
            selenium.WaitForPageToLoad(“30000″);
            selenium.Click(“link=3″);
            selenium.Click(“link=4″);
            selenium.WaitForPageToLoad(“30000″);
            selenium.Click(“link=Next”);
            selenium.WaitForPageToLoad(“30000″);
            selenium.Click(“link=Previous”);
            selenium.WaitForPageToLoad(“30000″);
        }
    }
}

This code should be compiled to a Windows Library type, and run within an NUnit Test runner. There’s a few things you need to consider before straight up running this code:

  • Ensure that your selenium server is running on your localhost, or change the selenium constructor line to point to the correct network path.
  • Include the NUnit.Framework and NUnit.Core dll’s in your resource directory, and make sure they get copied to the output directory.

For the NUnit test runner, I would reccommend downloading testdriven.net- it allows you to easily right click within the method and then run the tests without having to worry about compiling, launching the NUnit test runner, and then opening up the DLL. The end result of this is a firefox browser is opened, and Selenium reproduces exactly what you did when you were controlling firefox.

More on integrating this test with CruiseControl soon…

Setting Up CruiseControl

Today I delved into the world of automation, in an attempt to try and refine and automate some of the process that happens around here. I have known about the existance of CruiseControl for well over a year now, but I haven’t had (or necessarily needed) the chance to use it. With the size of my development group growing larger on quite a regular basis, tools like this are going to become increasingly necessary.

What is Cruise Control?

Taken straight from their home page..

CruiseControl is a framework for a continuous build process. It includes, but is not limited to, plugins for email notification, Ant, and various source control tools. A web interface is provided to view the details of the current and previous builds.

This means we’ll be able to focus on bigger and better things, such as writing unit tests to improve the quality control of our code, automating deployments when it is time for our releases. (including database scripts that need to run, as well as the code)

Goals for this side project of mine include:

  • Improving the way we version our database changes
  • Bringing in regular use of unit testing into my group
  • Bringing in regular use of functional and performance testing

From what I understand, CruiseControl, along with other tools such as ANT and Selenium will allow us to achieve these objectives. What will be interesting is that I haven’t read anywhere on achievements with this specific to ColdFusion.

Automation with CruiseControl and ColdFusion

Today I delved into the world of automation, in an attempt to try and refine and automate some of the process that happens around here. I have known about the existance of CruiseControl for well over a year now, but I haven’t had (or necessarily needed) the chance to use it. With the size of my development group growing larger on quite a regular basis, tools like this are going to become increasingly necessary.

What is Cruise Control?

Taken straight from their home page..

CruiseControl is a framework for a continuous build process. It includes, but is not limited to, plugins for email notification, Ant, and various source control tools. A web interface is provided to view the details of the current and previous builds.

This means we’ll be able to focus on bigger and better things, such as writing unit tests to improve the quality control of our code, automating deployments when it is time for our releases. (including database scripts that need to run, as well as the code)

Goals for this side project of mine include:

  • Improving the way we version our database changes
  • Bringing in regular use of unit testing into my group
  • Bringing in regular use of functional and performance testing

From what I understand, CruiseControl, along with other tools such as ANT and Selenium will allow us to achieve these objectives. What will be interesting is that I haven’t read anywhere on achievements with this specific to ColdFusion.

This will be the first post in a series of many on this topic.