博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[整理]在命令行执行 UIAutomation
阅读量:4693 次
发布时间:2019-06-09

本文共 6158 字,大约阅读时间需要 20 分钟。

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:

  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.

========================================================

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 
/
.app/ -e UIASCRIPT
-e UIARESULTSPATH

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.

  1. How to run automation script from the command-line?
  2. 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] 
... arguments ...Find and execute the named command line utility fromthe 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 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)"

========================================================

 

转载于:https://www.cnblogs.com/Proteas/p/3511579.html

你可能感兴趣的文章
Java导入execl
查看>>
Js中的window.parent ,window.top,window.self 详解
查看>>
next
查看>>
数据库---表---多表查询
查看>>
【分享】常用获取IP及地区信息API
查看>>
Spring 【引用】类型【注入】
查看>>
正则表达式 环视
查看>>
关于Tchar
查看>>
小白学习Spark系列三:RDD常用方法总结
查看>>
将jquery序列化转成对象的编码坑
查看>>
6.824 LAB1 环境搭建
查看>>
shell 脚本实战笔记(10)--spark集群脚本片段念念碎
查看>>
HDU - 3572 Task Schedule
查看>>
log4j2.xml的例子
查看>>
1004 四子连棋
查看>>
二、第一个C程序:Hello World!
查看>>
Ubuntu 编译 ARM-Linux-Gcc 工具链 -- 编译过程
查看>>
java url生成二维码保存到本地
查看>>
python platform模块
查看>>
Nginx
查看>>