Vbscript正则表达式实例及在QTP中应用

发表于:2009-2-23 13:18

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:tester2009    来源:51Testing博客

  完整的代码如下:

  Function SelectRegExp(Obj,Patrn,Button,Offset)

  Dim NumOfItems,i,CurrentValue,regEx,ItemToSelect,oldFilter

  '初始化正则表达式

  Set regEx=new RegExp

  regEx.pattern=patrn

  regEx.Ignorecase=false '区分大小写

  ldfilter=Reporter.Filter '保存默认值

  Reporter.Filter=2'仅发送错误

  ItemToSelect=-1

  '获取测试对象的 NumOfItems属性

  NumOfItems=Obj.getroproperty("items count")

  For i=0 to NumOfItems-1

  CurrentValue=Obj.GetItem(i)

  If regEx.test(CurrentValue)Then

  If (ItemToselect<>-1) Then

  SelectRegExp=-1 '表示匹配项不唯一

  Reporter.Filter=oldFilter

  Exit function

  End If

  ItemToSelect=i

  End If

  Next

  Reporter.Filter=oldFilter '重置默认设置

  '做出选择动作

  If (ItemToSelect>=0) Then

  SelectRegExp=Obj.Select(ItemToSelect,Button,Offset)

  else

  SelectRegExp=-1

  End If

  End Function

  Dialog("Login").WinEdit("Password:").Set "Cheers.lee"

  Dialog("Login").WinEdit("Edit").SetSecure "48d51f921459c0234cb35e05206c9141a5197c6a"

  Dialog("Login").WinButton("OK").Click

  Window("Flight Reservation").WinObject("Flight No:").Type "092208"

  Window("Flight Reservation").WinComboBox("Departure Time:").Select "London"

  Window("Flight Reservation").WinComboBox("Arrival Time:").Select "Los Angeles"

  Window("Flight Reservation").WinCheckBox("text:=FLIGHT").click

  RegisterUserFunc"WinList","select","SelectRegExp"

  Window("Flight Reservation").Dialog("Flights Table").Activate

  Window("Flight Reservation").Dialog("Flights Table").WinList("ListBox").select "19170.*"

  'Window("Flight Reservation").Dialog("Flights Table").WinList("ListBox").Select"19170 LON 08:00 AM LAX 08:45 AM AA $100.50"

  Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

  Window("Flight Reservation").WinEdit("Edit").Set "lihuichang"

  Window("Flight Reservation").WinRadioButton("Business").Set

  Window("Flight Reservation").WinButton("Insert Order").Click

  Window("Flight Reservation").Close

22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号