Web automation with Chickenfoot

ChickenfeenI was getting scared there for a minute. It had been at least a few weeks since I last found something on the interweb that rocked my web-based world.

Things were getting desperate, and for a moment I feared I might be forced to go back and work on one of my half-finished projects or something. But I was saved. Saved by the crunchy goodness of Chickenfoot. Yes, Chickenfoot will (slightly) change your life.

Chickenfoot must be compared to Greasemonkey. Indeed, from the vague description I was given at Sydney BarCamp (I was told the wrong session time, and missed the actual demo) I assumed it was just someone re-inventing the monkey.

But I was wrong. Slightly wrong.

Chickens vs. Monkeys

Like Greasemonkey, Chickenfoot lets you mess with web pages on the client side: Correct bugs, fix annoyances, create new functionality... whatever you want - without having to ask the site admins to lift a finger.

The main difference between the chicken and the monkey is that Greasemonkey primarily operates on a page-by-page basis, where as Chickenfoot scripts run as a single transaction involving multiple pages - even spanning multiple sites.

This makes it more suited for automating repetitive processes, rather than tweaking DOM elements. (Note I said "more suited" - Chickenfoot can do some fancy tweaking, just as Greasemonkey can work as a process automater.)

Scripting for the people

The other big difference is that Chickenfoot has tried to target the non-techy user. Here is an example of a Chickenfoot transaction:

go("google.com")
enter("Mr Speaker")
click("google search")

No prizes for guessing what that script does. Well, it's not that obvious, I just don't have any prizes. Chickenfoot acts like a real life user - the commands get executed as if a user had done them: go("google.com") navigates to google.com, enter("Mr Speaker") types Mr Speaker into the text box, and click("google search") simulates a click on the button called "google search". The result is your browser opened on the Google search results page having done a search for "Mr Speaker". Pretty cool hey?

As you can see they've tried to make it nice and friendly. Though, it really only stays friendly while you are trying to do pretty simple stuff. It doesn't take long until you find yourself DOM-inspecting to get element names, or writing some funky regular expressions to extract data - something that the developers are trying to avoid you having to do.

But the built in functions are quite powerful. The wrapper functions (like go, enter, click, pick, check) do more than just a simple document.location, button.click(), item.select()... they fire events, and wait for callbacks - so you don't have to! In the above example, the line to enter some text in a text box does not occur until the page load from the line before has completed. This makes writing Chickenfoot scripts damn fun!

Where it can be used

Chickenfoot scriptLike all these cool gadgets, they are only useful if they actually solve a problem. The problem that Chickenfoot is best at solving usually goes along the lines of "To get to the information I need I have to log in, then select this from that dropdown box, then check that checkbox and then click here. Then click here. Then there. And that's the screen I want."

Chickenfoot can automate all those steps, and then take you to your final destination. Or better still, automate all those steps, do a bit of screen-scraping, and display the data somewhere else without you having to go to the site at all!

If you are doing web dev work, it's the best thing since the Web Dev Toolbar... You can automate EVERYTHING; automatically log yourself into all your apps and display a status update of your flickr/twitter/blah blah accounts. Automate all your forms testing, bug tracker updates and time sheet entries. Add your RSS feeds into the company intranet so it looks like you're actually working.

Then with a press of the button, your awesome time-saving scripts can be converted to standalone Firefox extensions which you can distribute to co-workers and receive accolades from your bosses. Or be fired by your bosses.

How it changes things

Chickenfoot has a chance to change things considerably. As more desktop applications are being accessed by web-based front-ends, this kind of automation can help streamline business processes and remove user frustrations.

If users begin writing thier own scripts that become popular within a department, they could be flagged to the dev team as a possible system enhancement. Alternatively, annoying users who demand stupid functionality changes could be appeased with a couple of lines of code.

It also probably presents severe security implications that we won't worry about right now.

Get to it

In conclusion: have a go. Chickenfoot is currently buggy and confusing, but inspirational and time-wastey. It will fill your head with ideas that I'm sure you'll never implement. That's what Web2.0 is all about.

The Chickenfoot documentation is pretty atrocious, so I'm in the processes of writing up a lil' tutorial for you all. But that won't be done until I've written a few Chickenfoot scripts that I can't believe I've had to live without all this time...