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

watir参数化

上一篇 / 下一篇  2009-07-31 13:58:56 / 个人分类:watir+ruby

1.读取CSV文件中的值:

   require "#{File.dirname(__FILE__)}/libFile.rb"#调用公共库51Testing软件测试网7r9hK+nxB

path = "#{File.dirname(__FILE__)}/username.csv"#调用.csv文件51Testing软件测试网L kMh#? O)z

 

:I'n*kD:~,K0GI0

dfile         = DealFile::DealCsvFile.new

#q8h`` C6m)D0

 51Testing软件测试网&^QeW&FC

$type_row = []51Testing软件测试网S$S~S}5o)ok

is_exist     = dfile.GetFileInfo(path)#获取文件信息

&Zs oA\aV1?[^:B0Mq0

 

)k,OY-S nkS0

if (is_exist[0] ==true)#判断文件是否存在

pXG;a],{ q0

   user_info = dfile.CsvToArray(path,2,100)#从第二行开始读取文件

OmD/iX-T/I3Hi[0

 

y9Ab;~vXs%}\ @`9P0

Vin_info.each do |info|

-t)OC/e!i,sx d4`0

   $username = info[0].strip.upcase#读取username

n.GrPooc'~4I R0

   password = info[1].strip.upcase#读取password

0[*i3x"e|:eF0

    

'u q1uC2}5^0

   puts"#{$username}--#{password}"#输出结果51Testing软件测试网G"ub*}g/@ J)C#j

end51Testing软件测试网7q/lic)Zt X

end

4[9E PH7V02.waitr参数化,把红色部分加入到watir脚本中51Testing软件测试网\5U.T~5R!{
require 'test/unit'51Testing软件测试网0h+ynT(h;lf8VibD
require 'watir'
i(GwZ*o5}%xI F0require "#{File.dirname(__FILE__)}/libFile.rb"
X7V6C!wf6W"IP A0path = "#{File.dirname(__FILE__)}/username.csv"51Testing软件测试网.g9[&L;K2~-[8o
class TestLogin < Test::Unit::TestCase
XMN.C+mK _'Y0def test_a_openlink51Testing软件测试网 y^y,L1`z$F(cl
   #open tookilt
jz6A\x |%]a9Z0   $ie= Watir::IE.new
5y{4p2hR8nu Y0   $ie.goto("http://192.168.1.178:9992/toolkit/User/SignIn.aspx")51Testing软件测试网$e}`a8WN t
   $ie.maximize()51Testing软件测试网 bG'm,v$bH EW8f{
 end
eI"q y*~qg2s/I0 
}&^ A/`-kO0# login method51Testing软件测试网LYp F dP

h f'EqFt'r6ih8~GB0def test_b_Login51Testing软件测试网 OY'ov%Sb!|/DN#|
        dfile             = DealFile::DealCsvFile.new
HAN0C4kr\"o%m0
N8?9L%[w+Tj0        $type_row    = []51Testing软件测试网W `7F {oe:S,k
        is_exist        = dfile.GetFileInfo(path)  #获取文件信息
Mx3gfOB\s0        user_info = dfile.CsvToArray(path,2,100)51Testing软件测试网LhQHrFLe;` G
       51Testing软件测试网LoJ)j9PK!mgWQ
        user_info.each do |info|
e4@{i(F,?0        $username = info[0].strip.upcase #用户名51Testing软件测试网8P-K$}pWj#~ X
        password = info[1].strip.upcase#密码51Testing软件测试网C!Nq0di
       51Testing软件测试网-t-F J(XM` b@
        $ie.text_field(:name,"ctl00$ContentPlaceHolderBody$TextBoxUserName").set("#{username}")51Testing软件测试网*z \ vvtmvZ
        $ie.text_field(:name,"ctl00$ContentPlaceHolderBody$TextBoxPassword").set("#{password}")
!P+Ie@7~4F,Krw0        $ie.button(:name,"ctl00$ContentPlaceHolderBody$ButtonSignIn").click
P]0AF!J'NBqH0      end
9h.N6nF$Fxm\5o0 51Testing软件测试网BtX/~U*S+|
   def test_c_mytest51Testing软件测试网R#wAw{!].{w^w
    $ie.link(:text, "Logout").click             51Testing软件测试网 QZ6[ t \ _AG
  end51Testing软件测试网V4Y%mG.^0`"w
end
@;`Y Xr Df Bc0
$wiw1g:g.EW0再次运行,就ok了
M[1}G*@Z0

TAG:

 

评分:0

我来说两句

Open Toolbar