xcode 可以从命令行运行 UI 自动化仪器吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4191945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:36:01  来源:igfitidea点击:

Can the UI Automation instrument be run from the command line?

iphonexcodeapplescriptinstrumentsios-ui-automation

提问by Vijay

Is there a way to open the UIAutomationinstrument through the terminal?

有没有办法UIAutomation通过终端打开仪器?

Will it be possible to write an AppleScriptto open Apple's UIAutomationtool and load the application to be tested?

是否可以编写一个AppleScript打开 Apple 的UIAutomation工具并加载要测试的应用程序?

Can you please tell me is there any way through scripting or through the command line we can open UIAutomationand select the app to be tested, as well as select the test script?

请问有没有什么办法可以通过脚本或者命令行我们可以打开UIAutomation并选择要测试的应用程序,以及选择测试脚本?

回答by Farhan Ahmed Wasim

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

对于 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

对于 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.

  1. 除非您想在设备上运行脚本,否则不需要 -w 参数。如果要在模拟器上运行脚本,只需从命令中省略此参数即可。
  2. full_path_to_application 是模拟器创建的 .app 文件的路径。对我来说,路径是

    /Users/fwasim/Library/Application Support/iPhone Simulator/5.0/Applications/AA6BA2E1-D505-4864-BECC-29ADEE28194D/name_of_application.app

    根据您在模拟器上运行的 iOS 版本,此路径对其他人可能有所不同。还要记住将此路径放在双引号中。

  3. path_to_script.js 应该是保存用 javascript 编写的自动化脚本的完整路径。还要记住将此路径放在双引号中。

  4. 最后输出结果路径是您要保存输出结果的路径。还要记住将此路径放在双引号中。

These were the points I had been missing on and thus was getting some of the errors mentioned above.

这些是我一直遗漏的要点,因此出现了上面提到的一些错误。

回答by user887803

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:

通过命令行启动 UIAutomation 您现在可以开始,从适用于 iOS5 beta 4 的 XCode 4.2 开始从命令行,您可以运行指向自动化模板的仪器,并将您要执行的测试脚本和结果的目标路径指定为环境变量:

instruments -w -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -e UIASCRIPT

仪器 -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

以上来自这个源网址: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

在 Apple 的命令行中查看更多详细信息: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?

加上来自 Stacktrace 用户在命令行上的帖子,使用 iphone iOS UIAutomation 可以使用命令行使用仪器吗?

Hope this helps- have a good day :)

希望这会有所帮助-祝您有美好的一天:)

回答by idStar

Updated and tested for Xcode 6.0.1:

针对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.

受到其他人的启发,他们编写了一段时间没有更新的命令行包装器,因此不起作用(并且似乎很难理解,因为我很想复活它们),我写了一个 bash shell 脚本,我相信会更透明,更轻,因此更容易维护。

You can find the project on githuband a companion blog post.

您可以在github上找到该项目和一篇配套的博客文章

回答by Michael Enriquez

Instead of the long instrumentscommand, I wrote a wrapper that is easier to use: https://github.com/enriquez/uiauto

instruments我写了一个更容易使用的包装器,而不是长命令: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.
  1. 在 Xcode 中为模拟器构建您的项目(设备支持即将推出)。
  2. cd 到您的项目的 .xcodeproj 或 .xcworkspace 所在的位置。
  3. 运行uiauto exec path/to/your/script.js

回答by harish

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 -scommand which would list out all the available templates.

对于每个新版本的 Xcode,模板路径似乎都发生了变化。找出模板路径的最好方法之一是instruments -s列出所有可用模板的命令。

回答by yoosiba

I also very intrested in this topic. What I actually found is this referencewhich 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 instrumentsto get parameters list.

我也对这个话题很感兴趣。我实际找到的是这个参考资料,它表明可以使用预定义的模板、应存储结果的位置、应运行的目标设备以及其他参数从终端启动仪器。您也可以只输入终端instruments来获取参数列表。

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 SObut from the lack of any response I think that not many people are using instruments this way.

我以这种方式在 iPhone 上运行 UI 自动化没有成功。我没有尝试模拟器或 mac 应用程序,因为我最感兴趣的是设备。我在 SO 上发布了一个问题但由于没有任何回应,我认为没有多少人以这种方式使用仪器。

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.

但是有希望让它运行,因为在苹果开发者论坛上他的简短帖子(你需要登录)表明它可以完成。我稍后会尝试,如果我成功了,我会在这里发布解决方案。如果您设法让它运行,请在此处发布您的方式,因为我(可能还有其他人)会感兴趣。

回答by WooKyoung Noh

there's a tool for record/replay UI events with shell environment, and could writting script with ruby.

有一个用 shell 环境记录/重放 UI 事件的工具,并且可以用 ruby​​ 编写脚本。

interactive iPhone application development http://github.com/wookay/libcat

交互式 iPhone 应用程序开发 http://github.com/wookay/libcat

回答by Prasad Rampilla

Type this command in terminal instruments -s, you get template path after type:

在终端仪器 -s 中键入此命令,键入后将获得模板路径:

instruments -t <template path> <Application file path> -e UIASCRIPT <script.js> UIARESULTPATH <result_path>

回答by barryjones

The right way to do it on a iOS simulator is as follows:

在 iOS 模拟器上正确的做法如下:

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/