设为首页 加入收藏

TOP

Calabash+Gearman实现多手机同步测试机制
2015-02-02 14:16:14 来源: 作者: 【 】 浏览:11
Tags:Calabash Gearman 实现 手机 同步 测试 机制

背景介绍


Calabash-android是支持android的UI自动化测试框架。



gearman


$ sudo apt-get install gearman-job-server
$ gearmand -V
?
gearmand 1.0.6 - https://bugs.launchpad.net/gearmand
?
$ sudo apt-get install gearman-tools
$ gearman -H
?
启动gearman job server,作为后台服务运行:


$ sudo gearmand -d
?
多手机同步测试举例


假设要测试微信的发送消息功能,calabash的测试用例可以按如下方式撰写:
?
AA-send-message-to-BB–role-AA.feature:


Feature: 微信测试发送消息给好友-角色A
?
? Scenario: 微信测试发送消息给好友
? ? ...打开微信软件,作为帐号A登录,进入与好友B的聊天窗口
? ? When I send weixin message "A说,你好!"? # 微信聊天窗口中发送消息
? ? And? I send sync message "A说,你好!" to role "BB"
? ? Then I see "A说,你好!"? #我能看到自己说的话
?
? ? When I wait sync message $AA_sync_1 as role "AA"
? ? Then I see $AA_sync_1 #我能看到对方说的话
? ? ...
?
AA-send-message-to-BB–role-BB.feature:


Feature: 微信测试发送消息给好友-角色B
?
? Scenario: 微信测试发送消息给好友
? ? ...打开微信软件,作为帐号B登录,进入与好友A的聊天窗口
? ? When I wait sync message $BB_sync_1 as role "BB"
? ? Then I see $BB_sync_1? #我能看到对方说的话
?
? ? When I send weixin message "B说,你好!"? # 微信聊天窗口中发送消息
? ? And? I send sync message "B说,你好!" to role "AA"
? ? Then I see "B说,你好!"? #我能看到自己说的话
? ? ...
?
命令行终端1中运行AA-send-message-to-BB–role-AA.feature


$ export ADB_DEVICE_ARG=HTC-G9
$ export GEARMAN_JOB_SERVER=localhost
?
$ calabash-android run weixin.apk -r features/ features/AA-send-message-to-BB--role-AA.feature
?
命令行终端2中运行AA-send-message-to-BB–role-BB.feature


$ export ADB_DEVICE_ARG=HWAWEI-P7
$ export GEARMAN_JOB_SERVER=localhost
?
$ calabash-android run weixin.apk -r features/ features/AA-send-message-to-BB--role-BB.feature
?
calabash中封装gearman命令实现同步机制
?
sync_step.rb:


# encoding: utf-8
require 'calabash-android/calabash_steps'
?
When /^I wait sync message \$([^\$]*) as role "([^\"]*)"$/ do |msg_ev, role|
? gearman_job_server=ENV["GEARMAN_JOB_SERVER"]
? fail "环境变量::GEARMAN_JOB_SERVER::未定义! 设置方法: export GEARMAN_JOB_SERVER=localhost" if ( gearman_job_server == nil)
? uuid=`uuidgen`.strip?
? cmd="gearman -h #{gearman_job_server} -t 30000 -w -c 1 -f receiver_#{role} -- tee /tmp/#{role}-#{uuid}; cat /tmp/#{role}-#{uuid}"
? puts "角色#{role}准备执行命令:#{cmd}"
?
? message=`#{cmd}`.strip
? fail "未收到同步消息" if ( message == "" )
? ENV[msg_ev]=message
? puts "角色#{role}接收到同步消息: #{ENV[msg_ev]}"
end
?
When /^I send sync message "([^\"]*)" to role "([^\"]*)"$/ do |msg, role|
? gearman_job_server=ENV["GEARMAN_JOB_SERVER"]
? fail "环境变量::GEARMAN_JOB_SERVER::未定义! 设置方法: export GEARMAN_JOB_SERVER=localhost" if ( gearman_job_server == nil)
? fail "sync message 为空" if ( msg == "" )
? cmd="echo '#{msg}' | gearman -h #{gearman_job_server} -t 30000 -f receiver_#{role}"
? puts "角色#{role}准备执行命令:#{cmd}"
?
? response=`#{cmd}`.strip
? fail "发送同步消息失败" if ( response != msg )
? puts "发送同步消息给角色#{role}: #{msg}"
end
?
When /^I send sync message \$([^\$]*) to role "([^\"]*)"$/ do |msg_ev, role|
? gearman_job_server=ENV["GEARMAN_JOB_SERVER"]
? fail "环境变量::GEARMAN_JOB_SERVER::未定义! 设置方法: export GEARMAN_JOB_SERVER=localhost" if ( gearman_job_server == nil)
? msg=ENV[msg_ev]
? response=`echo "${msg}" | gearman -h #{gearman_job_server} -f receiver_#{role}`
? fail "发送同步消息失败" if ( response != msg )
? puts "发送同步消息给角色#{role}: #{msg}"
end
?
calabash_steps.rb:


# encoding: utf-8
require 'calabash-android/calabash_steps'
?
Then /^I see \$([^\$]*)$/ do |text_ev|
? text = ENV[text_ev]
? steps %{
? Then I see "#{text}"
? }
end


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux程序链接时-lpthread对程序.. 下一篇Yii 用户登陆机制

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: