我目前正致力于使用Appium为iOS构建测试自动化框架。在我的框架中,我在测试套件启动之前从代码内部启动Appium服务器(@BeforeSuite
)。
当我使用命令手动运行测试时:
mvn clean test #... and so on
Appium能够启动模拟器并正常启动测试。但是当我使用Jenkins开始测试时,他们的目标和选项与终端上的相同,但它不能正常工作并停留在盯着模拟器上。
这是我的Appium服务器脚本:
#!/bin/bash
NODE='/Applications/Appium.app/Contents/Resources/node/bin/node'
APPIUM='/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js'
PORT=5000
ADDR=127.0.0.1
LOGDIR=~/log
LOGFILE=$LOGDIR/appium.log
DEVICE=$(idevice_id -l |head -1)
mkdir -p $LOGDIR
function startAppium() {
SCRIPT="$NODE $APPIUM"
SCRIPT="$SCRIPT --address $ADDR \
--port $PORT \
--native-instruments-lib \
--session-override \
--backend-retries 10 \
--debug-log-spacing \
--full-reset \
--debug-log-spacing \
--command-timeout 90 \
-g $LOGFILE \
--launch-timeout 500000"
echo "Running: $SCRIPT"
$SCRIPT >> /dev/null &
}
startAppium 2>/dev/null >>/dev/null &
sleep 5
以下是从jenkins开始尝试启动乐器时的Appium日志片段:
2016-02-25 09:56:03:175 - info: [debug] Starting instruments
2016-02-25 09:56:03:183 - info: [debug] Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
2016-02-25 09:56:03:184 - info: Launching instruments
2016-02-25 09:56:03:204 - info: [debug] Attempting to run app on iPhone 5 (9.0)
2016-02-25 09:56:03:205 - info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w "iPhone 5 (9.0)" /Users/Shared/Jenkins/AUT/iOS/Live-release.app -e UIASCRIPT "/Users/Shared/Jenkins/Library/Application Support/appium/bootstrap/bootstrap-f062718992d59810.js" -e UIARESULTSPATH /tmp/appium-instruments
2016-02-25 09:56:03:205 - info: [debug] And extra without-delay env: {}
2016-02-25 09:56:03:205 - info: [debug] And launch timeouts (in ms): {"global":500000}
2016-02-25 09:56:03:986 - info: [debug] [INST] Waiting for device to boot...
2016-02-25 09:56:34:536 - info: [debug] [INST STDERR] Instruments Usage Error : Timed out waiting for device to boot: "iPhone 5 (9.0)"
2016-02-25 09:56:34:546 - info: [debug] [INSTSERVER] Instruments exited with code 255
2016-02-25 09:56:34:546 - info: [debug] Killall instruments
2016-02-25 09:56:34:548 - info: [debug] Instruments crashed on startup
2016-02-25 09:56:34:548 - info: [debug] Attempting to retry launching instruments, this is retry #1
2016-02-25 09:56:34:549 - info: [debug] Killall iOS Simulator
2016-02-25 09:56:39:554 - info: Launching instruments
2016-02-25 09:56:39:555 - info: [debug] Attempting to run app on iPhone 5 (9.0)
...
and so on...
每次Appium尝试重启模拟器时都会输出system.log:
Feb 25 16:56:39 --- last message repeated 1 time ---
Feb 25 16:56:39 MyMac-Mac-mini.local instruments[27594]: Failed to initialize IconCache named: com.apple.iconservices with error: Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." (connection to service named com.apple.iconservices) UserInfo=0x7fc51bc29af0 {NSDebugDescription=connection to service named com.apple.iconservices}
Feb 25 16:56:39 MyMac-Mac-mini.local instruments[27594]: Error returned from iconservicesagent: Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." (connection to service named com.apple.iconservices) UserInfo=0x7fc51be0c8a0 {NSDebugDescription=connection to service named com.apple.iconservices}
Feb 25 16:56:39 MyMac-Mac-mini com.apple.xpc.launchd[1] (com.apple.StreamingUnzipService): The _DirtyJetsamPriority key is not available on this platform.
Feb 25 16:56:39 MyMac-Mac-mini com.apple.xpc.launchd[1] (com.apple.StreamingUnzipService): The _DirtyJetsamMemoryLimit key is not available on this platform.
Feb 25 16:56:39 MyMac-Mac-mini com.apple.xpc.launchd[1] (com.apple.imfoundation.IMRemoteURLConnectionAgent): The _DirtyJetsamMemoryLimit key is not available on this platform.
Feb 25 16:56:39 MyMac-Mac-mini com.apple.xpc.launchd[1] (com.apple.StreamingUnzipService): The _DirtyJetsamPriority key is not available on this platform.
Feb 25 16:56:39 MyMac-Mac-mini com.apple.xpc.launchd[1] (com.apple.StreamingUnzipService): The _DirtyJetsamMemoryLimit key is not available on this platform.
Feb 25 16:56:39 MyMac-Mac-mini.local com.apple.SecurityServer[80]: Session 100074 created
Feb 25 16:56:39 MyMac-Mac-mini.local com.apple.SecurityServer[80]: Killing auth hosts
Feb 25 16:56:39 MyMac-Mac-mini.local com.apple.SecurityServer[80]: Session 100073 destroyed
Feb 25 16:56:39 MyMac-Mac-mini.local instruments[27594]: DTServiceHubClient: connected to server (singleton pid: 27595, initial pid: 27595)
Feb 25 16:56:40 MyMac-Mac-mini.local instruments[27594]: enumerate proxied devices: true
Feb 25 16:56:40 MyMac-Mac-mini com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Caller not allowed to perform action: instruments.27594, action = service submission, code = 1: Operation not permitted, uid = 247, euid = 247, gid = 1, egid = 1, asid = 100003
Feb 25 16:56:50 MyMac-Mac-mini.local mds[61]: (DiskStore.Normal:2382) d001 1.000014
我对system.log
:Caller not allowed to perform action: instruments.27594, action = service submission, code = 1: Operation not permitted, uid = 247, euid = 247, gid = 1, egid = 1, asid = 100003
从Jenkin启动maven脚本时是否有任何不同的权限,而不是从终端?
仅供参考:Jenkins是以当前登录用户(jenkins)开始的,当我检查它时,进程所有者也是同一个用户。
我还尝试启动appium日志中提供的命令:
/Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w "iPhone 5 (9.0)" /Users/Shared/Jenkins/AUT/iOS/Live-release.app -e UIASCRIPT "/Users/Shared/Jenkins/Library/Application Support/appium/bootstrap/bootstrap-f062718992d59810.js" -e UIARESULTSPATH /tmp/appium-instruments
我已经尝试从jenkins手动运行它,并且当在终端上手动启动时,模拟器正常启动,但是当脚本从jenkins运行时它不会启动。
系统信息:
OSX 10.10.5
XCode版本:7.2
XCode命令行工具路径:/Applications/Xcode.app/Contents/Developer
工具,版本7.2(59503)
Appium版本:1.4.13(最新的Appium)
Jenkins版本:Jenkins ver。 1.634
任何线索或答案都会有所帮助。
谢谢。