[整理]在命令行执行 UIAutomation
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>
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.
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.
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.
========================================================
You can run your tests from command line and configure a hudson job to always deploy stable build automagically. You can run your tests from CLI using the following command.
$ instruments -t templateFilePath targetAppName
By default the tests will be executed on the simulator, you could execute the tests on actual device using the following command:
$ instruments -w deviceID -t templateFilePath targetAppName
You could execute any instruments template using command line, for example to trigger a UIAutomation template from command line you would use the command as follows:
$ instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate <path-to-your-app>/<appname>.app/ -e UIASCRIPT <path-to-your-js-test-file> -e UIARESULTSPATH <path-to-results-folder>
This is really helpful in terms of achieving CI compliance, I’ve basically written a py script that does the following:
- create a new tag from svn trunk with minor release version update
- grab the tag from svn
- complile the app from command line for xocde
- run the uiautomation smoke tests from command line (mentioned above)
- if tests are green, publish the build on the web server for OTA test distribution.
- repeat for new release
========================================================
Once you want to automate your ui automation tests you are faced with two questions.
- How to run automation script from the command-line?
- How to change testing device on a Simulator?
Let’s find out!
1. Command line
Answer is pretty straightforward. There is an instruments (lowercased) binary in the devtools suite.
Usage can be found in Apple’s docs and by running it with no params:
instruments, version 4.5 (46000)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]
You will have to install Command Line Tools package from developer.apple.com.
https://developer.apple.com/downloads/index.action
Or use xcrun.
Usage: xcrun [options] <utility> ... arguments ...
Find and execute the named command line utility from
the installed Xcode.
Syntax is also simple:
xcrun instruments -v -t <path to Automation instrument template> <path to app> -e UIASCRIPT <path to testing script> -e UIARESULTSPATH <path to results file>
-v for verbose output
-t <path to Automation instrument template> will likely point to:
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
<path to app> is a just an app name for testing on device (e.g. “Mobile EMR.app”) or a full path to application in simulator on local filesystem, e.g.:
~/Library/Application\ Support/iPhone\ Simulator/6.1/Applications/00C7521A-92D9-4627-BB1D-2CD7CA605B9B/Mobile\ EMR.app)
-e is for passing params, where we specify our JS script and path to results file.
For Simulator it will look like:
xcrun instruments -v -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ~/Library/Application\ Support/iPhone\ Simulator/6.1/Applications/00C7521A-92D9-4627-BB1D-2CD7CA605B9B/Mobile\ EMR.app -e UIASCRIPT /Volumes/Data/SoftServe/Projects/mEMR/imHealth/Testing/testUI.js -e UIARESULTSPATH /Volumes/Data/SoftServe/Projects/mEMR/imHealth/Testing/results.txt
-w <udid> has to be added for testing on device:
xcrun instruments -v -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w bd553b386b52b6c61b8a107xxxxxxfe6675 "Mobile EMR.app" -e UIASCRIPT /Volumes/Data/SoftServe/Projects/mEMR/imHealth/Testing/testUI.js -e UIARESULTSPATH /Volumes/Data/SoftServe/Projects/mEMR/imHealth/Testing/results.txt
2. Changing active device on Simulator
Default device in Simulator is always iPad. There is no way to alter this setting.
So we will do a little trick. Info.plist of the app contains UIDeviceFamily key, which contains array with 1 (iPhone)and 2 (iPad) values.
Leaving just 1 will make Simulator launch in iPhone mode.
When device family already specified, concrete device simulation can be managed via writing to Simulator preferences:
defaults write com.apple.iphonesimulator SimulateDevice -string "iPhone (Retina 4-inch)"
========================================================
[整理]在命令行执行 UIAutomation的更多相关文章
- linux命令行执行db2存储过程
存储过程代码如下: CREATE PROCEDURE proc_sum2(IN n INT,OUT sum INT,OUT j INT) BEGIN DECLARE i INT; ; ; ; WHIL ...
- mysql命令行执行外部文件
mysql命令行执行外部文件
- android程序中使用命令行及获得命令行执行后的内容
在开发android项目中,需要在程序中使用命令行执行,获得命令行执行后的结果并做处理. 下面是自己写的一个小例子,供以后参考使用: public String android_command(){ ...
- 命令行执行php脚本 中$argv和$argc
在实际工作中有可能会碰到需要在nginx命令行执行php脚本的时候,当然你可以去配置一个conf用外网访问. 在nginx命令行中 使用 php index.php 就可以执行这个index.php脚 ...
- php 运行linux命令 与 linux下命令行执行php
1.php运行linux命令 exec函数:string exec(string command, string [array], int [return_var]); 执行函数后不输出结果,返回最 ...
- yii2 命令行执行php命令 commands(命令)
YII2可以在命令行执行php命令,作为半路出家的撩妹君可谓是抠脚福音.作为一个屌丝级的程序员必须要有智能提示代码的IDE,比如PHPstorm.至于如何免费使用嘛..... 首先明白YII2自带的c ...
- 使用命令行执行jmeter的方法
1. 简介 使用非 GUI 模式,即命令行模式运行 JMeter 测试脚本能够大大缩减所需要的系统资 本文介绍windows下以命令行模式运行的方法. 1.1. 命令介绍 jmeter -n -t & ...
- hive -help hive命令行执行sql参数
在shell命令行执行 hive -help 结果如下: -d,--define <key=value> Variable substitution to apply to Hive co ...
- 在Linux命令行执行python命令
在Linux的命令行执行python的某些命令: [root@centos7 ~]# echo "import sys ;print(sys.path)"|python3.6 [' ...
随机推荐
- [ACM] POJ 3061 Subsequence (仿真足)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8403 Accepted: 3264 Descr ...
- cocos2dx 3.0 它 使用std::bind更换CC_CALLBACK_N
在cocos2dx 3.0 版本号,回调函数本质4一个CC_CALLBACK_N 替换功能.N的回调函数的参数的数量的代表 1.让我们来看看这些CC_CALLBACK_N怎么用 比方action的回调 ...
- 基础总结篇之五:BroadcastReceiver应用具体解释
問渠那得清如許?為有源頭活水來.南宋.朱熹<觀書有感> 据说程序猿是最爱学习的群体,IT男都知道,这个行业日新月异,必须不断地学习新知识,不断地为自己注入新奇的血液,才干使自己跟上技术的步 ...
- Swift语言指南(八)--语言基础之元组
原文:Swift语言指南(八)--语言基础之元组 元组 元组(Tuples)将多个值组合为一个复合值.元组内的值可以是任何类型,各个元素不需要为相同类型(各个元素之间类型独立,互不干扰--Joe.Hu ...
- Python的html和xml解析库Beautiful Soup
网站:http://www.crummy.com/software/BeautifulSoup/ 版权声明:本文博主原创文章,博客,未经同意不得转载.
- Php设计模式(三):行为型模式part2
原文详见:http://www.ucai.cn/blogdetail/7023?mid=1&f=5 可以在线运行查看效果哦! <接上文> 5.中介者模式(Mediator) : 用 ...
- git合并远端分支到本地分支的两种方式
作者:zhanhailiang 日期:2014-11-21 在使用版本号工具提交改动之前,都须要通过update先将本地代码更新到最新版本号.SVN通过svn update就能够实现,那么git怎样实 ...
- 01. SQL Server 如何读写数据
原文:01. SQL Server 如何读写数据 一. 数据读写流程简要SQL Server作为一个关系型数据库,自然也维持了事务的ACID特性,数据库的读写冲突由事务隔离级别控制.无论有没有显示开启 ...
- JS怎样将拖拉事件与点击事件分离?
帖子:http://bbs.csdn.net/topics/390785395?page=1#post-397369340 怎样将拖拉事件跟点击事件分离? 须要做到:拖拉时不触动点击事件 <ht ...
- Django----模板
为了将html页面和python代码分离开来,有必要介绍一下模板的作用,Django中自带很多模板. 以下一个html模板文件: <html> <head><title& ...