51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1916|回复: 3
打印 上一主题 下一主题

[原创] 如何使脚本化的Datatable循环

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-9-21 11:14:25 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本帖最后由 monalisali 于 2010-9-21 11:23 编辑

大家好:
我在编写一段关于datatable脚本时遇到一个问题,请大家帮我看看错在哪里了。
脚本的原意是在两个“SwfComboBox”中利用随机数任意选择一个搜索条件,然后利用Datatable.LocalSheet.AddParameter 语句在runtime
datatable中分别添加表头以及选择条件的数据。其中,搜索条件的循环次数是由For语句来控制的。 我没有在Keyword view进行过任何关于
datatable的设置,只想完全用脚本来实现datatable的创建,循环等操作。
我的问题:
1) 在For循环内的脚本只进行第一次循环,然后脚本就停止了,即搜索条件只会被执行一次
2) 当不在Keyword view中进行datatable操作时(这样的话当脚本写到关于datatable时,还需要进行相应的录制于datatable的设置,很麻烦
),如何在Expert view中完全用脚本来创建datatable,从而达到参数化某几个控件的目的?
脚本如下,略有点多。其中,For循环为12-57行,两个搜索条件是strkitorgname,strkitorglicense 它们的语句在19-22行
  1. Set  mgbox = CreateObject ("WScript.Shell")
  2. SwfWindow("食品安全电子化监管系统--城市运行区").Activate
  3. SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("日常监管子系统").Activate
  4. SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("日常监管子系统").SwfLabel("选择监管对象").Click
  5. '***************************************在中心厨房Tab中***************************************************
  6. SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("监管对象设置").SwfRadioButton("中心厨房").Set
  7. Set thewindow = SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("监管对象设置")
  8. Dim subslistcount, yearslistcount
  9.     subslistcount = thewindow.SwfComboBox("厨房区县").GetItemsCount
  10.     yearslistcount = thewindow.SwfComboBox("厨房许可证发证日期").GetItemsCount

  11. For i = 0 to yearslistcount -1
  12. thewindow.SwfRadioButton("中心厨房").Set
  13. Dim randdata, subsdata, licdatedata
  14. Randomize
  15. randdata =  int (((yearslistcount-1) * Rnd) +1)
  16. thewindow.SwfComboBox ("厨房区县").Select randdata
  17. thewindow.SwfComboBox ("厨房许可证发证日期").Select randdata
  18. subsdata = thewindow.SwfComboBox("厨房区县").GetItem (randdata)
  19. licdatedata= thewindow.SwfComboBox("厨房许可证发证日期").GetItem (randdata)
  20. Datatable.LocalSheet.AddParameter "中心厨房区县", subsdata
  21. Datatable.LocalSheet.AddParameter "中心厨房发证日期", licdatedata
  22. mgbox.Popup "此时的I="& i & vbnewline &_
  23.                        "选择的区县是:"& "  " & subsdata & vbnewline &_
  24.         "发证的日期是" & "  " & licdatedata, 5, " ",1
  25.         
  26. 'thewindow.SwfComboBox("厨房区县").Select "闵行"
  27. thewindow.SwfToolbar("swfname:=bindingNv","swfname
  28. path:=bindingNv;pnlToolbar;organizationSearchControl2;pnlCntKitchen;OrganizationDialog").Press "查询"
  29. Set KitTable = SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("监管对象设置").SwfTable
  30. ("swfname:=dgvOrganizationList","swfname
  31. path:=dgvOrganizationList;organizationSearchControl2;pnlCntKitchen;OrganizationDialog")
  32. Dim intkitrowcount,randomrow
  33. Dim strkitorgname, strkitorglicense
  34. intkitrowcount =  KitTable.RowCount
  35. Randomize
  36. randomrow = int (((intkitrowcount-1) * Rnd)+1)
  37. 'KitTable.SelectRow randomrow
  38. KitTable.SelectCell  randomrow, "企业名称"
  39. strkitorgname = KitTable.GetCellProperty (randomrow, "企业名称","Value")
  40. strkitorglicense = KitTable.GetCellProperty(randomrow, "许可证号", "Value")
  41. mgbox.Popup "现在选择的是第" & randomrow & vbnewline &_
  42.                       "企业名称:"&"  "&strkitorgname&vbnewline &_
  43.        "许可证号码:"& "  "&strkitorglicense, 3, " ", 1
  44. thewindow.SwfButton("加入我的监管对象").Click
  45. '***************************************在中心厨房Tab中***************************************************

  46. '************************************在我的监管对象Tab中************************************************
  47. Set MyFav = SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("监管对象设置")._
  48.                               SwfTable("swfname:=dgvOrganizationList","swfname
  49. path:=dgvOrganizationList;organizationSearchControl0;pnlMyFavourate;OrganizationDialog")
  50. thewindow.SwfRadioButton("regexpwndtitle:= 我的监管对象","swfname path:= rdoFavorite;panel1;OrganizationDialog"). Set
  51. GeneralAddedCheck MyFav,strkitorgname,strkitorglicense
  52. thewindow.close
  53. SwfWindow("食品安全电子化监管系统--城市运行区").Activate
  54. SwfWindow("食品安全电子化监管系统--城市运行区").SwfWindow("日常监管子系统").Activate
  55. Next  ' For i = 0 to yearslistcount -1 结束
  56. Function GeneralAddedCheck(tableobj,orgname,orglicense)
  57.    Set dictable = CreateObject ("Scripting.Dictionary")
  58.    Dim tablearray(1,0)
  59.    Dim genstrkey, gengetname, gengetlicense,rownum,getrowdata
  60.    Dim boolcheck
  61.    boolcheck = false
  62.    rownum = tableobj.RowCount
  63.    
  64.    For i = 0 to rownum -1
  65.      gengetname = tableobj.GetCellProperty (i,"企业名称", "Value")
  66.   gengetlicense = tableobj.GetCellProperty (i, "许可证号","Value")
  67.   tablearray (0,0) = gengetname
  68.   tablearray (1,0) = gengetlicense
  69.   genstrkey = tablearray (1,0)
  70.   dictable.Add genstrkey, tablearray
  71.   getrowdata = dictable.Item(genstrkey)
  72.      mgbox.Popup "当前选中的是第"& i &"行"&vbnewline&_
  73.                         "企业名:"& getrowdata(0,0)& vbnewline &_
  74.          "许可证号:" & getrowdata(1,0) & vbnewline, 5, "当前数据", 1
  75.      
  76.   If orgname = getrowdata(0,0) and orglicense = getrowdata(1,0) Then
  77.    mgbox.Popup "被添加的数据如下" & vbnewline &_
  78.                          "企业名:" & "   " & getrowdata(0,0) & vbnewline &_
  79.           "许可证号:" & "   " & getrowdata(1,0), 5, "一般化的SearchData方法
  80. ", 1
  81.   Reporter.ReportEvent micPass, "一般化的SearchData方法_添加到我的监管对象", "成功!!!!"
  82.   boolcheck = true
  83.   End If
  84.   If i = rownum -1 and boolcheck = false Then
  85.    mgbox.Pop "失败", 3, " ",1
  86.    Reporter.ReportEvent micPass, "一般化的SearchData方法_添加到我的监管对象", "失败囧囧囧囧"
  87.   End If
  88.    Next   
  89. End Function
  90. '************************************在我的监管对象Tab中************************************************
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2010-9-21 15:11:06 | 只看该作者
经过研究,其实只要把54-56行直接注释掉就可以循环了,呵呵,是我自己的一时疏忽。
和SetNextRow没有关系,不过还是要感谢TIB同学的回复,^_^。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2010-9-21 12:03:03 | 只看该作者
奥!? 谢谢奥,去研究下看看
回复 支持 反对

使用道具 举报

该用户从未签到

2#
发表于 2010-9-21 11:26:54 | 只看该作者
你可能需要用到 DataTable.SetNextRow

具体请查看QTP帮助文档中DataTable对象的使用方法
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-10-8 22:16 , Processed in 0.082804 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表