watir初学
上一篇 / 下一篇 2007-12-12 11:33:48 / 个人分类:watir
E*\G&k u`II0近日在同事的项目中用到了watir,并给我们进行了一次初级入门培训.
t/B1Sk|H!a,|&_051Testing软件测试网F!vY&P3r%["s(^学习后觉得容易上手,极想在真正的项目中用一次.
VH(aY0w~y051Testing软件测试网w#t?Z7`;b'S倒是巧了,刚好接到一个项目,业务复杂度很低,主要是一些简单的增删改查的操作,项目本身也不大.
1q M?'B ?v051Testing软件测试网z3\al1s+K于是磨拳擦掌,准备大干一场.51Testing软件测试网NG-j#p8`m6c
8L doMaB0瓢泼的大雨总是降落在炎炎夏日闷热的午后.51Testing软件测试网8K7R@Sj(P%i CI
51Testing软件测试网ozf/SX4O\.C一上场就碰到了两个问题.51Testing软件测试网2aKeT] fjp[6k9_
3Ki b"Zek}0一个是不支持中文的问题.在文本框里输入中文,watir不认.在google上搜,很快的我就查到了解决的方法,再一次感叹网络的无所不能.
.sb0E t^[:o,h0"\j_)kF0具体操作步骤摘抄如下:51Testing软件测试网Y&?v7\\]
51Testing软件测试网e5@Nn'xs3j1.打开watir.rb51Testing软件测试网6r\3P&h&K
2.在class TextField中加入一个新的method:
[I
Ku"j9xY0 def characters_in(value)51Testing软件测试网8T5hf:We x2Ut
index = 051Testing软件测试网$RH)q^3kiJ
while index < value.length51Testing软件测试网Ib\6Y/kL$m-HM]
len = value[index] > 128 ? 2 : 151Testing软件测试网,d'^$b K%q%c
yield value[index, len]
$k/fCY%|.F0 index += len
5gGK3x5K.I
B0 end51Testing软件测试网C;t5Y6P9L!BH
`'e4i
end51Testing软件测试网Rz.bq;_9z
51Testing软件测试网~"@b[H,@
3.更改class TextField的doKeyPress( value )方法部分代码,将下面代码
'U0So$p;i0-------------------------------------------51Testing软件测试网BzM.h4A!Y-S8C
for i in 0 .. value.length-1
Fa_ k7D5s0 sleep @container.typingspeed
&B/u N5S"NQ3|0 c = value[i,1]51Testing软件测试网{^6Ne}
@container.log " adding c.chr " + c
!Kz*sn+|1['Ck0 @o.value = @o.value.to_s + c
\zfVcN0 @o.fireEvent("onKeyDown")
gj9v9]_(Jq0 @o.fireEvent("onKeyPress")51Testing软件测试网9R xS^s*n@
@o.fireEvent("onKeyUp")
[5M1Y3Gv0 end
#[+h8y&m*s/BQK
c^0
C?+Iw/xjkFd0替换为如下代码
&m)\ wz!W0 characters_in(value) {|c|51Testing软件测试网
nmf)f*]%c
sleep @container.typingspeed51Testing软件测试网2J.y2X@&gF}
@o.value = @o.value.to_s + c
!C9v$gW3w8o~f!P!x0 @o.fireEvent("onKeyDown")51Testing软件测试网C:S#pde'ubJ"C
@o.fireEvent("onKeyPress")51Testing软件测试网E9}$GCptG
@o.fireEvent("onKeyUp")
N
B
^-]2p0 }51Testing软件测试网i'l&w~?!g
不过不同的版本会有所不同,我的版本是1.5.1的,按以上方法更改即可.低版本的,第三步按以下方式修改:
替换为如下代码51Testing软件测试网MatAq2qGn3v5H
characters_in(value) {|c|51Testing软件测试网
w t
vl?
sleep @ieController.typingspeed
E%P+A0]t1m
@0 @o.value = @o.value.to_s + c51Testing软件测试网$?:nt8WU)DTz
@ieController.typingspeed
h
cz'DGl0 }51Testing软件测试网GFnNpCS
:y^C0L^,N:F051Testing软件测试网2vL$?aF'p
第二个问题是识别DIV对象的问题51Testing软件测试网E)N-}i*Z
`Z5y9q:vMw!n7s0源代码如下:
6uK7LW.}efB'KvO#M0<DIVid="input_search_btn">51Testing软件测试网!}V3t0ld1?H(Kp.J
<Ahref="javascrīpt:pageFunction(1)"><IMGsrc="http://192.168.2.200:8080/petronx/attemper/images/newlist/images/chaxun.gif"/>51Testing软件测试网oR'AL#e
</A></DIV>
i8g#U^A:YzM+SD0多想了一下,觉得img是btn的图片,不能直接用来标识,所以想用ie.button(:id,"input_search_btn").click51Testing软件测试网)PDe,PT#J8gK
来做这个操作,执行的时候,watir没有执行这个语句,也没有出错.
}+k(hN*t:I0试了好几次,后来才发现,直接使用ie.image(:src,url).click即可
绕了个弯路,浪费了不少时间,不过好歹还是解决了.
!mKUJ2}o%}"Kf0R8Gh4c_2Fve0在Watir 的 Wiki 上有对html的对象识别的整理,可以进入下面的地址查看:
Krg.j.\\!\ XOJfV:\~0${ao+qZ }0http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
9@y[ \2~(bh0
相关阅读:
- Ruby+Watir经验谈: Understanding Watir (51testing, 2007-5-29)
- Ruby+Watir经验谈: javascript popup box (51testing, 2007-5-29)
- Ruby+Watir经验谈: 设计RUTF的TestRunner以产生格式化的测试结果 (fishy, 2007-5-30)
- Ruby+Watir经验谈: 漫谈针对功能的自动化测试框架 (lifr, 2007-5-30)
- Ruby+Watir经验谈: 包装Watir::IE (lifr, 2007-6-01)
- OpenSTA中文说明 (higkoo, 2007-8-08)
- QTP8.2中文帮助(F1) (higkoo, 2007-11-24)
- watir (iccer, 2007-11-27)
- 如何在 Watir 中识别各种 HTML 对象 (iccer, 2007-11-27)
- Recorder for WATiR (iccer, 2007-11-29)
标题搜索
日历
«
2024-03-28
日
一
二
三
四
五
六
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
我的存档
数据统计
- 访问量: 177999
- 日志数: 37
- 图片数: 2
- 书签数: 1
- 建立时间: 2007-03-01
- 更新时间: 2011-06-16
清空Cookie -
联系我们 -
51Testing软件测试网 -
交流论坛 -
空间列表 -
站点存档 -
升级自己的空间
Powered by 51Testing
© 2003-2021
沪ICP备05003035号
相关阅读:
- Ruby+Watir经验谈: Understanding Watir (51testing, 2007-5-29)
- Ruby+Watir经验谈: javascript popup box (51testing, 2007-5-29)
- Ruby+Watir经验谈: 设计RUTF的TestRunner以产生格式化的测试结果 (fishy, 2007-5-30)
- Ruby+Watir经验谈: 漫谈针对功能的自动化测试框架 (lifr, 2007-5-30)
- Ruby+Watir经验谈: 包装Watir::IE (lifr, 2007-6-01)
- OpenSTA中文说明 (higkoo, 2007-8-08)
- QTP8.2中文帮助(F1) (higkoo, 2007-11-24)
- watir (iccer, 2007-11-27)
- 如何在 Watir 中识别各种 HTML 对象 (iccer, 2007-11-27)
- Recorder for WATiR (iccer, 2007-11-29)
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
1 | 2 | ||||||||
3 | 4 | 5 | 6 | 7 | 8 | 9 | |||
10 | 11 | 12 | 13 | 14 | 15 | 16 | |||
17 | 18 | 19 | 20 | 21 | 22 | 23 | |||
24 | 25 | 26 | 27 | 28 | 29 | 30 | |||
31 |
我的存档
数据统计
- 访问量: 177999
- 日志数: 37
- 图片数: 2
- 书签数: 1
- 建立时间: 2007-03-01
- 更新时间: 2011-06-16
清空Cookie - 联系我们 - 51Testing软件测试网 - 交流论坛 - 空间列表 - 站点存档 - 升级自己的空间
Powered by 51Testing
© 2003-2021
沪ICP备05003035号