Weve all had a web application that works in such a way that you are required to complete two or three steps in a workflow to get to the specific page youre currently developing. Its a pain to fill out all those required fields, some with complicated regular expression validations (e.g. credit card numbers, e-mail addresses, phone numbers, etc.). It sucks. You have automated acceptance tests, but right now, youre just exploring with some JavaScript or server code.

So what do you do? What is the normal answer to a boring, repetitious problem. Automate it baby! Its not that hard at all.  In acceptance testing Im a big fan of not using the record-and-play type automation. I like seeing the detailed chatter between the browser and the server, but for this throw away situation its perfectly fine.

There are two tools that Ive used to record browser interactions; Selenium IDE and iMacros. Actually, now that I think about it, there are two more; ACT and VSTS Web Tests. Im going to ignore the last two because I dont find them very friendly and ill suited for what Im doing.

Between the two main options, Selenium IDE and iMacros, I use iMacros only because of its nicer integration with Firefox. I like the docked sidebar window with all the scripts Ive recorded as opposed to Selenium IDEs floating window and needing to load a test suite before being able to run a test. With that said, I do drive all automated acceptance tests with Selenium. The IDE is very useful, the API to interact with the browser has allows all the control I need.  I am very happy with it.

iMacros gives me one button to click to show my scripts.

image

Then a double click takes me where I need to go; simple, fast, efficient.

Recording the scripts are just as easy; click record, use the browser, stop and save.

image

iMacro does have the assertions that Selenium IDE has, but in this scenario, I dont care. I dont want to run any assertions, I just want to get where Im going. iMacros has a few other useful scenarios in our organization:

  • Quick smoke test of problem areas
  • Pre compile pages after deploying website

These two scenarios are probably better served by Selenium and automated through our build server, but it is really simple to setup a script to do whatever you need it to do. Dont discount its power.

Im adding custom validation messages to all my data annotation validation attributes. Simple stuff right. I started off with this.

Then added a customer message.

Then moved that message to a resource file

The problem is the resource file says something like Less than 50. If I change that 50 on the attribute, someone has to remember to go to the resource file and change it there too. Not very DRY.

Luckily the default message formatting will allow us to embed some tokens in the error message.  All we need to do is change our message to Less than {1} and the message is formatted to Less than 50.or whatever the argument value might be.

I haven't found a good list of the parameters you pass, but {0} is the property name, and then I assume 1, 2, 3, etc are the parameters of the constructor in order.