Pet Project: Mechanic.js, a jQuery-esque UIAutomation library for iOS

March 12, 2012 | Jason Kozemczak

A few weeks back, I started working on a new project at work. Our client had a suite of iPad apps that had originally been written by an offshore IT firm. The many-tentacled beast of a codebase had nothing in the form of testing, so early on we started adding basic UATs and regressions where possible in order to safeguard the features of the various iPad apps (which had little to nothing in terms of documentation, etc).

As we worked to add UAT coverage with UIAutomation, I was growing tired of the rather verbose syntax that UIAutomation provides. Many of the functions available to UIAutomation elements have multiple versions of functions (tap, doubleTap, twoFingerTap, tapWithOptions, etc.), and no easy way to traverse an app’s element hierarchy.

I pined for a library that would make interacting with UIAElements as fun and simple as libraries like jQuery, Dojo, Zepto and the like have made interacting with the DOM. When I found there was no such library, I wrote my own: mechanic.js.

Mechanic gives you the element traversal features you know and love from CSS selector engines along with the ability to chain selector functions together. Convenience methods for much of the UIAutomation API have been provided in a “chained” version.

I’ve been working on an initial implementation this week, and API documentation and test coverage are my next concerns in the coming weeks. In the meantime, check it out on Github. If you find a missing or broken feature (and there surely are some), submit an issue (or just fix it yourself and send a pull request via Github.

Hopefully this is useful to more than just myself. Let me know what you think in the comments!

Leave a Reply

Your email address will not be published.