测试之家淘宝店:主营软件测试定制服务 http://shop71136398.taobao.com/ 软件评测试考试论坛:http://www.testdao.com/forum-113-1.html 2012软件评测师考试群:28388329

watir基本语句

上一篇 / 下一篇  2009-07-31 14:03:48 / 个人分类:watir+ruby

1.   请求watir

/o$O mNYr[0

require ‘watir’51Testing软件测试网-C}+o(g7z&nr

2.   访问web页面51Testing软件测试网-T-B0qo@7d

test_site = ‘http://192.168.1.178:9992/TOOLKIT/User/SignIn.aspx’51Testing软件测试网 Y3[7P9rJC

3.   打开一个新的ie

V9eap-eoXbn.k0

a)   ie = Watir::IE.new51Testing软件测试网+Vr bK3T!x w

b)   Watir::Browser.default = ‘firefox’

9~EgQIFp0

Browser = Watir::Browser.new51Testing软件测试网!V.} S8QY x

Browser.goto(“http://192.168.1.178:9992/TOOLKIT/User/SignIn.aspx”)51Testing软件测试网5a]a/o-t$Q)d{

51Testing软件测试网 ]@;`"Ha\H

4.   进入到测试web页面

'Cl%rFO.r3g'|#Zdh0

ie.goto(test_site)

#Y&J-` _4f9?0

5.   输入文本51Testing软件测试网kW3NgQ5?.se

ie.text_field(:name,”ctl00$ContentPlaceHolderBody$TextBoxUserName”).set(“Jane.liu”)

:X-M U4t3w-}dR0

6.   点击按钮51Testing软件测试网htMlds f!Q

  ie.button(:name,”ctl00$ContentPlaceHolderBody$ButtonSignIn”).click51Testing软件测试网%|?1dj|

7.   进入到新的页面51Testing软件测试网'l's ]%z.g7\e-B

  Ie = Watir::IE.attach(:title, ‘Select OPEN Appraisal’)51Testing软件测试网D&b'|*V!c/o\

8.   预期结果51Testing软件测试网an3kG8k!i S

If ie.contains_text(“1GCGG256291100045”)

t&sgss&@X(E^{4Ry0

puts “test passed!”

@(W:T0R&q0

else

9aet9| {J0

puts “Test Failed!”51Testing软件测试网(GT-t*aU0q

end

mV+Bk$@oD)c5C,`J0

9.   下拉列表

wAv#\6w4F3mG,k7`I0

ie.select_list(:name, 'name').select_value('value')

:ew-ko9j]0

10. 上传图片51Testing软件测试网a8q/C9}dd"S A!V

ie.file_field(:id,”the_file”).set(“c:\\image.jpg”)51Testing软件测试网2G'~AP N\K}g%Q

*如果是中文操作系统,那么需要修改C:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.6\watir\input_elements.rb文件中

/|x-]:R kp0m0

找到filefield类下的set方法修改中间的“choose file成“选择文件”(其中“选择文件”是根据自己操作系统的弹出对话框的title来决定的。因为有些即使是英文操作系统但是“choose file to upload”就需要也进行修改。

LA!B C9f7Q0

并且需要去掉button2按钮。51Testing软件测试网Z.V3Z*N&V+g

system("rubyw -e \"require 'win32ole'; @autoit=WIN32OLE.new('AutoItX3.Control'); waitresult=@autoit.WinWait '选择文件', '', 15; sleep 1; if waitresult == 1\" -e \"@autoit.ControlSetText '选择文件', '', 'Edit1', '#{setPath}'; @autoit.ControlSend '选择文件', '', '', '{ENTER}';\" -e \"end\"")

]JfeQo` X/Hd?0

11. combobox

/\QQ6Gu-o;W0

ie.image(:id,”ext-gen11”).click51Testing软件测试网'w6NpAi IB

ie.div(:text,”Changshaone”).click

#C5b J)@^-D;R&t0

12. radio button51Testing软件测试网8{Zsx.O[!E2He

ie.radio(:id,”ct100_ContentPlaceHolderBody_rbviClean”).set

,\)g3MYEF0

13. 输出结构判断

k/B e.PP5i0

if ie.text.include? "Congratulations,vehicle info has sent to lot successfully!"51Testing软件测试网`vLNS:}\&n

 puts "Test Passed. complete a Appraisal . Actual Results match Expected Results."

ZM*x@r#{;enq0

else

gJ gQA ~-`9T0

 puts "Test Failed! Don't complete a apprasial."51Testing软件测试网sIz!z)HOg!_m

14Test suite51Testing软件测试网.`)s9`)@ |'Yti@

    require "#{File.dirname(__FILE__)}/LiveNetPriceCheck.rb"

;Bz2Y1q}5\0

15undefined method `radio' for nil:NilClass

6]Z/i | G(]F0

   因为:id"ctl00_ContentPlaceHolderBody_RadioNew"之间多了个空格51Testing软件测试网E-^Wfj\Z)R;b

$ie.radio(:id,"ctl00_ContentPlaceHolderBody_RadioNew").set51Testing软件测试网){ \\2q$Ns:i aiPO!y

16IE窗口最大化51Testing软件测试网1`#^ V2G%Ycyv

ie.maximize()51Testing软件测试网8v4J9I c)D1rn-I

运行cmd51Testing软件测试网1b!YmF3|i\

regsvr32 C:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.4\watir\AutoItX3.dll51Testing软件测试网l:AE4b*e+gI1F }


TAG:

 

评分:0

我来说两句

Open Toolbar