Can the UI Automation instrument be run from the command line?
Asked Answered
I

9

55

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?

Indict answered 16/11, 2010 at 7:17 Comment(1)
How about since iOS5 betas, this should be quite possible.Grimalkin
S
54
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.

  3. 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.

  4. 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.

Swoon answered 22/6, 2012 at 22:7 Comment(11)
Where do you have a -w parameter in the example above?Teuton
I do excatly same things but i have error like that " instruments[2760:1207] Unable to interpret path '(null)' Instruments Trace Error : Error Starting Recording" but paths are not null or empty. Do you have an idea?Counterplot
@yucelbayram Any advice on that Unable to interpret path '(null)' ?Hydrography
@FullDecent Sure, my application Path was not fully true. True path was like that "/Users/MyUserName/Library/Application Support/iPhone Simulator/7.1/Applications/87F1A296-A45A-4E48-8157-0C4574DECFD6" I fixed this and it start to work. Check your paths are really true.Counterplot
where is -w parameter ?? please i wanna run this on my deviceBricole
how do you get the application output? i.e NSLog or exit code..? i am doing automation tests and i need this value to verify that my app worked ok during this instrumetnts run.Shirleyshirlie
I found I had to use the -w option even with my simulator in Xcode 6.1.1. I found this was needed: -w "iPhone 5s"Yurt
I have given the UDID and the path to the trace file .... Now what would be the <full_path_to_application> on my iPhone 5S running on 8.3 ??Claudelle
This is really great and it helped me a lot. But I have question regarding the template -t. What does it do and why is it needed?Syriac
I got an error called: Instruments Trace Error : *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0] when I was using the xcode >= 6.1 template. Does anyone know why this is happening?Gnomon
<full_path_to_application> can alternatively be the name of the Application/process that you want to attach to.Blader
W
22

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 Can Instruments be used using the command line?

Hope this helps- have a good day :)

Wardmote answered 10/8, 2011 at 11:51 Comment(2)
thanks for the links, i have my scrips running in Instruments properly, but still can't get it running from the command line. i can't seem to get it to run through the simulator. any ideas on what to pass the -w argument?Windburn
You've probably already worked it out but the argument to the -w should be the UDID for the attached deviceTwink
P
8

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.

Polyptych answered 20/9, 2014 at 22:23 Comment(0)
V
6

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.
Velure answered 17/8, 2013 at 18:28 Comment(0)
A
4

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.

Arria answered 10/1, 2013 at 22:29 Comment(1)
'instruments -s' also prints out useful information about devices.Naman
I
3

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.

Incorporator answered 21/1, 2011 at 11:15 Comment(5)
No, unfortunately. For now I just focus on tests I will need to run, later (if I will have time) I will focus on way of running them in automated way. Worst case scenario - I will use Sikuli (sikuli.org) to automated this, but it is such workaround, that I would like to avoid that...Incorporator
I wounder if this command line tool works at all. My goal is test automation an CI but I even don't get it work on the Simulator. I also tried the shipped Leaks.tracetemplate. The Simulator appears, tries to launch the App but fails with an "Unknown Error". Very depressing indeed. The App-File is OK, running it with Instruments-GUI works fine. On the Apple sites there seems to be no hint for that command option. Maybe, they forgot about it? :)Tamarra
@Rene Berlin,. Are You Facing "Unexpected error ...." ? "Unexpected error in -[UIATarget_0x5a20d20 frontMostApp], /SourceCache/UIAutomation_Sim/UIAutomation-37/Framework/UIATargetElements.m line 437" If you are facing this problem, this can be corrected by copying a com.apple.Accessibility.plist to 4.0.1. Copy com.apple.Accessibility.plist to: Collapse ~/Library/Application Support/iPhone Simulator/4.0.1/Library/Preferences Make sure that there should be only two Keys in this file name as “AccessibilityEnabled” and “ApplicationAccessibilityEnabled”. Both the keys should be checked.Indict
@Yoosiba,. No offence, but using Sikuli for to automate UI Automation is seriously not a good idea.Indict
I agree that it is not the best approach, but I don't see other choice with Instruments. Other than trained monkey to start/stop & change script.Incorporator
L
2

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

Loren answered 24/3, 2011 at 14:29 Comment(1)
. When we are testing a client application,. usually they expect not to make/add any code to their proj file. Anyway I like your idea of libcat. ThanksIndict
U
0

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>
Ufo answered 8/3, 2013 at 16:6 Comment(0)
P
0

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/
Perplex answered 16/12, 2015 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.