51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1852|回复: 0
打印 上一主题 下一主题

【我分享】使用 Gearman+Calabash 并行测试手机 APP

[复制链接]
  • TA的每日心情
    慵懒
    2017-7-9 10:38
  • 签到天数: 13 天

    连续签到: 1 天

    [LV.3]测试连长

    跳转到指定楼层
    1#
    发表于 2015-1-9 08:32:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
            摘要:使用任务分发系统Gearman分布式执行Calabash的自动化测试用例,可以达到并行测试手机APP的目的。
    背景介绍Gearman
    Gearman是一个分发任务的程序框架,可以用在各种场合,与Hadoop相比,Gearman更偏向于任务分发功能。它的 任务分布非常简单,简单得可以只需要用脚本即可完成。
    Calabash
    Calabash-android是支持android的UI自动化测试框架,PC端使用了cucumber框架,通过http和json与模拟器和真机上安装的测试apk通信,测试apk调用robotium的方法来进行UI自动化测试,支持webview操作。
    calabash脚本以 使用calabash测试开源中国Android客户端 为例。
    Gearman安装和执行测试Ubuntu上安装Gearman$ sudo apt-get install gearman-job-server$ gearmand -Vgearmand 1.0.6 - https://bugs.launchpad.net/gearmand $ sudo apt-get install gearman-tools$ gearman -H运行Gearman并发执行Calabash测试用例启动gearman job server,作为后台服务运行:
    $ gearmand -d启动两个worker,每个woker代表一个手机测试设备(tester),woker始终不退出,且没有任何打印:
    $ gearman -w -f tester -- ./test-case.sh NEXUS-7 testdata-aa.bashrc$ gearman -w -f tester -- ./test-case.sh HUAHEI-8860 testdata-bb.bashrc分发测试用例到各个worker,收集到所有测试打印后,即完成测试:
    ./run-suite.sh @BVT实时查看测试结果,任何一个worker测试完一个用例,测试结果会立即打印出来:
    tail -f /tmp/test-result并发测试的效果:
    理论上如果顺序执行测试所有用例要10个小时,那么只要准备10个手机,每个手机对应启动一个worker:tester,测试时间将缩短到最少1个小时。
    下面的脚本是在同一台Ubuntu电脑上,利用多个USB口连接多个手机来并发测试,
    如果要在多台电脑上执行并发测试,那要考虑这多台电脑如何获取同一份apk和calabash脚本,可以考虑从一个公共的url去wget。
    Gearman测试脚本test-case.sh从stdin接收到的calabash测试脚本文件路径,调用calabash-android完成测试,再作为client调用printer
    #!/bin/bashif [ x$2 == x ]then  echo "usage: $0 device-id testdata-xx.bashrc"  echo "      device-id get from: adb devices"  exit 1firead lineecho $0 $1 $2uuid=`uuidgen`d1=`date +%T`suite_path=$HOME/git/oschina/android-app/calabashapk_path=$HOME/git/oschina/android-app/bin/oschina-android-app.apkecho "test result in /tmp/${uuid}"echo $d1 at `hostname`1 >> /tmp/${uuid}mkdir -p $HOME/$1cd $HOME/$1export ADB_DEVICE_ARG=$1. $src/$2calabash-android run $apk_path -r $suite_path/features/ $line 2>&1 | tee -a /tmp/${uuid}d2=`date +%T`echo $d2 at `hostname`1 >> /tmp/${uuid}failed=`grep "Failing Scenarios" /tmp/${uuid} | wc -l`if [ $failed == 0 ]then  echo "===PASS=== : $line" >> /tmp/${uuid}else  echo "===FAIL=== : $line" >> /tmp/${uuid}figearman -f printer < /tmp/${uuid}rm -f /tmp/${uuid}print-result.sh 从stdin接收测试结果,并添加到文件/tmp/test-result
    #!/bin/bashwhile read line do  echo "$line" >> /tmp/test-resultdonecase_count=`cat /tmp/case_count`finished=`egrep "===(PASS|FAIL)===" /tmp/test-result | wc -l`echo -n "rogress:" $finished "/ $case_count  [" >> /tmp/test-resultfor ((i=0; i<$finished; i++ ))do  echo -n ">" >> /tmp/test-resultdonelet unfinished=$case_count-$finishedfor ((i=0; i<$unfinished; i++ ))do  echo -n "." >> /tmp/test-resultdoneecho -en "]\n" >> /tmp/test-resultrun-suite.sh 作为client,后台一次分发所有calabash脚本到tester,并启动woker: printer,直到收到所有测试结果打印才退出
    #!/bin/bashif [ x$1 == x ]then  echo "usage:" $0 "@BVT|@nightly|all|failed"  exit 1fisuite_path=$HOME/git/oschina/android-app/calabashuuid=`uuidgen`if [ "$1" == "all" ]then  find $suite_path -name "*.feature" > /tmp/${uuid}elif [ "$1" == "failed" ]then  if [ -f /tmp/failed ]  then    cat /tmp/failed > /tmp/${uuid}  else    touch /tmp/${uuid}  fielif [[ "$1" == @* ]]then  grep $1 $suite_path -rl | grep ".feature$" > /tmp/${uuid}ficase_count=`cat /tmp/${uuid} | wc -l`echo $case_count > /tmp/case_countif [ $case_count == 0 ]then  echo "NO case to run, exit." | tee /tmp/test-result  rm -f /tmp/${uuid}  exit 1fiecho "total $case_count cases." | tee /tmp/test-resulti=0while read line do  let i+=1  echo "send No.$i case --- $line"  echo $line | gearman -b -f runcasedone < /tmp/${uuid}rm -f /tmp/${uuid}gearman -w -c $case_count -f printer -- ./print-result.sh $case_countcat /tmp/test-resultgrep "===FAIL===" /tmp/test-result | awk '{print $3}' > /tmp/failedecho "" > /tmp/summaryecho "=================test result summary================" 2>&1 | tee -a /tmp/summarygrep "===PASS===" /tmp/test-result 2>&1 | tee -a /tmp/summarygrep "===FAIL===" /tmp/test-result 2>&1 | tee -a /tmp/summaryfails=`grep "===FAIL===" /tmp/test-result | wc -l`if [ $fails == 0 ] then  echo -e "\033[32;1;7mPASS\033[0m :" `grep "===PASS===" /tmp/test-result | wc -l` 2>&1 | tee -a /tmp/summaryelse  echo -e "\033[31;1;7mFAIL\033[0m :" `grep "===FAIL===" /tmp/test-result | wc -l` 2>&1 | tee -a /tmp/summaryfiecho "TOTAL: $case_count" 2>&1 | tee -a /tmp/summarycat /tmp/summary >> /tmp/test-result      

    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-7 06:52 , Processed in 0.060721 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表