Software to help you build a better store
SEARCH
May 16, 2006

Unit Testing Anthem with Selenium

Saw this post today, so I installed Selenium Remote Control and wrote these unit tests in about an hour. Nice!

using System;

using System.Configuration;

using NUnit.Framework;

using Selenium;

 

namespace Anthem_Tests

{

    [TestFixture]

    public class ButtonsAndLabels

    {

        DefaultSelenium selenium;

 

        [SetUp]

        public void SetUp()

        {

            selenium = new DefaultSelenium(

                ConfigurationManager.AppSettings["selenium.serverHost"],

                int.Parse(ConfigurationManager.AppSettings["selenium.serverPort"]),

                ConfigurationManager.AppSettings["selenium.browserString"],

                ConfigurationManager.AppSettings["selenium.browserURL"]

            );

            selenium.Start();

        }

 

        [TearDown]

        public void TearDown()

        {

            selenium.Stop();

        }

 

        [Test]

        public void CheckTheTitle()

        {

            selenium.Open("/Anthem-Examples-2005/ButtonsAndLabels.aspx");

            Assert.AreEqual(

                "ButtonsAndLabels",

                selenium.GetTitle(),

                "Check the title of the browser"

            );

        }

 

        [Test]

        public void ClickButtonAndCheckResponse()

        {

            selenium.Open("/Anthem-Examples-2005/ButtonsAndLabels.aspx");

            Assert.AreEqual(

                string.Empty,

                selenium.GetText("label"),

                "Verify that the label is empty."

            );

            string now1 = DateTime.Now.ToString();

            selenium.Click("button");

            string now2 = selenium.GetText("label");

            Assert.AreEqual(

                now1.Substring(0, 10),

                now2.Substring(0, 10),

                "Check that the date matches."

            );

        }

    }

}

This site looks much better in a browser that supports current web standards, but it is accessible to any browser. Download one now This link is to a third party web site which will open in a new window

Some parts of this site will not work effectively on this older browser.
Please consider updating your browser This link is to a third party web site which will open in a new window

SSL