0

我目前正在使用 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.logCaller 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

从 Jenkins 启动 maven 脚本时与从终端启动 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)

  • 詹金斯版本:詹金斯版本。1.634

任何线索或答案都会非常有帮助。

谢谢你。

4

0 回答 0