I am conducting a spike for a couple of evening on the way we might automate our functional tests at Jobping.

I started with Watin and MSpec and the MSpec excellent plugin for ReSharper 5 which gives the following great outputs directly from Visual Studio

4602612162_a3a0e50945_o[1]

After some discussion with Alexander Groß (Thanks for your help ;) to gain some knowhow about MSpec I finally managed to have some automated functional tests running like this:

[Subject(“Search”)]
public class when_user_search_using_keywords : WebBaseSpec
{
const string Keywords = “C#”;
static SearchScreenObject searchScreenObject;
static ResultScreenObject resultScreenObject;

<span style="color:#2b91af">Establish</span> context = () =>  
    {  
        searchScreenObject = <span style="color:#0000ff">new</span> <span style="color:#2b91af">SearchScreenObject</span>(Browser);  
        resultScreenObject = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ResultScreenObject</span>(Browser);  
    };  

<span style="color:#2b91af">Because</span> of = () => searchScreenObject.Search(Keywords);  

<span style="color:#2b91af">It</span> should_direct_user_to_results_page = () =>   
    Browser.Uri.Route().ShouldMapTo<<span style="color:#2b91af">HomeController</span>>(x =>   
        x.Search(<span style="color:#a31515">"AU"</span>, <span style="color:#0000ff">new</span> <span style="color:#2b91af">SearchRequest</span> { Keywords = Keywords}));  

<span style="color:#2b91af">It</span> should_fill_search_textbox_with_keywords_entered_by_user = () =>   
    resultScreenObject.SearchText.Text.ShouldEqual(Keywords);  

}

I think it talks for itself!

Remarks to note:

  1. SearchScreenObject and ResultScreenObject represents an isolation layer between my tests and objects that are present on the web pages. This helps in the case you decide to change an id of an element
  2. I use MvcContrib ShouldMap to ensure that the browser navigates to the correct destination page which add another isolation layer and let me change my URL without impacting my tests

It is really funny to see the browser opening and clicking automatically, typing texts…

Hopefully, at the end this will replace our smoke test document and quite some time of manual testing.