Automating UIAutomation

Recently I stumbled on this wonderful introduction to UIAutomation. Until then I hadn’t known how relatively easy it is to write UIAutomation tests. After jumping in and writing several tests, I started to wonder how difficult it would be to automate the running of my tests on actual devices, through the command line.

I tried to use Bwoken, but unfortunately found it to have issues in Yosemite for running on actual devices. So I decided to figure how to do it manually.

The first step was to build the app through the command line with xcodebuild, which looks something like this:

xcodebuild -workspace “/path/to/workspace.xcworkspace" -scheme MySchemeName -sdk "iphoneos8.1" -configuration Debug SYMROOT=“/path/to/build/folder” DSTROOT=“/path/to/build/folder” 

The next step was to get the app onto the device. This was a bit harder. I couldn’t find an out of the box way to do this, so ended up using ios-deploy which can be installed through npm. Then, to get the device uuid for deploying, you can run instruments -s and find the device id there.

ios-deploy --justlaunch --bundle “/path/to/build/" --id {device-uuid}

Last, I used the instruments command to run my automation tests:

instruments -w {device-uuid} -t /Applications/ myapp -e UIASCRIPT /path/to/automation/tests.js