David的测试技术空间,收藏好文档和分享我的技术理解。5年的数通产品测试和安全产品测试经验,3年Web产品测试和多年测试管理和测试工具开发经验。目前关注性能分析调优、Jmeter和TestNG+WebDriver+Hamcrest的培训推广。Welcome沟通交流,请留言或者发邮件到daviwang_2004 at soguo.com。

QTP: An interesting solution

上一篇 / 下一篇  2007-08-14 10:37:18 / 个人分类:QTP

转贴:http://geekswithblogs.net/tmoore/archive/2005/10/11/56669.aspx

QTP: An interesting solution

So, here I am working on our VBscrīpt communication shell wrapped around QTP for testing (for all of you QTP purists who would scoff at the use of this, read some of my earlier posts about why we use this) and I realize I need a way to handle nested tables. Now, the problem really is this: I have nested tables used to format some pages. Trouble is that deep down in there, there is an image on which I need to click. So, how to get there dynamically? I need code that will search the tables and find the particular thing for which I am looking, be it a string, or an object of some sort.

Well, I have a way on which I am working that seems to be the right track, and it looks something like this:

Set ōDesc = Descrīption.Create()
oDesc("html tag").Value = "TABLE"

Set ōChild = Browser("Browser").Page("Page").ChildObjects(oDesc)
 iTableCount = oChild.Count
 
 Msgbox "We have " & iTableCount &" tables"

 For lCount = 0 to iTableCount - 1 'Zero-based
  For lRowCount = 1 to oChild(lCount).RowCount
   'Msgbox "Table " & CStr(lCount) & " has " & oChild(lCount).RowCount  & " rows and " & Cstr(oChild(lCount).ColumnCount(lRowCount + 1)) & " columns." 
   For lColumnCount = 1 to oChild(lCount).ColumnCount(lRowCount)
    Msgbox "Current Cell: " & lRowCount  & "," & lColumnCount
    Msgbox "CellData: " & oChild(lCount).GetCellData(lRowCount , lColumnCount)
    
   Next
   
  Next
 Next
 oChild(0).ChildItem(2,2,"Image",0).Click
 
Set ōChild = Nothing

Set ōDesc = Nothing

Note that I've left some of the less interesting stuff out that opens the page, declares variables, etc. This will allow me to grab an array of all of the tables, interate through them, in turn looping thru each column and row. The click line works for my example HTML, but I need to tweak it to use the dynamic stuff above for the determination.

We are using the Descrīptive programming to get at our array of tables. Some interesting notes:

1) The tables array is zero-based

2) The rows/columns seem to be collections, and are therefore 1 based

3) The two tables in my example HTML are nested, but both show up in the tables array. I find this interesting, but very useful. Since it works that way, I don't have to loop a table's row/column combination to determine if a particular cell contains a nested table. Allows for a much more dynamic way to get at certain information.


TAG: QTP

 

评分:0

我来说两句

Open Toolbar