From 7d06d5181ff1c6dc0dd8887dc6915feb5d48dc6c Mon Sep 17 00:00:00 2001 From: idmcloud Date: Thu, 15 Dec 2022 22:47:51 +0300 Subject: [PATCH 01/31] #142: added explicit version we need for go-ios utility: 1.0.98+ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95c4d4a..b8323ff 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Feel free to support the development with a [**donation**](https://www.paypal.co * Install jq `brew install jq` * Install cmake to be able to compile jpeg-turbo: https://cmake.org/install -* Download go ios utility [go-ios-mac.zip](https://github.com/danielpaulus/go-ios/releases/latest/download/go-ios-mac.zip) and put into `/usr/local/bin` +* Download v1.0.98+ go ios utility [go-ios-mac.zip](https://github.com/danielpaulus/go-ios/releases/download/v1.0.98/go-ios-mac.zip) and put into `/usr/local/bin` ## iOS-agent setup * Clone mcloud-ios repo From 60e750d0ba3982c89e9870ada70894b64d14e4f7 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Fri, 16 Dec 2022 00:27:08 +0300 Subject: [PATCH 02/31] #144: started ios forwarding for physical devices --- zebrunner.sh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index 8c1b43e..bca4599 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -459,23 +459,31 @@ export SIMULATORS=${metaDataFolder}/simulators.txt -scheme $scheme -destination id=$udid USE_PORT=$WDA_PORT MJPEG_SERVER_PORT=$MJPEG_PORT test > "${WDA_LOG}" 2>&1 & verifyWDAStartup "${WDA_LOG}" 300 >> "${WDA_LOG}" - if [[ $? = 0 ]]; then - # WDA was started successfully! - # parse ip address from log file line: - # 2020-07-13 17:15:15.295128+0300 WebDriverAgentRunner-Runner[5660:22940482] ServerURLHere->http://192.168.88.127:20001<-ServerURLHere - - WDA_HOST=`grep "ServerURLHere->" "${WDA_LOG}" | cut -d ':' -f 5` - # remove forward slashes - WDA_HOST="${WDA_HOST//\//}" - # put IP address into the metadata file - echo "export WDA_HOST=${WDA_HOST}" > ${WDA_ENV} - echo "export WDA_PORT=${WDA_PORT}" >> ${WDA_ENV} - echo "export MJPEG_PORT=${MJPEG_PORT}" >> ${WDA_ENV} - else + if [[ ! $? = 0 ]]; then echo "WDA is not started successfully!" rm -fv "${WDA_ENV}" stop-wda $udid + return 0 fi + + # WDA was started successfully! + # parse ip address from log file line: + # 2020-07-13 17:15:15.295128+0300 WebDriverAgentRunner-Runner[5660:22940482] ServerURLHere->http://192.168.88.127:20001<-ServerURLHere + + WDA_HOST=`grep "ServerURLHere->" "${WDA_LOG}" | cut -d ':' -f 5` + # remove forward slashes + WDA_HOST="${WDA_HOST//\//}" + # put IP address into the metadata file + + #echo "export WDA_HOST=${WDA_HOST}" > ${WDA_ENV} + if [ -n "$device" ]; then + # start proxy forwarding for physical devices + ios forward $WDA_PORT $WDA_PORT --udid=$udid & + fi + + echo "export WDA_HOST=localhost" > ${WDA_ENV} + echo "export WDA_PORT=${WDA_PORT}" >> ${WDA_ENV} + echo "export MJPEG_PORT=${MJPEG_PORT}" >> ${WDA_ENV} } stop() { From b7cb47b14a72a47e49e1a5c689680662bbf8f5c5 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Fri, 16 Dec 2022 19:22:43 +0300 Subject: [PATCH 03/31] updated readme aking patch appium as obligatory process --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8323ff..16f2a36 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Phone_X1 | 7643aa9bd1638255f48ca6beac4285cae4f6454g | 4842 | 20011 | 200 * Setup user [auto-login](https://support.apple.com/en-us/HT201476) for your current user to enable LaunchAgents loading on reboot -### Patch appium to enable video recordings +### Patch appium * Clone Zebrunner Appium and patch sources: ``` git clone https://github.com/zebrunner/appium.git From fe26ff09c6d5d7923bbed6102929d91ae7761ace Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 17 Dec 2022 20:09:52 +0300 Subject: [PATCH 04/31] refactored zebrunner.sh --- zebrunner.sh | 344 +++++++++++++++++++++++---------------------------- 1 file changed, 157 insertions(+), 187 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index bca4599..31422bb 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -3,7 +3,6 @@ BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd ${BASEDIR} -MCLOUD_SERVICE=com.zebrunner.mcloud export CHECK_APP_SIZE_OPTIONALLY=true if [ -f backup/settings.env ]; then @@ -48,11 +47,11 @@ export SIMULATORS=${metaDataFolder}/simulators.txt print_banner # software prerequisites check like appium, xcode etc - which ios-deploy > /dev/null - if [ ! $? -eq 0 ]; then - echo_warning "Unable to proceed as ios-deploy utility is missed!" - exit -1 - fi + #which ios-deploy > /dev/null + #if [ ! $? -eq 0 ]; then + # echo_warning "Unable to proceed as ios-deploy utility is missed!" + # exit -1 + #fi which xcodebuild > /dev/null if [ ! $? -eq 0 ]; then @@ -190,7 +189,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo echo "Pull STF updates:" if [ ! -d stf ]; then - git clone -b 2.3 --single-branch https://github.com/zebrunner/stf.git + git clone -b develop --single-branch https://github.com/zebrunner/stf.git cd stf else cd stf @@ -207,14 +206,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt fi cd "${BASEDIR}" - # setup LaunchAgents - if [ ! -d $HOME/Library/LaunchAgents ]; then - mkdir -p $HOME/Library/LaunchAgents - fi - cp LaunchAgents/syncZebrunner.plist $HOME/Library/LaunchAgents/syncZebrunner.plist - replace $HOME/Library/LaunchAgents/syncZebrunner.plist "working_dir_value" "${BASEDIR}" - replace $HOME/Library/LaunchAgents/syncZebrunner.plist "user_value" "$USER" - echo "" echo_warning "Make sure to register your devices and simulators in devices.txt!" @@ -246,8 +237,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt rm .env rm backup/settings.env - rm -f $HOME/Library/LaunchAgents/syncZebrunner.plist - echo "Removing devices metadata and STF" rm -rf stf rm -f ./metaData/*.env @@ -263,33 +252,56 @@ export SIMULATORS=${metaDataFolder}/simulators.txt print_banner + # unblock all devices for automatic startup + rm -rf ./tmp/frozen* + + devicesFile=${metaDataFolder}/connectedDevices.txt +# ios listen > ${connectedDevices} & +# + echo "#TODO: implement start by udid using whitelisted devices.txt " +# # verify one by one connected devices and authorized simulators +# while read -r line +# do +# udid=`echo $line | cut -d '|' -f ${udid_position}` +# #to trim spaces around. Do not remove! +# udid=$(echo $udid) +# #echo "udid: $udid" +# if [[ "$udid" = "UDID" ]]; then +# continue +# fi +# if [[ -d ./tmp/frozen-$udid ]]; then +# continue +# fi +# +# start-device $udid +# done < ${devices} + } + + start-device() { + if [ ! -f backup/settings.env ]; then + echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" + echo_telegram + exit -1 + fi + + print_banner + udid=$1 - if [ ! -z $udid ]; then - # unblock this particular device from automatic startup - rm -rf ./tmp/frozen-$udid + # unblock this particular device from automatic startup + rm -rf ./tmp/frozen-$udid + + . ./configs/getDeviceArgs.sh $udid - . ./configs/getDeviceArgs.sh $udid + if [ -n "$physical" ]; then echo "Starting MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." start-wda $udid start-appium $udid start-stf $udid - return 0 + else + echo "No sense to start services for unavailable device: $name; udid: $udud"" fi - - # unblock all devices for automatic startup - rm -rf ./tmp/frozen* - - load - echo "Starting MCloud services..." - # initiate kickstart of the syncZebrunner without any pause. It should execute start-services function asap - launchctl kickstart gui/$UID/$MCLOUD_SERVICE - echo "Use 'tail -f ./logs/agents.log' to control startup process." } - start-services() { - syncDevices - syncServices - } start-appium() { udid=$1 @@ -363,7 +375,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt --boot-complete-timeout 60000 --mute-master never \ --connect-app-dealer tcp://${STF_MASTER_HOST}:7160 --connect-dev-dealer tcp://${STF_MASTER_HOST}:7260 \ --wda-host ${WDA_HOST} --wda-port ${WDA_PORT} \ - --appium-port ${appium_port} \ --connect-sub tcp://${STF_MASTER_HOST}:7250 --connect-push tcp://${STF_MASTER_HOST}:7270 --no-cleanup >> "${STF_LOG}" 2>&1 & } @@ -436,27 +447,38 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid - #backup current wda log to be able to analyze failures if any - if [[ -f "${WDA_LOG}" ]]; then - mv "${WDA_LOG}" "logs/backup/wda_${name}_`date +"%T"`.log" - fi - echo Starting WDA: ${name}, udid: ${udid}, WDA_PORT: ${WDA_PORT}, MJPEG_PORT: ${MJPEG_PORT} echo "Use 'tail -f ./logs/wda_${name}.log' to see WDA startup logs" scheme=WebDriverAgentRunner - if [ "$DEVICETYPE" == "tvOS" ]; then - scheme=WebDriverAgentRunner_tvOS - fi + #if [ "$DEVICETYPE" == "tvOS" ]; then + # scheme=WebDriverAgentRunner_tvOS + #fi - if [ ! -d "${APPIUM_HOME}/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj" ]; then - echo_warning "${APPIUM_HOME}/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj is missed!" - return 0 - fi + if [ -n "$physical" ]; then + #TODO: move install WDA ipa onto the setup state +# ios image auto --basedir=./DeveloperDiskImages --udid=$DEVICE_UDID +# echo "[$(date +'%d/%m/%Y %H:%M:%S')] Installing WDA application on device" +# #TODO: use path to ipa from env var! +# ios install --path=./WebDriverAgent.ipa --udid=$DEVICE_UDID - nohup /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project ${APPIUM_HOME}/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj \ - -derivedDataPath "${BASEDIR}/tmp/DerivedData/${udid}" \ - -scheme $scheme -destination id=$udid USE_PORT=$WDA_PORT MJPEG_SERVER_PORT=$MJPEG_PORT test > "${WDA_LOG}" 2>&1 & +# echo "[$(date +'%d/%m/%Y %H:%M:%S')] Killing existing WebDriverAgent application if any" +# ios kill $WDA_BUNDLEID --udid=$udid > /dev/null 2>&1 + + #Start the WDA service on the device using the WDA bundleId + echo "[$(date +'%d/%m/%Y %H:%M:%S')] Starting WebDriverAgent application on port $WDA_PORT" + ios runwda --bundleid=$WDA_BUNDLEID --testrunnerbundleid=$WDA_BUNDLEID --xctestconfig=WebDriverAgentRunner.xctest \ + --env USE_PORT=$WDA_PORT --env MJPEG_SERVER_PORT=$MJPEG_PORT --env UITEST_DISABLE_ANIMATIONS=YES --udid $udid > "${WDA_LOG}" 2>&1 & + else + #TODO: investigate an option to install from WebDriverAgent.ipa using `xcrun simctl install ${udid} *.app`!!! + #for simulators continue to build WDA + + export SIMCTL_CHILD_USE_PORT=$WDA_PORT + export SIMCTL_CHILD_MJPEG_SERVER_PORT=$MJPEG_PORT + export SIMCTL_CHILD_UITEST_DISABLE_ANIMATIONS=YES + + xcrun simctl launch --console --terminate-running-process ${udid} com.facebook.WebDriverAgentRunner.xctrunner > "${WDA_LOG}" 2>&1 & + fi verifyWDAStartup "${WDA_LOG}" 300 >> "${WDA_LOG}" if [[ ! $? = 0 ]]; then @@ -466,24 +488,19 @@ export SIMULATORS=${metaDataFolder}/simulators.txt return 0 fi - # WDA was started successfully! - # parse ip address from log file line: - # 2020-07-13 17:15:15.295128+0300 WebDriverAgentRunner-Runner[5660:22940482] ServerURLHere->http://192.168.88.127:20001<-ServerURLHere - - WDA_HOST=`grep "ServerURLHere->" "${WDA_LOG}" | cut -d ':' -f 5` - # remove forward slashes - WDA_HOST="${WDA_HOST//\//}" - # put IP address into the metadata file - - #echo "export WDA_HOST=${WDA_HOST}" > ${WDA_ENV} - if [ -n "$device" ]; then - # start proxy forwarding for physical devices - ios forward $WDA_PORT $WDA_PORT --udid=$udid & + if [ -n "$physical" ]; then + # #148: ios: reuse proxy for redirecting wda requests through appium container + ios forward $WDA_PORT $WDA_PORT --udid=$udid > /dev/null 2>&1 & + ios forward $MJPEG_PORT $MJPEG_PORT --udid=$udid > /dev/null 2>&1 & fi - echo "export WDA_HOST=localhost" > ${WDA_ENV} + echo "export WDA_HOST=${WDA_HOST}" > ${WDA_ENV} echo "export WDA_PORT=${WDA_PORT}" >> ${WDA_ENV} echo "export MJPEG_PORT=${MJPEG_PORT}" >> ${WDA_ENV} + + #TODO: implement recursive restart after wda crash + #nc localhost $WDA_PORT + #nohup ./configs/check-wda.sh $udid & } stop() { @@ -493,30 +510,12 @@ export SIMULATORS=${metaDataFolder}/simulators.txt exit -1 fi - udid=$1 - if [ ! -z $udid ]; then - . ./configs/getDeviceArgs.sh $udid - echo "Stopping MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." - stop-stf $udid - stop-appium $udid - stop-wda $udid - - mkdir -p ./tmp/frozen-$udid - - return 0 - fi - - echo "Stopping MCloud services..." - launchctl list $MCLOUD_SERVICE > /dev/null 2>&1 - if [ $? -eq 0 ]; then - unload - fi + export pids=`ps -eaf | grep ios | grep 'listen' | grep -v grep | awk '{ print $2 }'` + kill_processes $pids - stop-stf - stop-appium - stop-wda + echo "#TODO: implement stop based on devices.txt" pkill -f zebrunner.sh # clean logs @@ -525,6 +524,24 @@ export SIMULATORS=${metaDataFolder}/simulators.txt rm -fv ./logs/backup/*.log } + stop-device() { + if [ ! -f backup/settings.env ]; then + echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" + echo_telegram + exit -1 + fi + + udid=$1 + . ./configs/getDeviceArgs.sh $udid + echo "Stopping MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." + stop-stf $udid + stop-appium $udid + stop-wda $udid + + mkdir -p ./tmp/frozen-$udid + } + + stop-wda() { if [ ! -f backup/settings.env ]; then echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" @@ -534,17 +551,26 @@ export SIMULATORS=${metaDataFolder}/simulators.txt udid=$1 #echo udid: $udid - if [ "$udid" != "" ]; then - export pids=`ps -eaf | grep ${udid} | grep xcodebuild | grep 'WebDriverAgent' | grep -v grep | grep -v stop-wda | awk '{ print $2 }'` - . ./configs/getDeviceArgs.sh $udid - rm -fv "${WDA_ENV}" + + if [ -n "$physical" ]; then + ios kill $WDA_BUNDLEID --udid=$udid + # ios runwda --bundleid=com.facebook.WebDriverAgentRunner.xctrunner --testrunnerbundleid=com.facebook.WebDriverAgentRunner.xctrunner --xctestconfig=WebDriverAgentRunner.xctest --env USE_PORT= --env UITEST_DISABLE_ANIMATIONS=YES --udid + export pids=`ps -eaf | grep ${udid} | grep ios | grep 'runwda' | grep $WDA_PORT | grep -v grep | awk '{ print $2 }'` + echo "ios ruwda pid: $pids" + kill_processes $pids + + # kill ios forward proxy requests + export pids=`ps -eaf | grep ${udid} | grep ios | grep 'forward' | grep -v grep | awk '{ print $2 }'` + #echo "ios forward pid: $pids" + kill_processes $pids else - export pids=`ps -eaf | grep xcodebuild | grep 'WebDriverAgent' | grep -v grep | grep -v stop-wda | awk '{ print $2 }'` - rm -fv ${metaDataFolder}/*.env + xcrun simctl terminate $udid com.facebook.WebDriverAgentRunner.xctrunner fi - #echo pids: $pids - kill_processes $pids + . ./configs/getDeviceArgs.sh $udid + rm -fv "${WDA_ENV}" + } stop-stf() { @@ -587,56 +613,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt kill_processes $pids } - down() { - if [ ! -f backup/settings.env ]; then - echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" - echo_telegram - exit -1 - fi - - udid=$1 - if [ ! -z $udid ]; then - . ./configs/getDeviceArgs.sh $udid - stop $udid - - # clean metadata - echo "Removing temp Appium/WebDriverAgent data for $udid" - rm -rf ./tmp/AppiumData/$udid - rm -rf ./tmp/DerivedData/$udid - - mkdir -p ./tmp/frozen-$udid - - return 0 - fi - - - stop - - # clean metadata - echo "Removing temp Appium/WebDriverAgent data..." - rm -rf ./tmp/* - } - - load() { - launchctl list $MCLOUD_SERVICE > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo_warning "syncZebrunner services already loaded!" - else - echo "Loading syncZebrunner services..." - launchctl load $HOME/Library/LaunchAgents/syncZebrunner.plist - fi - } - - unload() { - launchctl list $MCLOUD_SERVICE > /dev/null 2>&1 - if [ ! $? -eq 0 ]; then - echo_warning "syncZebrunner services already unloaded!" - else - echo "Unloading syncZebrunner services..." - launchctl unload $HOME/Library/LaunchAgents/syncZebrunner.plist - fi - } - status() { if [ ! -f backup/settings.env ]; then echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" @@ -645,14 +621,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt fi echo - launchctl list $MCLOUD_SERVICE > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "syncZebrunner services status - LOADED" - else - echo "syncZebrunner services status - UNLOADED" - fi - echo - echo "TODO: #78 implement extended status call for iOS devices and simulators" } @@ -667,7 +635,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt cp .env backup/.env cp backup/settings.env backup/settings.env.bak cp devices.txt backup/devices.txt - cp $HOME/Library/LaunchAgents/syncZebrunner.plist backup/syncZebrunner.plist cp ${SIMULATORS} ${SIMULATORS}.bak cp -R stf stf.bak @@ -692,11 +659,10 @@ export SIMULATORS=${metaDataFolder}/simulators.txt cp backup/.env .env cp backup/settings.env.bak backup/settings.env - down + stop echo "Starting Devices Farm iOS agent restore..." cp backup/devices.txt devices.txt - cp backup/syncZebrunner.plist $HOME/Library/LaunchAgents/syncZebrunner.plist cp ${SIMULATORS}.bak ${SIMULATORS} rm -rf stf @@ -709,7 +675,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt if [[ $? -eq 1 ]]; then start fi - } version() { @@ -789,7 +754,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt STARTUP_LOG=$1 STARTUP_COUNTER=$2 - STARTUP_INDICATOR="ServerURLHere->" + STARTUP_INDICATOR="ServerURLHere-" FAIL_INDICATOR=" TEST FAILED " UNSUPPORTED_INDICATOR="Unable to find a destination matching the provided destination specifier" @@ -851,15 +816,12 @@ export SIMULATORS=${metaDataFolder}/simulators.txt Flags: --help | -h Print help Arguments: - status Status of the syncZebrunner services + status Status of the Device Farm iOS agent setup Setup Devices Farm iOS agent authorize-simulator Authorize whitelisted simulators - load Load LaunchAgents Zebrunner syncup services - unload Unload LaunchAgents Zebrunner syncup services start [udid] Start Device Farm iOS agent services [all or for exact device by udid] stop [udid] Stop Device Farm iOS agent services and remove logs [all or for exact device by udid] restart [udid] Restart Device Farm iOS agent services [all or for exact device by udid] - down [udid] Stop Device Farm iOS agent services, remove logs and Appium/WDA temp data [all or for exact device by udid] shutdown Destroy Device Farm iOS agent completely backup Backup Device Farm iOS agent services restore Restore Device Farm iOS agent services @@ -868,12 +830,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt exit 0 } - syncDevices() { - echo `date +"%T"` Sync Devices script started - devicesFile=${metaDataFolder}/connectedDevices.txt - /usr/local/bin/ios-deploy -c -t 3 > ${connectedDevices} - } - syncSimulators() { echo `date +"%T"` Sync Simulators script started xcrun simctl list --json > ${SIMULATORS} @@ -889,6 +845,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt udid=`echo $line | cut -d '|' -f ${udid_position}` #to trim spaces around. Do not remove! udid=$(echo $udid) + #echo "udid: $udid" if [[ "$udid" = "UDID" ]]; then continue fi @@ -901,24 +858,36 @@ export SIMULATORS=${metaDataFolder}/simulators.txt ########## WDA SERVICES ########## # unable to reuse WDA_HOST/WDA_PORT and status call as service might not be started # how about verify start-wda shell script as well? - wda=`ps -ef | grep xcodebuild | grep $udid | grep WebDriverAgent` + if [ -n "$device" ]; then + ps -ef | grep ios | grep $udid | grep forward | grep $WDA_PORT > /dev/null 2>&1 + wda=$? + else + #verify wda status on simulator via process + ps -ef | grep xcodebuild | grep $udid | grep WebDriverAgent + wda=$? + fi #echo device: $device - #echo wda: $wda + #echo wda: $wda + #wda=0 means up&running, wda=1 means no started wda - if [[ -n "$device" && -z "$wda" ]]; then + if [[ -n "$device" && $wda -eq 1 ]]; then # simultaneous WDA launch is not supported by Xcode! # error: error: accessing build database "/Users/../Library/Developer/Xcode/DerivedData/WebDriverAgent-../XCBuildData/build.db": database is locked # Possibly there are two concurrent builds running in the same filesystem location. start-wda $udid start-session $udid - elif [[ -z "$device" && -n "$wda" ]]; then + elif [[ -z "$device" && $wda -eq 0 ]]; then #double check for the case when connctedDevices.txt in sync and empty - device=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` + #device=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` + device=`ios list | grep ${udid}` if [[ -z "${device}" ]]; then echo "WDA will be stopped: ${udid} - device name : ${name}" stop-wda $udid & fi + else + #TODO: hide later + echo "WDA is ok: ${udid} - device name : ${name}" fi ########## APPIUM SERVICES ########## @@ -935,7 +904,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-appium $udid & elif [[ -z "$device" && -n "$appium" ]]; then #double check for the case when connctedDevices.txt in sync and empty - device=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` + #device=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` + device=`ios list | grep ${udid}` if [[ -z "${device}" ]]; then echo "Appium will be stopped: ${udid} - device name : ${name}" stop-appium $udid & @@ -957,7 +927,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-stf $udid & elif [[ -z "$device" && -n "$stf" ]]; then #double check for the case when connctedDevices.txt in sync and empty - device_status=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` + #device_status=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` + device_status=`ios list | grep ${udid}` if [[ -z "${device_status}" ]]; then echo "The iSTF ios-device will be stopped: ${udid} device name : ${name}" stop-stf $udid & @@ -1031,28 +1002,27 @@ case "$1" in setup) setup ;; - load) - load - ;; - unload) - unload - ;; start) - start $2 + if [ -z $2 ]; then + start + else + start-device $2 + fi ;; - start-services) - start-services + start-wda) + start-wda $2 ;; stop) - stop $2 + if [ -z $2 ]; then + stop + else + stop-device $2 + fi ;; restart) stop $2 start $2 ;; - down) - down $2 - ;; shutdown) shutdown ;; From bece99a49c2e5da146ea571bd7eeac4c15c2473b Mon Sep 17 00:00:00 2001 From: vdelendik Date: Thu, 22 Dec 2022 20:43:19 +0300 Subject: [PATCH 05/31] fixed appium patch command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8323ff..cd9da98 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Phone_X1 | 7643aa9bd1638255f48ca6beac4285cae4f6454g | 4842 | 20011 | 200 git clone https://github.com/zebrunner/appium.git cd appium export APPIUM_HOME=/usr/local/lib/node_modules/appium - cp -R -v ./files/mcloud/* ${APPIUM_HOME}/node_modules + cp -R -v ./files/mcloud/* ${APPIUM_HOME}/ ``` * Generate symlinks to shell scripts: ``` From db16401f1042301956ee16780a5262d4934099c7 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Thu, 22 Dec 2022 21:30:22 +0300 Subject: [PATCH 06/31] simplified iOS service manipulation --- .env.original | 3 + LaunchAgents/syncZebrunner.plist | 37 --------- configs/getDeviceArgs.sh | 7 +- zebrunner.sh | 128 ++++++++++++++++--------------- 4 files changed, 73 insertions(+), 102 deletions(-) delete mode 100755 LaunchAgents/syncZebrunner.plist diff --git a/.env.original b/.env.original index bde80cd..3cc1aae 100644 --- a/.env.original +++ b/.env.original @@ -18,3 +18,6 @@ AUTOMATION_NAME=XCUITest WEBSOCKET_PROTOCOL=ws WEB_PROTOCOL=http +WDA_HOST=localhost +WDA_BUNDLEID=com.facebook.WebDriverAgentRunner.xctrunner +WDA_WAIT_TIMEOUT=30 diff --git a/LaunchAgents/syncZebrunner.plist b/LaunchAgents/syncZebrunner.plist deleted file mode 100755 index 3b0186e..0000000 --- a/LaunchAgents/syncZebrunner.plist +++ /dev/null @@ -1,37 +0,0 @@ - - - - - EnvironmentVariables - - PATH - /bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin - - Label - com.zebrunner.mcloud - ProgramArguments - - ./zebrunner.sh - start-services - - WorkingDirectory - working_dir_value - UserName - user_value - KeepAlive - - - AbandonProcessGroup - - - StartInterval - 15 - - StandardErrorPath - logs/agents.log - StandardOutPath - logs/agents.log - - - diff --git a/configs/getDeviceArgs.sh b/configs/getDeviceArgs.sh index 5cdd9b3..30f7bbc 100755 --- a/configs/getDeviceArgs.sh +++ b/configs/getDeviceArgs.sh @@ -47,17 +47,14 @@ if [ -z $proxy_port ]; then export proxy_port=9000 fi -export APPIUM_LOG="logs/appium_${name}.log" -export STF_LOG="logs/stf_${name}.log" -export WDA_LOG="logs/wda_${name}.log" +export DEVICE_LOG="logs/${name}.log" export WDA_ENV="${metaDataFolder}/${name}.env" if [ -f "${WDA_ENV}" ]; then . ${WDA_ENV} fi - -export physical=`cat ${connectedDevices} | grep $udid` +export physical=`cat ${connectedDevices} | grep $udid | grep 'Attached'` #echo physical: $physical export DEVICETYPE='Phone' diff --git a/zebrunner.sh b/zebrunner.sh index 31422bb..3807a28 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -16,10 +16,6 @@ fi export devices=${BASEDIR}/devices.txt export metaDataFolder=${BASEDIR}/metaData -if [ ! -d "${BASEDIR}/logs/backup" ]; then - mkdir -p "${BASEDIR}/logs/backup" -fi - if [ ! -d "${BASEDIR}/metaData" ]; then mkdir -p "${BASEDIR}/metaData" fi @@ -256,25 +252,22 @@ export SIMULATORS=${metaDataFolder}/simulators.txt rm -rf ./tmp/frozen* devicesFile=${metaDataFolder}/connectedDevices.txt -# ios listen > ${connectedDevices} & -# - echo "#TODO: implement start by udid using whitelisted devices.txt " -# # verify one by one connected devices and authorized simulators -# while read -r line -# do -# udid=`echo $line | cut -d '|' -f ${udid_position}` -# #to trim spaces around. Do not remove! -# udid=$(echo $udid) -# #echo "udid: $udid" -# if [[ "$udid" = "UDID" ]]; then -# continue -# fi -# if [[ -d ./tmp/frozen-$udid ]]; then -# continue -# fi -# -# start-device $udid -# done < ${devices} + ios listen > ${connectedDevices} & + + # verify one by one connected devices and authorized simulators + while read -r line + do + udid=`echo $line | cut -d '|' -f ${udid_position}` + #to trim spaces around. Do not remove! + udid=$(echo $udid) + #echo "udid: $udid" + if [[ "$udid" = "UDID" ]]; then + continue + fi + + echo "udid: $udid" + start-device $udid & + done < ${devices} } start-device() { @@ -284,21 +277,28 @@ export SIMULATORS=${metaDataFolder}/simulators.txt exit -1 fi - print_banner - udid=$1 + echo udid: $udid # unblock this particular device from automatic startup - rm -rf ./tmp/frozen-$udid . ./configs/getDeviceArgs.sh $udid - if [ -n "$physical" ]; then - echo "Starting MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." - start-wda $udid - start-appium $udid - start-stf $udid + echo "device: $device" + if [ -n "$device" ]; then + echo "Starting services for $DEVICE_UDID. Find details in logs/$DEVICE_NAME.log" + start-wda $udid > ${DEVICE_LOG} 2>&1 + if [ $? -eq 1 ]; then + echo_warning "WDA is not started for $DEVICE_NAME udid: $DEVICE_UDID!" + exit -1 + else + echo "seems like wda started!" + fi + start-appium $udid >> ${DEVICE_LOG} 2>&1 + start-stf $udid >> ${DEVICE_LOG} 2>&1 + + echo nohup ./check-device.sh $udid >> ${DEVICE_LOG} 2>&1 & else - echo "No sense to start services for unavailable device: $name; udid: $udud"" + echo "No sense to start services for unavailable device: $name; udid: $udud" fi } @@ -333,8 +333,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt --session-override \ --tmp "${BASEDIR}/tmp/AppiumData/${udid}" \ --default-capabilities \ - '{"mjpegServerPort": '${MJPEG_PORT}', "webkitDebugProxyPort": '${iwdp_port}', "clearSystemFiles": "false", "webDriverAgentUrl":"'http://${WDA_HOST}:${WDA_PORT}'", "derivedDataPath":"'${BASEDIR}/tmp/DerivedData/${udid}'", "preventWDAAttachments": "true", "simpleIsVisibleCheck": "true", "wdaLocalPort": "'$WDA_PORT'", "usePrebuiltWDA": "true", "useNewWDA": "'$newWDA'", "platformVersion": "'$PLATFORM_VERSION'", "automationName":"'${AUTOMATION_NAME}'", "deviceName":"'$name'" }' \ - --nodeconfig ./metaData/$udid.json >> "${APPIUM_LOG}" 2>&1 & + '{"mjpegServerPort": '${MJPEG_PORT}', "webkitDebugProxyPort": '${iwdp_port}', "clearSystemFiles": "false", "webDriverAgentUrl":"'http://${WDA_HOST}:${WDA_PORT}'", "preventWDAAttachments": "true", "simpleIsVisibleCheck": "true", "wdaLocalPort": "'$WDA_PORT'", "usePrebuiltWDA": "true", "useNewWDA": "'$newWDA'", "platformVersion": "'$PLATFORM_VERSION'", "automationName":"'${AUTOMATION_NAME}'", "deviceName":"'$name'" }' \ + --nodeconfig ./metaData/$udid.json & } start-stf() { @@ -375,7 +375,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt --boot-complete-timeout 60000 --mute-master never \ --connect-app-dealer tcp://${STF_MASTER_HOST}:7160 --connect-dev-dealer tcp://${STF_MASTER_HOST}:7260 \ --wda-host ${WDA_HOST} --wda-port ${WDA_PORT} \ - --connect-sub tcp://${STF_MASTER_HOST}:7250 --connect-push tcp://${STF_MASTER_HOST}:7270 --no-cleanup >> "${STF_LOG}" 2>&1 & + --connect-sub tcp://${STF_MASTER_HOST}:7250 --connect-push tcp://${STF_MASTER_HOST}:7270 --no-cleanup & } @@ -448,7 +448,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid echo Starting WDA: ${name}, udid: ${udid}, WDA_PORT: ${WDA_PORT}, MJPEG_PORT: ${MJPEG_PORT} - echo "Use 'tail -f ./logs/wda_${name}.log' to see WDA startup logs" scheme=WebDriverAgentRunner #if [ "$DEVICETYPE" == "tvOS" ]; then @@ -468,7 +467,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt #Start the WDA service on the device using the WDA bundleId echo "[$(date +'%d/%m/%Y %H:%M:%S')] Starting WebDriverAgent application on port $WDA_PORT" ios runwda --bundleid=$WDA_BUNDLEID --testrunnerbundleid=$WDA_BUNDLEID --xctestconfig=WebDriverAgentRunner.xctest \ - --env USE_PORT=$WDA_PORT --env MJPEG_SERVER_PORT=$MJPEG_PORT --env UITEST_DISABLE_ANIMATIONS=YES --udid $udid > "${WDA_LOG}" 2>&1 & + --env USE_PORT=$WDA_PORT --env MJPEG_SERVER_PORT=$MJPEG_PORT --env UITEST_DISABLE_ANIMATIONS=YES --udid $udid & else #TODO: investigate an option to install from WebDriverAgent.ipa using `xcrun simctl install ${udid} *.app`!!! #for simulators continue to build WDA @@ -477,15 +476,15 @@ export SIMULATORS=${metaDataFolder}/simulators.txt export SIMCTL_CHILD_MJPEG_SERVER_PORT=$MJPEG_PORT export SIMCTL_CHILD_UITEST_DISABLE_ANIMATIONS=YES - xcrun simctl launch --console --terminate-running-process ${udid} com.facebook.WebDriverAgentRunner.xctrunner > "${WDA_LOG}" 2>&1 & + xcrun simctl launch --console --terminate-running-process ${udid} com.facebook.WebDriverAgentRunner.xctrunner & fi - verifyWDAStartup "${WDA_LOG}" 300 >> "${WDA_LOG}" + verifyWDAStartup "${DEVICE_LOG}" ${WDA_WAIT_TIMEOUT} if [[ ! $? = 0 ]]; then echo "WDA is not started successfully!" rm -fv "${WDA_ENV}" stop-wda $udid - return 0 + return 1 fi if [ -n "$physical" ]; then @@ -498,9 +497,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo "export WDA_PORT=${WDA_PORT}" >> ${WDA_ENV} echo "export MJPEG_PORT=${MJPEG_PORT}" >> ${WDA_ENV} - #TODO: implement recursive restart after wda crash - #nc localhost $WDA_PORT - #nohup ./configs/check-wda.sh $udid & + return 0 } stop() { @@ -515,13 +512,22 @@ export SIMULATORS=${metaDataFolder}/simulators.txt export pids=`ps -eaf | grep ios | grep 'listen' | grep -v grep | awk '{ print $2 }'` kill_processes $pids - echo "#TODO: implement stop based on devices.txt" + # verify one by one connected devices and authorized simulators + while read -r line + do + udid=`echo $line | cut -d '|' -f ${udid_position}` + #to trim spaces around. Do not remove! + udid=$(echo $udid) + #echo "udid: $udid" + if [[ "$udid" = "UDID" ]]; then + continue + fi + + stop-device $udid & + done < ${devices} - pkill -f zebrunner.sh - # clean logs - echo "Removing logs..." - rm -fv ./logs/*.log - rm -fv ./logs/backup/*.log + #TODO: do we need pkill? + #pkill -f zebrunner.sh } stop-device() { @@ -533,12 +539,17 @@ export SIMULATORS=${metaDataFolder}/simulators.txt udid=$1 . ./configs/getDeviceArgs.sh $udid - echo "Stopping MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." - stop-stf $udid - stop-appium $udid - stop-wda $udid - mkdir -p ./tmp/frozen-$udid + if [ -n "$device" ]; then + echo "Stopping MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." + stop-appium $udid >> ${DEVICE_LOG} 2>&1 + stop-wda $udid >> ${DEVICE_LOG} 2>&1 + # wda should be stopped before stf to mark device disconnected asap + stop-stf $udid >> ${DEVICE_LOG} 2>&1 + else + echo "No sense to stop services for unavailable device: $name; udid: $udud" + fi + } @@ -849,9 +860,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt if [[ "$udid" = "UDID" ]]; then continue fi - if [[ -d ./tmp/frozen-$udid ]]; then - continue - fi . ${BASEDIR}/configs/getDeviceArgs.sh $udid @@ -1009,9 +1017,6 @@ case "$1" in start-device $2 fi ;; - start-wda) - start-wda $2 - ;; stop) if [ -z $2 ]; then stop @@ -1023,6 +1028,9 @@ case "$1" in stop $2 start $2 ;; + start-stf) + start-stf $2 + ;; shutdown) shutdown ;; From ddd3a60d5f16a2bce01820bab96afc740dd8eae7 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 17:06:46 +0300 Subject: [PATCH 07/31] improved start/stop logging and implemented check-device method --- zebrunner.sh | 53 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index 3807a28..fc43974 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -246,13 +246,14 @@ export SIMULATORS=${metaDataFolder}/simulators.txt exit -1 fi - print_banner + echo "Starting MCloud services..." # unblock all devices for automatic startup rm -rf ./tmp/frozen* devicesFile=${metaDataFolder}/connectedDevices.txt - ios listen > ${connectedDevices} & + #ios listen > ${connectedDevices} & + ios list > ${connectedDevices} # verify one by one connected devices and authorized simulators while read -r line @@ -265,9 +266,14 @@ export SIMULATORS=${metaDataFolder}/simulators.txt continue fi - echo "udid: $udid" start-device $udid & done < ${devices} + + wait + echo "MCloud services started." + #TODO: launch status and show healtchcheck + + #TODO: start in background check-device processes } start-device() { @@ -278,27 +284,22 @@ export SIMULATORS=${metaDataFolder}/simulators.txt fi udid=$1 - echo udid: $udid - # unblock this particular device from automatic startup . ./configs/getDeviceArgs.sh $udid - echo "device: $device" if [ -n "$device" ]; then - echo "Starting services for $DEVICE_UDID. Find details in logs/$DEVICE_NAME.log" + echo "Device: $DEVICE_NAME ($DEVICE_UDID)" start-wda $udid > ${DEVICE_LOG} 2>&1 if [ $? -eq 1 ]; then echo_warning "WDA is not started for $DEVICE_NAME udid: $DEVICE_UDID!" exit -1 - else - echo "seems like wda started!" fi start-appium $udid >> ${DEVICE_LOG} 2>&1 start-stf $udid >> ${DEVICE_LOG} 2>&1 echo nohup ./check-device.sh $udid >> ${DEVICE_LOG} 2>&1 & else - echo "No sense to start services for unavailable device: $name; udid: $udud" + echo "Device: $DEVICE_NAME ($DEVICE_UDID) is not connected!" fi } @@ -500,6 +501,26 @@ export SIMULATORS=${metaDataFolder}/simulators.txt return 0 } + check-device() { + udid=$1 + if [ "$udid" == "" ]; then + echo_warning "Unable to check WDA without device udid!" + return 0 + fi + #echo udid: $udid + + . ./configs/getDeviceArgs.sh $udid + echo "Keeping WDA MJPEG connection until it is alive..." + echo "Press Ctrl-C to stop listening" + nc localhost ${MJPEG_PORT} + echo "Connection to WDA $MJPEG_PORT is closed." + + # as only connection corrupted restart wda and stf services + echo "Restarting WDA and STF service for $name..." + start-wda $udid >> ${DEVICE_LOG} 2>&1 & + start-stf $udid >> ${DEVICE_LOG} 2>&1 & + } + stop() { if [ ! -f backup/settings.env ]; then echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" @@ -509,8 +530,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo "Stopping MCloud services..." - export pids=`ps -eaf | grep ios | grep 'listen' | grep -v grep | awk '{ print $2 }'` - kill_processes $pids + #export pids=`ps -eaf | grep ios | grep 'listen' | grep -v grep | awk '{ print $2 }'` + #kill_processes $pids # verify one by one connected devices and authorized simulators while read -r line @@ -526,6 +547,9 @@ export SIMULATORS=${metaDataFolder}/simulators.txt stop-device $udid & done < ${devices} + wait + echo "MCloud services stopped." + #TODO: do we need pkill? #pkill -f zebrunner.sh } @@ -541,7 +565,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid if [ -n "$device" ]; then - echo "Stopping MCloud services for $DEVICE_NAME udid: $DEVICE_UDID..." + echo "Device: $DEVICE_NAME ($DEVICE_UDID)" stop-appium $udid >> ${DEVICE_LOG} 2>&1 stop-wda $udid >> ${DEVICE_LOG} 2>&1 # wda should be stopped before stf to mark device disconnected asap @@ -1028,6 +1052,9 @@ case "$1" in stop $2 start $2 ;; + check-device) + check-device $2 + ;; start-stf) start-stf $2 ;; From 8297aec42f22b995793ce927f0d9c17ef90460b7 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 17:34:43 +0300 Subject: [PATCH 08/31] #78: implemented status check per device using customized /wd/hub/status-wda end point --- zebrunner.sh | 55 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index fc43974..f916828 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -246,15 +246,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt exit -1 fi - echo "Starting MCloud services..." - - # unblock all devices for automatic startup - rm -rf ./tmp/frozen* - - devicesFile=${metaDataFolder}/connectedDevices.txt - #ios listen > ${connectedDevices} & ios list > ${connectedDevices} - # verify one by one connected devices and authorized simulators while read -r line do @@ -269,10 +261,13 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-device $udid & done < ${devices} + echo "Waiting while services are up&running..." + echo + wait - echo "MCloud services started." - #TODO: launch status and show healtchcheck + echo + status #TODO: start in background check-device processes } @@ -299,7 +294,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo nohup ./check-device.sh $udid >> ${DEVICE_LOG} 2>&1 & else - echo "Device: $DEVICE_NAME ($DEVICE_UDID) is not connected!" + echo "Device: $DEVICE_NAME ($DEVICE_UDID) is disconnected!" fi } @@ -655,8 +650,42 @@ export SIMULATORS=${metaDataFolder}/simulators.txt exit -1 fi - echo - echo "TODO: #78 implement extended status call for iOS devices and simulators" + + ios list > ${connectedDevices} + # verify one by one connected devices and authorized simulators + while read -r line + do + udid=`echo $line | cut -d '|' -f ${udid_position}` + #to trim spaces around. Do not remove! + udid=$(echo $udid) + #echo "udid: $udid" + if [[ "$udid" = "UDID" ]]; then + continue + fi + + status-device $udid & + done < ${devices} + + wait + } + + status-device() { + udid=$1 + + . ./configs/getDeviceArgs.sh $udid + + if [ -n "$device" ]; then + #Hit the Appium status URL to see if it is available + if curl -Is "http://localhost:$appium_port/wd/hub/status-wda" | head -1 | grep -q '200 OK' + then + echo "$DEVICE_NAME ($DEVICE_UDID) is healthy." + else + echo "$DEVICE_NAME ($DEVICE_UDID) is unhealthy!" + fi + else + echo "$DEVICE_NAME ($DEVICE_UDID) is disconnected!" + fi + } backup() { From badb6c44b6e235f7ced970c575663eaf893cc09e Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 17:44:39 +0300 Subject: [PATCH 09/31] improved log messages a little bit --- zebrunner.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index f916828..bb0a029 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -283,7 +283,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid if [ -n "$device" ]; then - echo "Device: $DEVICE_NAME ($DEVICE_UDID)" + echo "$DEVICE_NAME ($DEVICE_UDID)" start-wda $udid > ${DEVICE_LOG} 2>&1 if [ $? -eq 1 ]; then echo_warning "WDA is not started for $DEVICE_NAME udid: $DEVICE_UDID!" @@ -294,7 +294,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo nohup ./check-device.sh $udid >> ${DEVICE_LOG} 2>&1 & else - echo "Device: $DEVICE_NAME ($DEVICE_UDID) is disconnected!" + echo "$DEVICE_NAME ($DEVICE_UDID) is disconnected!" fi } @@ -560,13 +560,13 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid if [ -n "$device" ]; then - echo "Device: $DEVICE_NAME ($DEVICE_UDID)" + echo "$DEVICE_NAME ($DEVICE_UDID)" stop-appium $udid >> ${DEVICE_LOG} 2>&1 stop-wda $udid >> ${DEVICE_LOG} 2>&1 # wda should be stopped before stf to mark device disconnected asap stop-stf $udid >> ${DEVICE_LOG} 2>&1 else - echo "No sense to stop services for unavailable device: $name; udid: $udud" + echo "$DEVICE_NAME ($DEVICE_UDID) is disconnected!" fi } @@ -880,7 +880,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt Flags: --help | -h Print help Arguments: - status Status of the Device Farm iOS agent + status [udid] Status of the Device Farm iOS agent services [all or for exact device by udid] setup Setup Devices Farm iOS agent authorize-simulator Authorize whitelisted simulators start [udid] Start Device Farm iOS agent services [all or for exact device by udid] @@ -1100,7 +1100,11 @@ case "$1" in syncSimulators ;; status) - status + if [ -z $2 ]; then + status + else + status-device $2 + fi ;; version) version From 3e100df8e420f8cc6d63c22ff8c87f72fae863cb Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 17:45:40 +0300 Subject: [PATCH 10/31] removed syncServices method --- zebrunner.sh | 99 ---------------------------------------------------- 1 file changed, 99 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index bb0a029..8327a27 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -900,105 +900,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo `date +"%T"` Sync Simulators script finished } - syncServices() { - echo `date +"%T"` Sync MCloud Services script started - - # verify one by one connected devices and authorized simulators - while read -r line - do - udid=`echo $line | cut -d '|' -f ${udid_position}` - #to trim spaces around. Do not remove! - udid=$(echo $udid) - #echo "udid: $udid" - if [[ "$udid" = "UDID" ]]; then - continue - fi - - . ${BASEDIR}/configs/getDeviceArgs.sh $udid - - ########## WDA SERVICES ########## - # unable to reuse WDA_HOST/WDA_PORT and status call as service might not be started - # how about verify start-wda shell script as well? - if [ -n "$device" ]; then - ps -ef | grep ios | grep $udid | grep forward | grep $WDA_PORT > /dev/null 2>&1 - wda=$? - else - #verify wda status on simulator via process - ps -ef | grep xcodebuild | grep $udid | grep WebDriverAgent - wda=$? - fi - - #echo device: $device - #echo wda: $wda - #wda=0 means up&running, wda=1 means no started wda - - if [[ -n "$device" && $wda -eq 1 ]]; then - # simultaneous WDA launch is not supported by Xcode! - # error: error: accessing build database "/Users/../Library/Developer/Xcode/DerivedData/WebDriverAgent-../XCBuildData/build.db": database is locked - # Possibly there are two concurrent builds running in the same filesystem location. - start-wda $udid - start-session $udid - elif [[ -z "$device" && $wda -eq 0 ]]; then - #double check for the case when connctedDevices.txt in sync and empty - #device=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` - device=`ios list | grep ${udid}` - if [[ -z "${device}" ]]; then - echo "WDA will be stopped: ${udid} - device name : ${name}" - stop-wda $udid & - fi - else - #TODO: hide later - echo "WDA is ok: ${udid} - device name : ${name}" - fi - - ########## APPIUM SERVICES ########## - appium=`ps -ef | grep ${APPIUM_HOME}/build/lib/main.js | grep $udid` - - wda=${WDA_ENV} - if [[ -n "$appium" && ! -f "$wda" ]]; then - echo "Stopping Appium process as no WebDriverAgent process detected. ${udid} device name : ${name}" - stop-appium $udid & - #continue - fi - - if [[ -n "$device" && -f "$wda" && -z "$appium" ]]; then - start-appium $udid & - elif [[ -z "$device" && -n "$appium" ]]; then - #double check for the case when connctedDevices.txt in sync and empty - #device=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` - device=`ios list | grep ${udid}` - if [[ -z "${device}" ]]; then - echo "Appium will be stopped: ${udid} - device name : ${name}" - stop-appium $udid & - fi - fi - - device="$physical$simulator" - #echo device: $device - - stf=`ps -eaf | grep ${udid} | grep 'ios-device' | grep -v grep` - wda=${WDA_ENV} - if [[ -n "$stf" && ! -f "$wda" ]]; then - echo "Stopping STF process as no WebDriverAgent process detected. ${udid} device name : ${name}" - stop-stf $udid & - #continue - fi - - if [[ -n "$device" && -f "$wda" && -z "$stf" ]]; then - start-stf $udid & - elif [[ -z "$device" && -n "$stf" ]]; then - #double check for the case when connctedDevices.txt in sync and empty - #device_status=`/usr/local/bin/ios-deploy -c -t 5 | grep ${udid}` - device_status=`ios list | grep ${udid}` - if [[ -z "${device_status}" ]]; then - echo "The iSTF ios-device will be stopped: ${udid} device name : ${name}" - stop-stf $udid & - fi - fi - - done < ${devices} - } - replace() { #TODO: https://github.com/zebrunner/zebrunner/issues/328 organize debug logging for setup/replace file=$1 From 4482958430719d5ed20029d93e6566b7358072d8 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 18:09:13 +0300 Subject: [PATCH 11/31] #128: fixed stf cloning to pull latest changes from valid release/version branch --- zebrunner.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index 8327a27..6d00738 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -184,12 +184,14 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo echo "Pull STF updates:" + stf_branch=2.4 if [ ! -d stf ]; then - git clone -b develop --single-branch https://github.com/zebrunner/stf.git + git clone https://github.com/zebrunner/stf.git cd stf + git -c advice.detachedHead=false checkout ${stf_branch} else cd stf - git pull + git pull origin ${stf_branch} fi echo From e0270f5ca7041befcbe65408b83dfe9c2d3774de Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 18:27:24 +0300 Subject: [PATCH 12/31] #150: added minimal npm version in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 515c5be..d435991 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Feel free to support the development with a [**donation**](https://www.paypal.co ## Software prerequisites * Install XCode 11.2+ +* Install npm 8.3.0 or higher + `npm install -g npm@8.3.0` * Install [nvm](https://github.com/nvm-sh/nvm) version manager > NVM required to organize automatic switch between nodes -* Using NVM install v17.1.0 for STF and the latest Appium compatible node version -* Make the Appium node as default one, for example: - `nvm alias default 17` +* Using NVM install node v17.1.0 and make it default `nvm alias default 17` * Install Appium, optionally install opencv module to be able to support [find by image](https://zebrunner.github.io/carina/automation/mobile/#how-to-use-find-by-image-strategy) strategy * Sign WebDriverAgent using your Dev Apple certificate and install WebDriverAgent on each device manually * Open in XCode APPIUM_HOME/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj From b3aa6c3388fcf5ba676cc54e588eae770bdd2cff Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 18:46:53 +0300 Subject: [PATCH 13/31] added TODO for check-device implementation --- zebrunner.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index 6d00738..b92450d 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -270,7 +270,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo status - #TODO: start in background check-device processes } start-device() { @@ -294,7 +293,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-appium $udid >> ${DEVICE_LOG} 2>&1 start-stf $udid >> ${DEVICE_LOG} 2>&1 - echo nohup ./check-device.sh $udid >> ${DEVICE_LOG} 2>&1 & + #TODO: register check-device script via LaunchAgents as we can not establish and keep mjpeg socket connection in background:( + #check-device $udid >> ${DEVICE_LOG} 2>&1 & else echo "$DEVICE_NAME ($DEVICE_UDID) is disconnected!" fi From d7c10cc98ab547eba28f68a7d519bcb3a9cd00b1 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 20:03:34 +0300 Subject: [PATCH 14/31] #151: implemented recovery using LaunchAgent scripts --- LaunchAgents/syncZebrunner.plist | 43 +++++++++++++++++++ zebrunner.sh | 71 +++++++++++++++++++++++++++++--- 2 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 LaunchAgents/syncZebrunner.plist diff --git a/LaunchAgents/syncZebrunner.plist b/LaunchAgents/syncZebrunner.plist new file mode 100644 index 0000000..4eb1199 --- /dev/null +++ b/LaunchAgents/syncZebrunner.plist @@ -0,0 +1,43 @@ + + + + + EnvironmentVariables + + PATH + /bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin + + Label + com.zebrunner.mcloud.udid_value + ProgramArguments + + ./zebrunner.sh + recover + udid_value + + WorkingDirectory + working_dir_value + UserName + user_value + KeepAlive + + SuccessfulExit + + + + RunAtLoad + + + AbandonProcessGroup + + + StartInterval + 0 + + StandardErrorPath + logs/agents.log + StandardOutPath + logs/agents.log + + diff --git a/zebrunner.sh b/zebrunner.sh index b92450d..0e70d03 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -211,6 +211,28 @@ export SIMULATORS=${metaDataFolder}/simulators.txt # export all ZBR* variables to save user input export_settings + #Configure LaunchAgent service per each device for fast recovery + while read -r line + do + udid=`echo $line | cut -d '|' -f ${udid_position}` + #to trim spaces around. Do not remove! + udid=$(echo $udid) + #echo "udid: $udid" + if [[ "$udid" = "UDID" ]]; then + continue + fi + + cp LaunchAgents/syncZebrunner.plist $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist + replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "working_dir_value" "${BASEDIR}" + replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "user_value" "$USER" + replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "udid_value" "$udid" + + #unload explicitly in advance in case it is secondary etc setup + launchctl unload $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 + launchctl load $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 + done < ${devices} + + } shutdown() { @@ -230,6 +252,23 @@ export SIMULATORS=${metaDataFolder}/simulators.txt down + # Unload ad remove customized LaunchAgents + while read -r line + do + udid=`echo $line | cut -d '|' -f ${udid_position}` + #to trim spaces around. Do not remove! + udid=$(echo $udid) + #echo "udid: $udid" + if [[ "$udid" = "UDID" ]]; then + continue + fi + + #unload explicitly in advance in case it is secondary etc setup + launchctl unload $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 + rm -f $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist + done < ${devices} + + # remove configuration files and LaunchAgents plist(s) git checkout -- devices.txt rm .env @@ -293,8 +332,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-appium $udid >> ${DEVICE_LOG} 2>&1 start-stf $udid >> ${DEVICE_LOG} 2>&1 - #TODO: register check-device script via LaunchAgents as we can not establish and keep mjpeg socket connection in background:( - #check-device $udid >> ${DEVICE_LOG} 2>&1 & else echo "$DEVICE_NAME ($DEVICE_UDID) is disconnected!" fi @@ -509,6 +546,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid echo "Keeping WDA MJPEG connection until it is alive..." echo "Press Ctrl-C to stop listening" + nc localhost ${MJPEG_PORT} echo "Connection to WDA $MJPEG_PORT is closed." @@ -518,6 +556,21 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-stf $udid >> ${DEVICE_LOG} 2>&1 & } + recover() { + udid=$1 + if [ "$udid" == "" ]; then + echo_warning "Unable to check WDA without device udid!" + return 0 + fi + #echo udid: $udid + + . ./configs/getDeviceArgs.sh $udid + echo "Recovering services for $DEVICE_NAME ($DEVICE_UDID)" + start-wda $udid >> ${DEVICE_LOG} 2>&1 & + start-appium $udid >> ${DEVICE_LOG} 2>&1 & + start-stf $udid >> ${DEVICE_LOG} 2>&1 & + } + stop() { if [ ! -f backup/settings.env ]; then echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" @@ -547,8 +600,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt wait echo "MCloud services stopped." - #TODO: do we need pkill? - #pkill -f zebrunner.sh } stop-device() { @@ -981,12 +1032,20 @@ case "$1" in fi ;; restart) - stop $2 - start $2 + if [ -z $2 ]; then + stop + start + else + stop-device $2 + start-device + fi ;; check-device) check-device $2 ;; + recover) + recover $2 + ;; start-stf) start-stf $2 ;; From 12c78ffa69e6da2b37e4e2640b5f6a001e6b7d4a Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 20:23:38 +0300 Subject: [PATCH 15/31] enable runatload back for launchagent service --- LaunchAgents/syncZebrunner.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchAgents/syncZebrunner.plist b/LaunchAgents/syncZebrunner.plist index 4eb1199..e92b74e 100644 --- a/LaunchAgents/syncZebrunner.plist +++ b/LaunchAgents/syncZebrunner.plist @@ -27,7 +27,7 @@ RunAtLoad - + AbandonProcessGroup From ec24af929739d7eeec66c0db9adb4e0295c284a4 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sat, 24 Dec 2022 20:24:08 +0300 Subject: [PATCH 16/31] added log messae about auto startup after setup --- zebrunner.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/zebrunner.sh b/zebrunner.sh index 0e70d03..d766c92 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -232,6 +232,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt launchctl load $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 done < ${devices} + echo "MCloud agent services will be started automatically soon for connected devices..." } From 74b5dc1c65aa8fc64423d1ba6299f40f523ca8f7 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:02:00 +0300 Subject: [PATCH 17/31] #154: updated readme content --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index d435991..8618ea3 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,25 @@ Feel free to support the development with a [**donation**](https://www.paypal.co * Install cmake to be able to compile jpeg-turbo: https://cmake.org/install * Download v1.0.98+ go ios utility [go-ios-mac.zip](https://github.com/danielpaulus/go-ios/releases/download/v1.0.98/go-ios-mac.zip) and put into `/usr/local/bin` +### Prepare WebDriverAgent.ipa file + +You need an Apple Developer account to sign in and build **WebDriverAgent**. + +1. Open **WebDriverAgent.xcodeproj** in Xcode. +2. Ensure a team is selected before building the application. To do this, go to *Targets* and select each target (one at a time). There should be a field for assigning team certificates to the target. +3. Remove your **WebDriverAgent** folder from *DerivedData* and run *Clean build folder* (just in case). +4. Build the application by selecting the *WebDriverAgentRunner* target and build for *Generic iOS Device*. Run *Product -> Build for testing*. This will create a *Products/Debug-iphoneos* in the specified project directory. + *Example*: **/Users//Library/Developer/Xcode/DerivedData/WebDriverAgent-dzxbpamuepiwamhdbyvyfkbecyer/Build/Products/Debug-iphoneos** +5. Go to the "Products/Debug-iphoneos" directory and run: + **mkdir Payload** +6. Copy the WebDriverAgentRunner-Runner.app to the Payload directory: + **cp -r WebDriverAgentRunner-Runner.app Payload** +7. Finally, zip up the project as an *.ipa file: + **zip -r WebDriverAgent.ipa ./Payload** + > Make sure to specify relative `./Payload` to archive only Payload folder content +8. Get the WebDriverAgent.ipa file and put it onto the mcloud-ios host + + ## iOS-agent setup * Clone mcloud-ios repo ``` From 93ce9125a25c5dec4805e0bd1038db710c0683d6 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:02:49 +0300 Subject: [PATCH 18/31] registered WebDriverAgent.ipa in ignored file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bf88033..283bd80 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ stf *.log metaData/connectedDevices.txt metaData/simulators.txt +WebDriverAgent.ipa From 7a37c1ccb6ddede4ef23fbc5ffd3a1419e21e634 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:07:35 +0300 Subject: [PATCH 19/31] moved warning about devices.txt update onto the top of setup --- zebrunner.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index d766c92..d82e92d 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -91,6 +91,9 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo_warning "Appium is not detected! Interrupt setup if you don't have it installed!" fi + echo "" + echo_warning "Make sure to register your devices and simulators in devices.txt!" + echo # load default interactive installer settings @@ -204,9 +207,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt fi cd "${BASEDIR}" - echo "" - echo_warning "Make sure to register your devices and simulators in devices.txt!" - syncSimulators # export all ZBR* variables to save user input export_settings From e3cdc163c10d6bf98beefaedfcc9f27a5c1e91c9 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:23:59 +0300 Subject: [PATCH 20/31] fixed markup language mistake --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8618ea3..ec3c61b 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You need an Apple Developer account to sign in and build **WebDriverAgent**. 2. Ensure a team is selected before building the application. To do this, go to *Targets* and select each target (one at a time). There should be a field for assigning team certificates to the target. 3. Remove your **WebDriverAgent** folder from *DerivedData* and run *Clean build folder* (just in case). 4. Build the application by selecting the *WebDriverAgentRunner* target and build for *Generic iOS Device*. Run *Product -> Build for testing*. This will create a *Products/Debug-iphoneos* in the specified project directory. - *Example*: **/Users//Library/Developer/Xcode/DerivedData/WebDriverAgent-dzxbpamuepiwamhdbyvyfkbecyer/Build/Products/Debug-iphoneos** + *Example*: **/Users/$USER/Library/Developer/Xcode/DerivedData/WebDriverAgent-dzxbpamuepiwamhdbyvyfkbecyer/Build/Products/Debug-iphoneos** 5. Go to the "Products/Debug-iphoneos" directory and run: **mkdir Payload** 6. Copy the WebDriverAgentRunner-Runner.app to the Payload directory: From 996b92fbba2ad92f6756ff87bfb71531fb2b624b Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:28:10 +0300 Subject: [PATCH 21/31] removed commented ios-deploy verifiocation --- zebrunner.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index d82e92d..d403ad7 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -43,12 +43,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt print_banner # software prerequisites check like appium, xcode etc - #which ios-deploy > /dev/null - #if [ ! $? -eq 0 ]; then - # echo_warning "Unable to proceed as ios-deploy utility is missed!" - # exit -1 - #fi + #TODO: seema like not needed if ipa/app build on different hosts which xcodebuild > /dev/null if [ ! $? -eq 0 ]; then echo_warning "Unable to proceed as XCode application is missed!" From 7323be804bee1184b62db8018aefe20f99abea0e Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:51:47 +0300 Subject: [PATCH 22/31] fixed devices.txt parser for disconnected devices --- configs/getDeviceArgs.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/configs/getDeviceArgs.sh b/configs/getDeviceArgs.sh index 30f7bbc..b532a72 100755 --- a/configs/getDeviceArgs.sh +++ b/configs/getDeviceArgs.sh @@ -54,6 +54,11 @@ if [ -f "${WDA_ENV}" ]; then . ${WDA_ENV} fi +#reset to generate new value per udid +export physical= +export simulator= + + export physical=`cat ${connectedDevices} | grep $udid | grep 'Attached'` #echo physical: $physical From 73d8c773cfc61f7eb5d6e1cd931bc8e38974714f Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 16:52:41 +0300 Subject: [PATCH 23/31] #154: automated device preparation steps for physical devices --- backup/settings.env.original | 1 + zebrunner.sh | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/backup/settings.env.original b/backup/settings.env.original index 945c25c..56cea18 100644 --- a/backup/settings.env.original +++ b/backup/settings.env.original @@ -4,4 +4,5 @@ ZBR_MCLOUD_PORT=80 ZBR_MCLOUD_NODE_HOSTNAME= ZBR_MCLOUD_NODE_NAME=mcloud-ios ZBR_MCLOUD_APPIUM_PATH=/usr/local/lib/node_modules/appium +ZBR_MCLOUD_WDA_PATH=./WebDriverAgent.ipa diff --git a/zebrunner.sh b/zebrunner.sh index d403ad7..aabac20 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -207,6 +207,18 @@ export SIMULATORS=${metaDataFolder}/simulators.txt # export all ZBR* variables to save user input export_settings + + local is_confirmed=0 + while [[ $is_confirmed -eq 0 ]]; do + read -p "WebDriverAgent.ipa path [$ZBR_MCLOUD_WDA_PATH]: " local_value + if [[ ! -z $local_value ]]; then + ZBR_MCLOUD_WDA_PATH=$local_value + fi + confirm "WebDriverAgent.ipa: $ZBR_MCLOUD_WDA_PATH" "Continue?" "y" + is_confirmed=$? + done + export ZBR_MCLOUD_WDA_PATH=$ZBR_MCLOUD_WDA_PATH + #Configure LaunchAgent service per each device for fast recovery while read -r line do @@ -218,6 +230,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt continue fi + prepare-device $udid + cp LaunchAgents/syncZebrunner.plist $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "working_dir_value" "${BASEDIR}" replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "user_value" "$USER" @@ -228,6 +242,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt launchctl load $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 done < ${devices} + echo echo "MCloud agent services will be started automatically soon for connected devices..." } @@ -277,6 +292,38 @@ export SIMULATORS=${metaDataFolder}/simulators.txt rm -f ./metaData/*.json } + prepare-device() { + udid=$1 + + . ./configs/getDeviceArgs.sh $udid + + # mount developer images, unistall existing wda, install fresh one. start, test and stop + # for simulators informa about prerequisites to build and install wda manually + + if [ -n "$device" ]; then + if [ -n "$physical" ]; then + echo "$DEVICE_NAME ($DEVICE_UDID)" + ios image auto --udid=$udid + ios uninstall $WDA_BUNDLEID --udid=$udid + ios install --path=$ZBR_MCLOUD_WDA_PATH --udid=$udid + + start-wda $udid > ${DEVICE_LOG} 2>&1 + if [ $? -eq 0 ]; then + echo "$DEVICE_NAME ($DEVICE_UDID): WebDriverAgent is OK." + else + echo_warning "$DEVICE_NAME ($DEVICE_UDID): WebDriverAgent is not started! Analyze ${DEVICE_LOG} for details." + return -1 + fi + stop-wda $udid > ${DEVICE_LOG} 2>&1 + else + echo_warning "$DEVICE_NAME ($DEVICE_UDID): WebDriverAgent on simulator should be installed in advance via XCode!" + fi + else + echo_warning "$DEVICE_NAME ($DEVICE_UDID) is disconnected now! Connect and repeat setup." + fi + + } + start() { if [ ! -f backup/settings.env ]; then echo_warning "You have to setup services in advance using: ./zebrunner.sh setup" @@ -945,9 +992,11 @@ export SIMULATORS=${metaDataFolder}/simulators.txt } syncSimulators() { + echo echo `date +"%T"` Sync Simulators script started xcrun simctl list --json > ${SIMULATORS} echo `date +"%T"` Sync Simulators script finished + echo } replace() { From 22ac9c0cf7990e4768d15fb784a964b865588bf4 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 17:00:32 +0300 Subject: [PATCH 24/31] improved readme setup steps and removed authorize-simulator separate action --- README.md | 57 ++++++++++++++++++++++++++-------------------------- zebrunner.sh | 4 ---- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index ec3c61b..5c7631c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Feel free to support the development with a [**donation**](https://www.paypal.co * Install [nvm](https://github.com/nvm-sh/nvm) version manager > NVM required to organize automatic switch between nodes * Using NVM install node v17.1.0 and make it default `nvm alias default 17` -* Install Appium, optionally install opencv module to be able to support [find by image](https://zebrunner.github.io/carina/automation/mobile/#how-to-use-find-by-image-strategy) strategy +* Install Appium v1.22.3, optionally install opencv module to be able to support [find by image](https://zebrunner.github.io/carina/automation/mobile/#how-to-use-find-by-image-strategy) strategy * Sign WebDriverAgent using your Dev Apple certificate and install WebDriverAgent on each device manually * Open in XCode APPIUM_HOME/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj * Choose WebDriverAgentRunner and your device(s) @@ -29,6 +29,28 @@ Feel free to support the development with a [**donation**](https://www.paypal.co * Install cmake to be able to compile jpeg-turbo: https://cmake.org/install * Download v1.0.98+ go ios utility [go-ios-mac.zip](https://github.com/danielpaulus/go-ios/releases/download/v1.0.98/go-ios-mac.zip) and put into `/usr/local/bin` +### Patch appium +* Clone Zebrunner Appium and patch sources: + ``` + git clone https://github.com/zebrunner/appium.git + cd appium + export APPIUM_HOME=/usr/local/lib/node_modules/appium + cp -R -v ./files/mcloud/* ${APPIUM_HOME}/ + ``` +* Generate symlinks to shell scripts: + ``` + ln -s $HOME/tools/appium/files/concat-video-recordings.sh /opt/ + ln -s $HOME/tools/appium/files/reset-logs.sh /opt/ + ln -s $HOME/tools/appium/files/start-capture-artifacts.sh /opt/ + ln -s $HOME/tools/appium/files/stop-capture-artifacts.sh /opt/ + ln -s $HOME/tools/appium/files/upload-artifacts.sh /opt/ + ``` +* Install aws cli: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +* Configure aws using your s3 access and secret keys, region etc + ``` + aws configure + ``` + ### Prepare WebDriverAgent.ipa file You need an Apple Developer account to sign in and build **WebDriverAgent**. @@ -47,7 +69,6 @@ You need an Apple Developer account to sign in and build **WebDriverAgent**. > Make sure to specify relative `./Payload` to archive only Payload folder content 8. Get the WebDriverAgent.ipa file and put it onto the mcloud-ios host - ## iOS-agent setup * Clone mcloud-ios repo ``` @@ -64,6 +85,8 @@ Phone_X1 | 7643aa9bd1638255f48ca6beac4285cae4f6454g | 4842 | 20011 | 200 > Specify unique port numbers per each service. Those ports should be accessible from MCloud master host +* Reboot physical device and connect to your MacOS server. + * Execute setup procedure ``` ./zebrunner.sh setup @@ -71,36 +94,12 @@ Phone_X1 | 7643aa9bd1638255f48ca6beac4285cae4f6454g | 4842 | 20011 | 200 * Provide the required arguments during the setup -* Important! Everytime you create new Simulator(s) via XCode, you have to add a new line into devices.txt to whitelist and run `authorize-simulator` command to authorize -``` -./zebrunner.sh authorize-simulator -``` - > It is enough to run `./zebrunner.sh authorize-simulator` command at once after generating multiple simulators +* Important! Everytime you create new Simulator(s) via XCode, you have to add a new line into devices.txt to whitelist and repeat `./zebrunner.sh setup` command to authorize. + > It is enough to execute setup command at once after generating multiple simulators * Setup user [auto-login](https://support.apple.com/en-us/HT201476) for your current user to enable LaunchAgents loading on reboot -### Patch appium -* Clone Zebrunner Appium and patch sources: - ``` - git clone https://github.com/zebrunner/appium.git - cd appium - export APPIUM_HOME=/usr/local/lib/node_modules/appium - cp -R -v ./files/mcloud/* ${APPIUM_HOME}/ - ``` -* Generate symlinks to shell scripts: - ``` - ln -s $HOME/tools/appium/files/concat-video-recordings.sh /opt/ - ln -s $HOME/tools/appium/files/reset-logs.sh /opt/ - ln -s $HOME/tools/appium/files/start-capture-artifacts.sh /opt/ - ln -s $HOME/tools/appium/files/stop-capture-artifacts.sh /opt/ - ln -s $HOME/tools/appium/files/upload-artifacts.sh /opt/ - ``` -* Install aws cli: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html -* Configure aws using your s3 access and secret keys, region etc - ``` - aws configure - ``` -* Restart services using `./zebrunner.sh restart` +* Execute `./zebrunner.sh` to see all available actions ## Documentation and free support * [Zebrunner PRO](https://zebrunner.com) diff --git a/zebrunner.sh b/zebrunner.sh index aabac20..0c53cdd 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -979,7 +979,6 @@ export SIMULATORS=${metaDataFolder}/simulators.txt Arguments: status [udid] Status of the Device Farm iOS agent services [all or for exact device by udid] setup Setup Devices Farm iOS agent - authorize-simulator Authorize whitelisted simulators start [udid] Start Device Farm iOS agent services [all or for exact device by udid] stop [udid] Stop Device Farm iOS agent services and remove logs [all or for exact device by udid] restart [udid] Restart Device Farm iOS agent services [all or for exact device by udid] @@ -1104,9 +1103,6 @@ case "$1" in restore) restore ;; - authorize-simulator) - syncSimulators - ;; status) if [ -z $2 ]; then status From ac1692c8f4326e7616e69c3f19551b87bcf163a1 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Sun, 25 Dec 2022 17:04:10 +0300 Subject: [PATCH 25/31] unloaded recovery script in advance during secondary etc setup to avoid automatic restarts --- zebrunner.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index 0c53cdd..985b33e 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -230,6 +230,10 @@ export SIMULATORS=${metaDataFolder}/simulators.txt continue fi + if [ -r $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist ]; then + # unload explicitly in advance in case it is secondary etc setup + launchctl unload $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 + fi prepare-device $udid cp LaunchAgents/syncZebrunner.plist $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist @@ -237,8 +241,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "user_value" "$USER" replace $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist "udid_value" "$udid" - #unload explicitly in advance in case it is secondary etc setup - launchctl unload $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 + # load syncup script to restart service and recover device at any failure launchctl load $HOME/Library/LaunchAgents/syncZebrunner_$udid.plist > /dev/null 2>&1 done < ${devices} @@ -304,6 +307,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt if [ -n "$physical" ]; then echo "$DEVICE_NAME ($DEVICE_UDID)" ios image auto --udid=$udid + stop-wda $udid ios uninstall $WDA_BUNDLEID --udid=$udid ios install --path=$ZBR_MCLOUD_WDA_PATH --udid=$udid From 35035f26a3648162f9e990db64a861e82cb9f827 Mon Sep 17 00:00:00 2001 From: kolyakrasnik Date: Sun, 25 Dec 2022 17:15:48 +0300 Subject: [PATCH 26/31] improved log messages during setup --- zebrunner.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zebrunner.sh b/zebrunner.sh index 985b33e..ba8ccef 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -311,11 +311,11 @@ export SIMULATORS=${metaDataFolder}/simulators.txt ios uninstall $WDA_BUNDLEID --udid=$udid ios install --path=$ZBR_MCLOUD_WDA_PATH --udid=$udid - start-wda $udid > ${DEVICE_LOG} 2>&1 + start-wda $udid if [ $? -eq 0 ]; then echo "$DEVICE_NAME ($DEVICE_UDID): WebDriverAgent is OK." else - echo_warning "$DEVICE_NAME ($DEVICE_UDID): WebDriverAgent is not started! Analyze ${DEVICE_LOG} for details." + echo_warning "$DEVICE_NAME ($DEVICE_UDID): WebDriverAgent is not started!" return -1 fi stop-wda $udid > ${DEVICE_LOG} 2>&1 From f8ff400be07d9e2ee0b32a4eca798cee5c850291 Mon Sep 17 00:00:00 2001 From: kolyakrasnik Date: Sun, 25 Dec 2022 17:21:07 +0300 Subject: [PATCH 27/31] fixed attached status detection using ios list command output --- configs/getDeviceArgs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/getDeviceArgs.sh b/configs/getDeviceArgs.sh index b532a72..f889b40 100755 --- a/configs/getDeviceArgs.sh +++ b/configs/getDeviceArgs.sh @@ -59,7 +59,7 @@ export physical= export simulator= -export physical=`cat ${connectedDevices} | grep $udid | grep 'Attached'` +export physical=`cat ${connectedDevices} | grep $udid` #echo physical: $physical export DEVICETYPE='Phone' From 7ceec7f0688d63fc4bb3f9c9156743c0e2459f82 Mon Sep 17 00:00:00 2001 From: kolyakrasnik Date: Sun, 25 Dec 2022 17:31:47 +0300 Subject: [PATCH 28/31] improved status call using 3 retries and added it right after start command --- zebrunner.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zebrunner.sh b/zebrunner.sh index ba8ccef..b521039 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -356,6 +356,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt wait echo + sleep 3 status } @@ -380,6 +381,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt start-appium $udid >> ${DEVICE_LOG} 2>&1 start-stf $udid >> ${DEVICE_LOG} 2>&1 + status-device $udid + else echo "$DEVICE_NAME ($DEVICE_UDID) is disconnected!" fi @@ -777,7 +780,11 @@ export SIMULATORS=${metaDataFolder}/simulators.txt if [ -n "$device" ]; then #Hit the Appium status URL to see if it is available - if curl -Is "http://localhost:$appium_port/wd/hub/status-wda" | head -1 | grep -q '200 OK' + # --max-time 10 (how long each retry will wait) + # --retry 5 (it will retry 5 times) + # --retry-delay 0 (an exponential backoff algorithm) + # --retry-max-time (total time before it's considered failed) + if curl --max-time 3 --retry 3 --retry-delay 0 --retry-max-time 10 -Is "http://localhost:$appium_port/wd/hub/status-wda" | head -1 | grep -q '200 OK' then echo "$DEVICE_NAME ($DEVICE_UDID) is healthy." else From 1b2f39f1409840a3e19a491808ef6d567addee3e Mon Sep 17 00:00:00 2001 From: vdelendik Date: Tue, 27 Dec 2022 19:04:58 +0300 Subject: [PATCH 29/31] added stf stop during recovery --- zebrunner.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zebrunner.sh b/zebrunner.sh index 985b33e..1292656 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -614,6 +614,8 @@ export SIMULATORS=${metaDataFolder}/simulators.txt . ./configs/getDeviceArgs.sh $udid echo "Recovering services for $DEVICE_NAME ($DEVICE_UDID)" + stop-stf $udid >> ${DEVICE_LOG} 2>&1 & + start-wda $udid >> ${DEVICE_LOG} 2>&1 & start-appium $udid >> ${DEVICE_LOG} 2>&1 & start-stf $udid >> ${DEVICE_LOG} 2>&1 & From 45ab011755480258cd2d5faec83606b26f826651 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Tue, 27 Dec 2022 19:18:22 +0300 Subject: [PATCH 30/31] #158: bump up to stf:2.4.1 --- zebrunner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebrunner.sh b/zebrunner.sh index 1292656..e01f51b 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -183,7 +183,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo echo "Pull STF updates:" - stf_branch=2.4 + stf_branch=2.4.1 if [ ! -d stf ]; then git clone https://github.com/zebrunner/stf.git cd stf From b9afa2aac5f318b65bc3b9a1c33f94e724fb25a5 Mon Sep 17 00:00:00 2001 From: vdelendik Date: Tue, 27 Dec 2022 19:20:44 +0300 Subject: [PATCH 31/31] reverted to 2.4 to make valid release in github --- zebrunner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebrunner.sh b/zebrunner.sh index 4259754..984ec34 100755 --- a/zebrunner.sh +++ b/zebrunner.sh @@ -183,7 +183,7 @@ export SIMULATORS=${metaDataFolder}/simulators.txt echo echo "Pull STF updates:" - stf_branch=2.4.1 + stf_branch=2.4 if [ ! -d stf ]; then git clone https://github.com/zebrunner/stf.git cd stf