Using Ruby and Automator to partially automate your exploratory testing on OSX

Some time ago I talked about linking automated scripts to keyboard shortcuts to generate test data on the fly. Since then, I’ve updated the code, stored it in Github and figured out how to make it work in OSX using Automator, rather than installing some additional app. You can find the Github repository here.

For some reason, setting this up with Automator was a right pain, so I’m recording the steps here so that I never have to go through it again. But once it’s set up, it’s very handy.

Prerequisites:
– You must have Ruby set up on your machine, ready to run. OSX does have this set up by default so maybe you’ll be alright.
– It probably wouldn’t hurt to know a bit of Ruby so that you know what the code is doing, then you can use this knowledge to do all kinds of awesome things instead of just doing what I did!

1. Create a new Automator Service
This screenshot should explain what you need. The important things to note are:
– Choose type “Run Shell Script” under “Utilities”
– Use Shell “/usr/bin/ruby”
– Select “Service receives no input” in “any application”

Then just copy and paste the source code into the action area.

2. Modify the source
You will need to change the filepath of the web2 file to wherever it resides on your computer. Important – the shell script will ignore references to your home directory and relative filepaths so you must use an absolute filepath (e.g. ‘/Users/trish/Documents/web2’)

For the email script, you will need to modify the email address to be your own email address (where it says “YOUR_EMAIL”).

3. Add a Growl notification (Optional)
If you have Growl installed you can add a notification for these actions which looks kind of cool and also lets you know that the script is working.

4. Save it!
You might also want to run it to make sure it’s working properly.

4. Link it to a keyboard shorcut
Open System Preferences > Keyboard and you should see your new services, ready to have keyboard shortcuts associated with them.

Important! Pick a keyboard shortcut that’s not already in use by your other apps, otherwise your new keyboard shortcut will be overridden. I ended up going for something like AppleKey+Shift+2 which seemed to work okay for most of my apps.

5. Try it out!
Press your keyboard combination while you’re filling in online forms and watch your test data magically appear! Isn’t that easier than trying to think up unique data all the time?