Automated functional tests using Watin and MSpec
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
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:
public class when_user_search_using_keywords : WebBaseSpec
{
const string Keywords = “C#”;
static SearchScreenObject searchScreenObject;
static ResultScreenObject resultScreenObject;
Establish context = () =>
{
searchScreenObject = new SearchScreenObject(Browser);
resultScreenObject = new ResultScreenObject(Browser);
};
Because of = () => searchScreenObject.Search(Keywords);
It should_direct_user_to_results_page = () =>
Browser.Uri.Route().ShouldMapTo<HomeController>(x =>
x.Search(“AU”, new SearchRequest { Keywords = Keywords}));
It should_fill_search_textbox_with_keywords_entered_by_user = () =>
resultScreenObject.SearchText.Text.ShouldEqual(Keywords);
}
I think it talks for itself!
Remarks to note:
- 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
- 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.