Can the UI Automation instrument be run from the command line?
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?
- How to automate creation of new XCode targets from Applescript/Automator/Shell Script
- Run AppleScript from Cocoa Application
- XCode 5 - AppleScript - How to get document in current tab
- Passing variables to an applescript
- Apple Script working fine but with Objective C Library not getting expected out put
- Can you execute an Applescript script from a Swift Application
9 Solutions Collect From Internet About “Can the UI Automation instrument be run from the command line?”
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:
- 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.
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.
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.
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:
See some more details on command line from Apple at:
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 🙂
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.
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:
- Build your project in Xcode for the simulator (device support coming soon).
- cd to where your project’s .xcodeproj or .xcworkspace is located.
uiauto exec path/to/your/script.js.
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.
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.
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>
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/
- iOS SQLite.swift, regarding upgrade of app?
- Tab bar, reload every time tab is pressed
- How to render a radial gradient onto a new UIImage on an iphone
- How to import GoogleAnalytics header into a library Framework?
- Keeping headers as `project` in Xcode framework
- 'UIApplicationMain' attribute cannot be used in a module that contains top-level code
- AVAudioUnitEQ / .BandPass filter doesn't work
- Swift Error: Binary operator '&&' cannot be applied to two 'Bool' operands
- header search path in XCode 4
- Assertion failure in UITextView _firstBaselineOffsetFromTop
- UISplitViewController Hide/Unhide MasterView In Storyboard
- Why doesn't this code produce the correct output?
- How to make Siri launch app on specific keyword?
- Completion handlers and return values
- Preventing UICollectionViewCell animated appearance when presenting UICollectionView