工具只是
自动化测试的手段,完全可以利用
其他方式来编写脚本自动化,今天的自动化脚本实现的目标是
Write a program to List all links in thewebpage?
Write a program to Check whether given link exists?
以上两个问题其实很类似,只不过是后面稍微变化了下,我们来看下代码的实现,根据第一个例子的解决方法实现第二个解决方法
程序1
问题1解决方法:
Dim oAnchors
Dim oAnchor
Set ōAnchors = Browser(X).Page(X).WebTable(X).Object.GetElementsByTagName("A") '获得页面的所有链接
For Each oAnchor in oAnchors
msgbox oAnchor.innertext
Next 'oAnchor
Set ōAnchors = Nothing
问题2解决方法
Dim oAnchors
Dim oAnchor
Dim blnFound
Set ōAnchors = Browser(X).Page(X).WebTable(X).Object.GetElementsByTagName("A")
blnFound = False
For Each oAnchor in oAnchors
If oAnchor.innertext = "Whatever" Then
oAnchor.Click()
blnFound = True
End If
Set ōAnchor = Nothing
If blnFound = True Then Exit For
Next 'oAnchor
Set ōAnchors = Nothing
实际问题应用:2006年在论坛上有位广州的朋友问得一个问题
QuickTestPro处理带有IFRAME的问题
原问题链接:
http://bbs.51testing.com/viewthread.php?tid=35723&extra=page%3D1
解决问题的答案:http://www.51testing.com/html/27/1566.html
http://www.51testing.com/html/27/1565.html
思考题:利用dom技术解决以上问题
项目实际问题延伸:
对比页面table表格中的数据,利用ado读取数据库内容,然后对比页面实际数据,页面扫描cell代码如下:
Dim objRows
Dim objRow
Dim objCells
Dim objCell
Dim blnFound
Dim lngCellCount
Set ōbjRows = Browser(X).Page(X).WebTable(X).Object.GetElementsByTagName("TR")
blnFound = False
lngCellCount = 0
For Each objRow in objRows
Set ōbjCells = objRow.GetElementsByTagName("TD")
For Each objCell in objCells
If objCell.InnerText = "需要查找的内容,可以利用数据库读取的数据对比" Then
'可以打印报告 你可以按照自己的意愿自己处理
End If
Set ōbjCell = Nothing
Next 'objCell
Set ōbjCells = Nothing
Set ōbjRow = Nothing
Next 'objRow
Set ōbjRows = Nothing