Monday, 12 November 2007

WatiN Testing Pattern

In my latest project I am utilising WatiN to perform my website testing. This is not the first time I have used it in a project but it is the largest test project I've had to create and I've come across a couple of challenges.

Early on I realised my code was becoming increasingly difficult to manage and well rather messy due to all the control find declarations that existed within my tests. So I decided to see if anyone had implemented a nice pattern for WatiN tests that they could recommend. And low and behold I came across a couple and I have included them as references as the bottom of this blog. There are slight variations for both and undoubtedly you will vary your own to suit the situation you are working with but the underlying principals are the same.

First of all we create a page class for every page of our website. This page class is going to contain all the controls that we need to access on our page. The page class is going to inherit from the IE object and instantiates itself using the correct url. Let's look at an example





public class BaseModelPage : IE
{
public const string PreConfiguredModelURL = "/BaseModel.aspx";

public BaseModelPage() : base (SharePointSiteFixture.Site.Url + PreConfiguredModelURL){}

public Button AddToQuoteButton
{
get{ return Button(Find.ById(new Regex("AddToRequestButton"))); }
}

public Button EditSpecButton
{
get{ return Button(Find.ById(new Regex("EditSpecButton"))); }
}
}

From here its a matter of removing all the control find code you had in your tests, reference the new page class and now our tests are clean, easy to read and is a true representation of what we're testing.

So here is what it looks like after the cleanup




[SetUp]]
public void SetUp()
{
page = new BaseModelPage();
}

[Test]
public void AddQuoteAndEditSpecButtonsAreHidden()
{
Assert.That(!page.AddToQuoteButton.Exists);
Assert.That(!page.EditSpecButton.Exists);
}

We can also abstract out common scenarios or workflows out to the classes also. For example if there are some textfields we need to fill out multiple times to cover off a couple of test scenarios then we'll pull this code into a method in our page class and simply reference it from our test. Again, our tests are becoming more clean and simple. Lets look at another test that calls one of these methods.







[Test]
public void SubmittingValuesHidesConfigureFormShowsButtons()
{
page.SubmitValues();

Assert.That(!page.ConfigureForm.Exists);
Assert.That(page.AddToQuoteButton.Exists);
Assert.That(page.EditSpecButton.Exists);
}


Another thing we can do is extend our page classes further to handle moving between pages. This is useful when you have a transactional website and you need to test page sequence. In this scenario we add another constructor which accepts an IE instance. Then we can call this constructor from another page class in order to return the new page.





public QuoteRequestPage(IE instance): base(instance.Uri){}


internal QuoteRequestPage GoToQuoteRequestPage()
{
RequestQuoteButton.Click();
return new QuoteRequestPage(this);
}



So that pretty much sums it up. I certainly recommend following a pattern like this as the maintainability of your code is greatly increased and your tests become clean and readable.

Ref1 - James Avery
Ref2 - Richard Griffin

Monday, 15 October 2007

EPiServer announces new EMVP program

Mikael Runhem has announced on his research blog the introduction of the new EMVP - The EPiServer Most Valued Professional Program.

The requirements to become an EMVP are:
  • Very high skills in EPiServer solution development.
  • To be able to leverage their personal expertise to other developers in blogs and sample code.
  • To have witten at least one high-class technical blog article about EPiServer with top ratings.
  • You also need to be invited by at least three EPiServer staff members
And to maintain EMVP status you need to publish at least one high-class technical blog article about EPiServer at the official EMVP blog with top ratings every 60 days.

This is a very exciting opportunity and I am happy to see EPiServer bringing in a program like this. For more information about the benefits check out the blog here - Mikes Blog

Friday, 12 October 2007

Lorem Ipsum Generator

I use this little tool all the time and thought I should share it with the rest of you.

It's a generator for Lorem Ipsum dummy text http://www.lipsum.com/

Thursday, 11 October 2007

CSSVista Tool

A friend at work put me on to this very cool free tool called CSSVista. It allows you to edit css against a live site and see the results in IE and Firefox simultaneously.

http://litmusapp.com/cssvista

It's a pretty basic tool, you make some changes to your css on the left and it displays on the right (no html changes available) however if you're like me, you no doubt have many occasion where you just can't seem to get your css to do what you want and this tool will allow you to play around till you get it right.

You can also disable css & images in one go to see the affect in both browsers, do some resolution resizing and outline elements.

Wednesday, 10 October 2007

EPiServer CMS 5 Released

The much anticipated EPiServer CMS 5 was released in september and I for one am very excited about working with this new version. We have two new projects coming up at Intergen so look out for some interesting posts as I learn the ins and outs of this new version.

For download details: Download EPiServer CMS

Thursday, 19 July 2007

TFS and Fiddler

If you are having problems with TFS and you use Fiddler then check out this post detailing the errors TFS encounters when Fiddler is running.

*Thanks to Duncan for the info

Friday, 6 July 2007

EPiServer CMS 5 RC3 Released

The next release candidate for EPiServer CMS has just been released.

You can download RC3 from here:

http://www.episerver.com/en/EPiServer_Knowledge_Center/Download2/EPiServer-CMS-5---RC3/

Alternatively, EPiServer have provided two Virtual Image downloads;

Windows Vista with EPiServer CMS 5 RC3 (SDK installation) and Visual Studio 2005 and
Windows 2003 Server with EPiServer CMS 5 RC3 (manager installation)

You can register for both of these downloads here:

http://www.episerver.com/en/EPiServer_Knowledge_Center/Download2/EPiServer-CMS-5---RC3/EPiServer-CMS-5-RC3---Virtual-PC-Image/