jenkins + UIAutomation 自动化脚本运行app

这里,我在jenkins上配置了子节点,脚本中包含了在master还是在slave上执行脚本的判断脚本

SERVER_HOME=$JENKINS_HOME/jobs/$JOB_NAME
ATTACHED_PROJECT=iOS_Mobile_Project

echo "node_name = $NODE_NAME, node_labels = $NODE_LABELS"
echo "master_ip = $MASTER_IP, mster_user = $MASTER_USER"
echo "excutor_number = $EXECUTOR_NUMBER"

if [ "$NODE_NAME" != master ]; then
    WORKSPACE_COMMON=$WORKSPACE/workspace
    echo "run in slave($NODE_LABELS)"
    rm -f $WORKSPACE_COMMON/*.ipa
	scp $MASTER_USER@$MASTER_IP:$SERVER_HOME/../$ATTACHED_PROJECT/workspace/build/Debug-iphoneos/*.ipa $WORKSPACE_COMMON/
else
    WORKSPACE_COMMON=$WORKSPACE
    cp $JENKINS_HOME/jobs/$ATTACHED_PROJECT/workspace/build/Debug-iphoneos/*.ipa $WORKSPACE_COMMON/
fi
上面脚本的功能:
判断是否是master节点,是的话就拷贝本地的ipa到jenkins的workspace目录;不是的话就从master机器的ipa包目录把ipa包拷贝到slave机器的workspace目录

执行脚本

SERVER_HOME=$JENKINS_HOME/jobs/$JOB_NAME

# not master node, need to download scripts from master
if [ "$NODE_NAME" != master ]; then
    WORKSPACE_COMMON=$WORKSPACE/workspace
else
    WORKSPACE_COMMON=$WORKSPACE
fi

#slave paths
TUNEUP_HOME=$WORKSPACE_COMMON/../../tuneup_engine
APP_PATH=$WORKSPACE_COMMON/build/Debug-iphoneos/xxx.app
AUTO_TEST_SCRIPT_DIR=$WORKSPACE_COMMON/scripts
AUTO_TEST_REPORT_DIR=$WORKSPACE/reports
REPORT_FILE_DIR=$AUTO_TEST_REPORT_DIR/$BUILD_NUMBER

if [ ! -d "$AUTO_TEST_SCRIPT_DIR" ]; then
  mkdir -p $AUTO_TEST_SCRIPT_DIR
fi

if [ ! -d "$AUTO_TEST_REPORT_DIR" ]; then
  mkdir -p $AUTO_TEST_REPORT_DIR
fi

if [ ! -d "$REPORT_FILE_DIR" ]; then
  mkdir -p $REPORT_FILE_DIR
fi

# not master node, need to download scripts from master
if [ "$NODE_NAME" != master ]; then
  	#copy tuneup_engine to slave
    echo "run in slave($NODE_LABELS)"
	rm -f $AUTO_TEST_SCRIPT_DIR/*
	scp -r $MASTER_USER@$MASTER_IP:$SERVER_HOME/workspace/scripts $AUTO_TEST_SCRIPT_DIR/../
fi


set +e
INSTRUMENTS_TRACE_FILE="Instruments.trace"
SCREENSHOTS_DIR="Run 1"

cd $AUTO_TEST_SCRIPT_DIR
for script_file in `ls test*.js`
do  
  echo "$script_file"
  $TUNEUP_HOME/test_runner/run $APP_PATH $script_file $REPORT_FILE_DIR -x -v -c -d dynamic
  
  if [ -d "$INSTRUMENTS_TRACE_FILE" ]; then
    mv $INSTRUMENTS_TRACE_FILE Instruments_$script_file.trace
  fi
  if [ -d "$SCREENSHOTS_DIR" ]; then
    mv $SCREENSHOTS_DIR Screenshots_$script_file
  fi
done
set -e

上面脚本的功能:
创建测试报告输出目录
判断是否是slave节点,是的话就从master节点拷贝脚本文件到slave节点
使用tuneup脚本引擎执行脚本,并输出脚本执行结果

你可能感兴趣的:(开源工具,iOS)