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?
- Is there a way to list all files and their targets in Xcode?
- Passing variables to an applescript
- How to automate creation of new XCode targets from Applescript/Automator/Shell Script
- Adding files via Applescript to an Xcode project target
- How to build & run Xcode with Applescript?
- XCode 5 - AppleScript - How to get document in current tab
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/
- How do I add text to an image in iOS Swift
- Documentation-generator for Objective-C?
- Really cool way to create custom UITabBar for iPhone app?
- UICollectionView + NSFetchedResultsController in Swift 3
- Custom cell: fatal error: unexpectedly found nil while unwrapping an Optional value
- how can i save in userdefaults if my app has crashed
- Different Bundle Identifier for different build configurations
- What is diffrence between self.timer = nil vs in iOS?
- How to permanently fix Xcode 5 SpringBoard failed to launch application with error: -3
- can't open image with NSOpenPanel
- XCode fails to run app on device, saying the program being debugged is not being run
- RestKit/RestKit.h' file not found error during xcodebuild
- Intercepting pan gestures over a UIScrollView breaks scrolling
- How to get indexPath.row of tableView which is currently being displayed?
- Can I include a framework in another framework?