Looking for more information about UI Automation? Check out my new book, published through the Pragmatic Programmers. Thanks for your support!
Since iOS 5 and Xcode 4.2 came out, I’ve been poking around in UI Automation and I’m starting to get impressed. You’ll want to read through the parts of my tutorial first. I assume you’ve already walked through those steps.
First off, they now let you invoke it from the terminal! Well…sort of. Observe:
I broke up the command parameters on separate lines for some sanity. That first
-t [template file], lets you specify the specific template file
you want to use when instruments is run. You can run any kind of instrument you
want, but in this case I’m using the unbelievably long path to the default
Automation template that is offered by the new document wizard. You could make
your own template from within Instruments and specify that instead, but you get
xcodebuild from the terminal, soon. I have a couple of tricks up my
sleeve to make them play better with Unix, but I’m testing a few things out,
The second parameter is the path to the application binary that the simulator
uses. You can find them by poking around in
Support/iPhone Simulator/5.0. You’ll see a list of directories with guids for
names. Look inside them to find the app bundle you are looking for and that’s
the path you hand in here.
The last parameter is where you specify environment variables that are handed
in to Instruments. In this case we set the environment variable
sent to standard out.
You can also specify other environment variables with subsequent
arguments. These environment variables pass through to the application so you
can have, say, a
RESET_ALL_DATA variable that your application checks for to
set itself up in a consistent state before the script is run.2
Notice that you switch between the script and logging views by using the popup menu named “Script” above the main editor/logging pane.3
the script and logging panes. See in the sidebar under the “Status” section where it says “Script is Capturing”? Double click that and you’ll toggle between the two panes on the right. Don’t ask me how I found that out. WYSIWYG for the win, right? :)
You can manage scripts in the editing pane by clicking the “Add” and “Remove” buttons in the sidebar. Choosing “Create” from the “Add” menu just gives you a blank script to play with.
Finally we come to the log pane. You’ll notice that when logging an element tree we finally have a hierarchial representation! Much easier to read than before. And to the right we have screen captures of each of the individual elements that a line belongs to. Nice touch.
I like where this is going. Since Apple claims to be using UI Automation internally, there’s solid hope it will keep improving. It’s not quite ready for prime time use in a continuous integration flow, yet. The fact that it doesn’t return a proper Unix status code on failure is surprising. You could capture the output and grep for failure messages and handle that if you need to, but unfortunately that’s effort to solve a problem that shouldn’t exist.
Apple, you’ve built your empire on top of Unix. Don’t be afraid to do it the Unix way. :)