Friday 14 January 2011

Acceptance Tests, Fluent Interfaces and a DSL

Lately ive been doing quite a lot of acceptance testing. We did give some BDD frameworks a try especially SpecFlow, but were left with a feeling that it was too complex for the benifits that it gave, was too inflexable and in the long run could turn into a bit of a mess. well that was the evaluation of the team, im sure there are good ways of doing it that is valuble but we decided not to go with a framework.

So i came up with a DSL that gives the developer a simple 'Given When Then' syntax that im quite pleased with, it allows for the most readable / maintainable acceptance test ive seen to date.

A small acceptance test follows as an example:

using NUnit.Framework;
using OpenQA.Selenium;
using AcceptanceTests.Domain;

namespace AcceptanceTests.Fixtures
{
    [TestFixture]
    public class TagTests : BaseTestFixture
    {
        [Test]
        public void ThisAndThatShouldDoSomeThings()
        {
            var resultsPage = Page.SiteABC.ResultsPage;
            given.WeAreOnThePage(resultsPage);

            when.I.Click.TheElement(By.LinkText("civil-engineering"));

            then.TheUrlShouldBe(Page.SiteABC.Article("civil-engineering"))
                .And.TheTitleShouldBe("civil-engineering articles in ABC example page");
            then.TheElement(By.ClassName("tag-wrapper")).ContainsTheText("Articles with the Tag:\r\ncivil engineering");

            when.I.Type("london").Into(By.Id("txtLocation"))
                .And.I.Click.TheElement(By.LinkText("search"));

            then ..... (You get the idea)
        }
    }
}

The base class gives the test fixtures access to the Given When Then classes similar to this:

public class BaseTestFixture
{
    protected Given given;
    protected When when;
    protected Then then;

    [TestFixtureSetUp]
    public void SetUp()
    {
        given = new Given();
        when = new When();
        then = new Then();
    }
}

The actual Given When Then classes delegate the actions to webdriver in the following manner:


public class Given
{
    private readonly WebDriver webDriver;

    public Given()
    {
        webDriver = WebDriver.GetCurrent();
    }

    public Given And
    {
        get { return this; }
    }

    public Given WeAreOnThePage(Page page)
    {
        webDriver.Driver.Navigate().GoToUrl(page.Url);
        return this;
    }
}


public class When
{
    private readonly WebDriver webDriver;

    public When()
    {
        this.webDriver = WebDriver.GetCurrent();
    }

    public When And
    {
        get { return this; }
    }

    public When I
    {
        get {return this; }
    }

    public IAction Click
    {
        get { return new Click(this); }
    }

    public TypeText Type(string text)
    {
        return new TypeText(text);
    }
}


By writing the step classes like this we can write the tests in a fluent style, making for very readable. This is important as it enables none technical (business) people to read / understand the tests and have input on the creation of the tests, although i admit it still does not really enable them to write them, as you do need to know c# and visual studio, but in my experience they never write them anyway (especially on the contact im on), its technical people who write the automated acceptance tests.

All in all im quite pleased who the suite of tests is progressing and how the DSL has evolved.

Thursday 6 January 2011

LauncherPro has expired. 403 forbidden. Phone is locked out...

Ive been using LauncherPro for a couple of months now, its a nice homescreen replacement on the android phone, actually i really liked it.

But this morning when i turned my phone on i got the error :-

"This version of LauncherPro has expired. Please goto http://www.launcherpro.com/ to get the latest version."

Then my web browser automatically opened so i could get it but i had a problem, i had no internet connection, no wifi, and no mobile connection.... arg.. Basically my phone was now a brick, well i could receive calls, but there was no way to access anything else as every time i hit the home key it would redirect to the internet...

Then later on in the morning i went into london and got a connection on 3G but then i got a 403 forbidden page.... double arg, whats going on this is so shoddy, so i still cant use my phone.

Only after getting to a PC with a decent internet connection did i managed to find a couple of solutions, the first was to download an app installer onto the pc and do a remote install of the new version of launcherPro, i didnt like this, it sounded too complex and i wanted rid of it not the latest version.

Then i found the following solution
browse to - http://bubiloop.com/download/org.adw.launcher
this should open the market (app store)
then search for launcherPro and finally update or uninstall.

I recommend un-installing, seams like this is a rather shoddy product if it locks out your phone like this. even if the actual software does everything else well i dont think this sort of error is in any way acceptabe in any software ever, locking you out of your device, laptop, PC whatever it is, is just wrong, i appreciate the developers might want to force people to upgrade all the time, but this is just not on, i dont know i just cant warn you folks enough, i woudnt trust this app.

morel of the story, dont use apps from random developers on major bits of your device, the home screen is quite major, if that dont work your stuffed.