从Xcode运行UIAutomation脚本

从Xcode运行UIAutomation脚本,第1张

概述有没有人成功在Xcode中建立自动化UIAutomation测试? 我试图在我的Xcode项目中设置一个目标,它应该运行我准备的所有UIAutomation脚本。目前,此目标的唯一构建阶段是此运行脚本块: TEMPLATE="/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/Automati 有没有人成功在Xcode中建立自动化UIautomation测试?

我试图在我的Xcode项目中设置一个目标,它应该运行我准备的所有UIautomation脚本。目前,此目标的唯一构建阶段是此运行脚本块:

TEMPLATE="/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/automationInstrument.bundle/Contents/Resources/automation.tracetemplate"MY_APP="/Users/Me/library/Application Support/iPhone Simulator/6.0/Applications/564ED15A-A435-422B-82C4-5AE7DBBC27DD/MyApp.app"RESulTS="/Users/Me/Projects/MyApp/Tests/UI/Traces/automation.trace"SCRIPT="/Users/Me/Projects/MyApp/Tests/UI/SomeTest.Js"instruments -t $TEMPLATE $MY_APP -e UIASCRIPT $SCRIPT -e UIARESulTSPATH $RESulTS

当我建立这个目标后,几秒钟后会成功,但脚本实际上没有运行。在构建日志中,我收到以下错误:

instruments[7222:707] Failed to load Mobile Device Locator plugininstruments[7222:707] Failed to load Simulator Local Device Locator plugininstruments[7222:707] automation Instrument ran into an exception while trying to run the script.  UIATargetHasGoneAWolException+0000 Fail: An error occurred while trying to run the script.Instruments Trace Complete (Duration : 1.077379s; Output : /Users/Me/Projects/MyApp/Tests/UI/Traces/automation.trace)

我很确定,我的JavaScript和我的运行脚本都是正确的,因为如果我在bash中运行完全相同的仪器命令,它的工作原理如预期。
这可能是Xcode中的错误吗?

解决方法 我终于找到了解决这个问题的办法。似乎Xcode正在运行有限权限的运行脚本。我不完全确定,什么导致仪器命令失败,但使用su更改为您的用户将修复它。

su $USER -l -c <instruments command>

显然,这将要求您输入密码,但是在作为脚本运行时不能输入密码。我没有找到一种方法来指定su的密码,但是如果以root用户身份运行,则不必指定一个密码。幸运的是sudo可以通过管道接受密码:

echo <password> | sudo -S su $USER -l -c <instruments command>

如果您不想对密码进行硬编码(总是一个坏主意),您可以使用一些AppleScript来询问密码。

我在下面发布了结果脚本。将其复制到项目中的* .sh文件,并从运行脚本运行该脚本。

#!/bin/bash# This script should run all (currently only one) tests,independently from# where it is called from (terminal,or Xcode Run Script).# REQUIREMENTS: This script has to be located in the same folder as all the# UIautomation tests. Additionally,a *.tracetemplate file has to be present# in the same folder. This can be created with Instruments (Save as template...)# The following variables have to be configured:EXECUtable="TestApp.app"# Optional. If not set,you will be prompted for the password.#PASSWORD="password"# Find the test folder (this script has to be located in the same folder).ROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"# Prepare all the required args for instruments.TEMPLATE=`find $ROOT -name '*.tracetemplate'`EXECUtable=`find ~/library/Application\ Support/iPhone\ Simulator | grep "${EXECUtable}$"`SCRIPTS=`find $ROOT -name '*.Js'`# Prepare traces folderTRACES="${ROOT}/Traces/`date +%Y-%m-%d_%H-%M-%s`"mkdir -p "$TRACES"# Get the name of the user we should use to run Instruments.# Currently this is done,by getting the owner of the folder containing this script.USERname=`ls -l "${ROOT}/.." | grep \`basename "$ROOT"\` | awk '{print }'`# Bring simulator window to front. Depending on the localization,the name is different.osascript -e 'try    tell application "iOS Simulator" to activateon error    tell application "iOS-Simulator" to activateend try'# Prepare an Apple Script that promts for the password.PASS_SCRIPT="tell application \"System Events\"activatedisplay dialog \"Password for user $USER:\" default answer \"\" with hIDden answertext returned of the resultend tell"# If the password is not set directly in this script,show the password prompt window.if [ -z "$PASSWORD" ]; then    PASSWORD=`osascript -e "$PASS_SCRIPT"`fi# Run all the tests.for SCRIPT in $SCRIPTS; do    echo -e "\nRunning test script $SCRIPT"    COMMAND="instruments -t \"$TEMPLATE\" \"$EXECUtable\" -e UIASCRIPT \"$SCRIPT\""    COMMAND="echo '$PASSWORD' | sudo -S su $USER -l -c '$COMMAND'"    echo "$COMMAND"    eval $COMMAND > results.log    SCRIPTname=`basename "$SCRIPT"`    TRACEname=`echo "$SCRIPTname" | sed 's_\.Js$_.trace_g'`    mv *.trace "${TRACES}/${TRACEname}"    if [ `grep " Fail: " results.log | wc -l` -gt 0 ]; then        echo "Test ${SCRIPTname} Failed. See trace for details."        open "${TRACES}/${TRACEname}"        exit 1        break    fidonerm results.log
总结

以上是内存溢出为你收集整理的从Xcode运行UIAutomation脚本全部内容,希望文章能够帮你解决从Xcode运行UIAutomation脚本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073192.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存