“Microautomation” With AutoHotkey


Well shoot. So I meant to publish one post every week, and I accidentally pushed this one out too early.

It’s funny how it happened. I’ll explain further below.

Reeeeally Wish I Could Remember That Article…

This is based off an article I read a few months back, about a concept called “microautomation”.

The idea was: automation is usually thought of in terms of test automation.We don’t often think it applies outside that area, but test automation is really a subset of automation of all kinds. It’s geared for running tests for us, instead of us spending time running them manually.

Also, we usually think of larger chunks of automation being the goal–large chunks of automation that save lots of time per use. But we don’t usually think of smaller pieces of it that save little bits of time more often.

This type of automation–microautomation–can actually save lots of time in the long run, in ways that a lot of people may not think of. Things that have become tribal knowledge, or muscle memory, can be automated.

If you know what article I’m talking about, let me know. It was a great article and I want to give credit to it.

Today I’ll explain how AutoHotKey can help with this level of automation. This is a tool that can simulate key presses, mouse operations, and also has logic built in. We’ll take a look at how it can be used


Installing AutoHotKey is simple. You can download and install a copy of it at their official website.

The user base for this tool is huge. It’s basically got its own language driving it. And, lots of people use AutoHotKey for day-to-day activities in IT. There’s probably not anything that you’ll get stuck on that hasn’t been figured out already.

It’s pretty easy to use, so getting it started is straightforward. The default script is AutoHotkey.ahk.

Example: Build a Page Object

When I build page objects for automation in Ruby, I keep just the locators in a Class file. The only other thing I put in is a method to return the hash of element names and locators.

They look like this:

class NameThisPage
 @elements = {
    "username" => "//input[@id='username']",
def get_elements {
 return self.elements

Instead of typing up skeleton page objects, AutoHotKey can be used to generate the skeleton, without any elements defined. Then I go back and change the class name to something that makes sense.

I like to start off scripts by having it intercept a character that gets it in a kind of “listening” mode. A key that doesn’t get used a whole lot is the tilde character, followed by a short 2-character string that can be used to change the behavior of the script.

For the example below, when I type `po, it means I want to make a (p)age (o)bject, which opens up Notepad (not what I use, but for now, it’ll work), and fill in just what’s needed to get started:

`:: ; start with the tilde character--not often used
input, command, L2 ; L2 to limit the input to 2 keys.

if command = po ; "po" = "page object"
 Run Notepad ; open up a new instance of notepad
 sleep 500 ; sleep a bit for it to come up fully
 ; write out the skeleton for the new page object
 send class NameThisPage{enter}
 ; need to enclose curly braces in a set of them
 ; to get them to "send" properly. 
 ; i.e.: {{} sends a "{". 
 ; same for "}"
 send {tab}@elements = {{}{enter}
 send {enter}
 send {tab}{}}{enter}
 send {}}
 send {enter}
 send def get_elements {{}{enter}
 send {tab}return self.elements{enter}
 send {}}{enter}
else if command = se ; "se" = "something else"
 ; put whatEEEEEEEEver you want in here. go nuts. 

The Funny Part

hurrWell. thought it was funny anyway.

So, when I was trying to explain that I use the tilde key above, I typed the character… and typed it again because it didn’t show up… and it proceeded to type out the page object skeleton, including all the tabs and enter presses. It ended up tabbing right over the Publish button, and pushed it out.


So. When you’re ready to turn AutoHotkey off, right click the icon in your status bar, and click Exit.

Where can you write microautomation to speed up your day-to-day? How else can you use this tool to your advantage?

All kinds of automation can be written, and we can’t be constrained to thinking in terms of one kind. Got knowledge gaps? Let’s fill them in. www.archdevops.com



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s