Can the UI Automation instrument be run from the command line?

IphoneXcodeApplescriptInstrumentsIos Ui-Automation

Iphone Problem Overview


Is there a way to open the UIAutomation instrument through the terminal?

Will it be possible to write an AppleScript to open Apple's UIAutomation tool and load the application to be tested?

Can you please tell me is there any way through scripting or through the command line we can open UIAutomation and select the app to be tested, as well as select the test script?

Iphone Solutions


Solution 1 - Iphone

instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/\
PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>

for xcode >= 4.5

instruments -t
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/\
AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>

for xcode >= 6.1

instruments -w <device ID> -t \
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/\
AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>

There a few important things to note though:

  1. the -w parameter is not required unless you want to run the scripts on your device. If you want to run your scripts on the simulator, simply omit this parameter from the command.
  2. full_path_to_application is the path to your .app file that is created by your simulator. For me, the path was >/Users/fwasim/Library/Application Support/iPhone Simulator/5.0/Applications/AA6BA2E1-D505-4864-BECC-29ADEE28194D/name_of_application.app

this path might be different for anyone else depending on what iOS version are you running on your simulator. Also remember to put this path in double quotation marks.

  1. The path_to_script.js should be the FULL PATH to where your automation script written in javascript is saved. Also remember to put this path in double quotation marks.

  2. Lastly output results path is the path where you want to save the output results. Also remember to put this path in double quotation marks.

These were the points I had been missing on and thus was getting some of the errors mentioned above.

Solution 2 - Iphone

Starting UIAutomation via command line You can do it now, starting with XCode 4.2 for iOS5 beta 4 From command line, you can run instruments pointing to the automation template and specify as environment variables the test script you want to execute and destination path for results:

instruments -w -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -e UIASCRIPT

Above is from this source url: http://dev-ios.blogspot.com/2011/07/starting-uiautomation-via-command-line.html

See some more details on command line from Apple at: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/instruments.1.html

Plus post from Stacktrace user on command line run with iphone iOS UIAutomation https://stackoverflow.com/questions/4819000/can-instruments-be-used-using-the-command-line

Hope this helps- have a good day :)

Solution 3 - Iphone

Updated and tested for Xcode 6.0.1:

instruments -w 'iPhone 5s' \
	-t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
	'/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/'

Inspired by others who wrote command-line wrappers that haven't been updated in a while, and thus didn't work (and seemed difficult to make sense of as I was tempted to resurrect them), I wrote a bash shell script that I believe will be more transparent, lighter and thus, easier to maintain.

You can find the project on github and a companion blog post.

Solution 4 - Iphone

Instead of the long instruments command, I wrote a wrapper that is easier to use: https://github.com/enriquez/uiauto

To use it, you just have to do the following:

  1. Build your project in Xcode for the simulator (device support coming soon).
  2. cd to where your project's .xcodeproj or .xcworkspace is located.
  3. Run uiauto exec path/to/your/script.js.

Solution 5 - Iphone

With every new version of Xcode the template path seems to be changed. One of the best ways find out the path of the template is instruments -s command which would list out all the available templates.

Solution 6 - Iphone

I also very intrested in this topic. What I actually found is this reference which shows that there is way to launch instruments from terminal with predefined template, location where results should be stored, and target device on which it should run, and other parameters. You can also just type in terminal instruments to get parameters list.

I was unsuccessful with running UI Automation on iPhone this way. I haven't try simulator or mac app since I am mostly interested in device. I posted a question here on SO but from the lack of any response I think that not many people are using instruments this way.

But there is hope to get it running, as there is this short thread on apple developer forum (you need to log in) that suggest that it can be done. I will be trying that later, if I will succeed I will post solution here. If you will manage to make it running pleas post your way here, as I (and probably others) will be interested.

Solution 7 - Iphone

there's a tool for record/replay UI events with shell environment, and could writting script with ruby.

interactive iPhone application development http://github.com/wookay/libcat

Solution 8 - Iphone

Type this command in terminal instruments -s, you get template path after type:

instruments -t <template path> <Application file path> -e UIASCRIPT <script.js> UIARESULTPATH <result_path>

Solution 9 - Iphone

The right way to do it on a iOS simulator is as follows:

instruments -w 'iPhone 5s (9.1)' \
-t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
'justTheNameOfYourAppDontAddExtension' \
-e UIASCRIPT '/Users/barry/Dropbox/Public/login.js' \
-e UIARESULTSPATH '/Users/barry/Dropbox/Public/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVijayView Question on Stackoverflow
Solution 1 - IphoneFarhan Ahmed WasimView Answer on Stackoverflow
Solution 2 - Iphoneuser887803View Answer on Stackoverflow
Solution 3 - IphoneidStarView Answer on Stackoverflow
Solution 4 - IphoneMichael EnriquezView Answer on Stackoverflow
Solution 5 - IphoneharishView Answer on Stackoverflow
Solution 6 - IphoneyoosibaView Answer on Stackoverflow
Solution 7 - IphoneWooKyoung NohView Answer on Stackoverflow
Solution 8 - IphonePrasad RampillaView Answer on Stackoverflow
Solution 9 - IphonebarryjonesView Answer on Stackoverflow