十五年测试老手,长期负责WEB\APP 项目测试,目前主要负责团队管理工作。

web验收测试工具Webrat

上一篇 / 下一篇  2011-11-07 22:37:08 / 个人分类:其它

文章来源
  • 文章来源:【转载】

Webrat 可帮我们编写可表达以及稳健的验收测试脚本,主要用于 Ruby 应用,支持多种 Ruby 的 Web 框架,例如Rails, Merb 和 Sinatra。Webrat 同时还支持一些常用的测试框架,例如:RSpec, Cucumber, Test::Unit and Shoulda51Testing软件测试网J%c9z3UhI

Cucumber已经成为广泛接受的集成测试工具,Rails的开发的热门。那么,下面将专门讨论对于写cucumber测试的调试(Debug)51Testing软件测试网3kc!\-c\K
51Testing软件测试网D+G] ZtiA(m;QH
ruby-debug
M ?w4i A q9_0breakpoint
51Testing软件测试网2~7[ zZ:{k L.{I+s
首先,添加调试支持环境,到对应的features/support/env.rb.51Testing软件测试网yT'|H'UB/R

l&pKLx2`0
Java代码 复制代码
  1. require 'ruby-debug'  
51Testing软件测试网?-q)td_YL,ZC9C*q%~"j
添加断点51Testing软件测试网0@$aO5a^;E-{YrW M

(X5NF-] l$['A0
Ruby代码 复制代码
  1. Then /^the process should exit cleanly$/ do  
  2.   breakpoint   
  3.   assert @exited_cleanly"Process did not exit cleanly: #{@stdout}"  
  4. end  
51Testing软件测试网KX hs&c]
这里特别说明,如果你把断点breakpoint加到了一个block的最后,会进入调用部分。例如,下面这样会好一些。51Testing软件测试网.hC{$J1^9K$s:yn
51Testing软件测试网W){? XA
<notextile>51Testing软件测试网6R.M"Q+G O0V`"Z
Ruby代码 复制代码
  1. Then /^the process should exit cleanly$/ do  
  2.   assert @exited_cleanly"Process did not exit cleanly: #{@stdout}"  
  3.   breakpoint; 0   
  4. end  

0e-JHff+L!_d@p8v`0</notextile>
8M1{t9`G_^E~ P0
;{ a/^v ZR6v6D0开始debug
~ S{bQ9aNr0使用“Then I debug”放到 features/step_definitions/debug_steps.rb:将会很方便
$u'qp1]kX0
Ruby代码 复制代码
  1. Then /^I debug$/ do  
  2.   breakpoint   
  3.   0   
  4. end  
51Testing软件测试网9a\"Q'|-^+Mk
这样写的好处在于可以方便的添加到你要测试的代码部分。如果,你把断点放到有问题的部分可能会比较不容易定位问题。
Q?oX!F)[ c1M0
:L$I"SJ6_T T0Webrat
7`4`&y.pD0Webrat是Rails默认的cucumber测试工具,将提供诸如点击链接,输入和提交表单的操作。如果,你的模拟点击的元素不存在,将会产生很多的html反馈。
H o2NSx2~3f1pF0
ng FFq;C8Z7Zf;E \8y0save_and_open_page
cEIh iHv_p0Webrat提供save_and_open_page来捕获当前的HTML页面并保存。如下使用:51Testing软件测试网'w4t:Z2Ntjdw]
Ruby代码 复制代码
  1. When /^I follow "(.*)"$/ do |link|   
  2.   save_and_open_page   
  3.   click_link(link)   
  4. end  
51Testing软件测试网&zs.n {ou5?
可是,这就有一个问题,如果,在测试的时候有太多的页面被保存,那么读取就很不方便51Testing软件测试网$K,w \v$a

#A:mv^,P$U%Em0
Ruby代码 复制代码
  1. When /^I follow "(.*)"$/ do |link|   
  2.   begin  
  3.     click_link(link)   
  4.   rescue  
  5.     save_and_open_page   
  6.     raise  
  7.   end     
  8. end  

&d0^;L ] u2C0结论51Testing软件测试网stq T6mD(GS`?V
Cucumber 可以结合 ruby-debug  save_and_open_page进行调试

TAG: web Web 测试工具

 

评分:0

我来说两句

Open Toolbar