Start Instruments from the command line

Xazen picture Xazen · Mar 14, 2013 · Viewed 11.4k times · Source

I followed this site to get started with UI Automation. http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#1.2

I am trying to start Instruments from the command line. Unfortunately I get an error:

2013-03-14 14:06:36.376 instruments[17854:1207] Connection to the remote device lost while launching target. Aborting...
2013-03-14 14:06:36.378 instruments[17854:1207] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.

This is the command I used:

instruments -w {deviceId} -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate {appname} -e UIASCRIPT /Path/to/Script.js

Currently I am using Xcode 4.6.

Answer

idStar picture idStar · Sep 21, 2014

In 2014 with Xcode 6.0.1, you would do something like this for running UIAutomation tests on the simulator, naming your simulator after the -w switch:

instruments -t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
    -w 'iPhone 5s' \
    '/Users/sohail/Library/Developer/CoreSimulator/Devices/7232A640-A9D2-4626-A2AD-37AFFF706718/data/Containers/Bundle/Application/E71B915E-051D-4BEF-9083-34416D02EC91/RoadRunnerRadar.app' \
    -e UIASCRIPT '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestRunner.js' \
    -e UIARESULTSPATH '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestResults/'

If you want to run this on your device, instead of 'iPhone 5s' like I have in the snippet above for running on the simulator, you'd provide the UDID of your device. You can then omit the long app path I've given above, and just provide the name of the app. Instruments will be able to find it on the device.

Using my example from above, but modified for a hypothetical device, this would look like:

instruments -t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
    -w '8532A640-A9C2-4626-A2AD-37AFFF706799' \
    'RoadRunnerRadar' \
    -e UIASCRIPT '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestRunner.js' \
    -e UIARESULTSPATH '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestResults/'

This is not verified with an on device invocation, so please test it. There's a bit of flexibility with parameter ordering.

I do have a verified UI Automation Runner script that works really well for Xcode 6.0.1 and the simulator.