I am currently working on building a test automation framework for iOS using Appium. In my framework, I start the Appium server from inside the code before the test suite started (@BeforeSuite
).
When I run the test manually using command:
mvn clean test #... and so on
the Appium are able to start the simulator and start the test normally. But when I start the test using Jenkins with same goal and options like on the terminal, it's not working and stuck on staring Simulator.
here is my Appium server script:
#!/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
Here is the Appium logs snippet when starting from jenkins, when it try to start the instruments:
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...
system.log output every time Appium trying to restart the simulator:
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
I am curious about the logs on 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
Is there any different permission when starting the maven script from Jenkin than from terminal??
FYI: Jenkins are started with the current logged in user (jenkins), and the process owner when I check it is the same user too.
I have also try to start the command which provided on appium logs:
/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
I have try to run it manually and from inside jenkins too, and when started manually on terminal, the simulator started normally, but it wont boot when the script run from jenkins.
System info:
OSX 10.10.5
XCode Version: 7.2
XCode command line tools path:
/Applications/Xcode.app/Contents/Developer
instruments, version 7.2 (59503)
Appium version: 1.4.13 (latest Appium)
Jenkins Version: Jenkins ver. 1.634
Any clue or answer will really helpful.
Thank you.