比较Web表和数据库表:代码跳过DB记录

时间:2017-09-18 19:51:47

标签: vbscript automated-tests qtp

我有一个分为50多页的网页表,每页20条记录。需要针对sql db进行验证。

页面在表格底部表示为链接,如下所示:

enter image description here

现在,我的代码正确地点击了下一页(当前页面+ 1)并且没有问题地验证了第1页到第10页。但是当它点击最后一个链接(...)并转到第11页时,它会从数据库表中跳过20条记录,并开始从数据库中记录221的webtable验证记录201。这有什么问题?

这是我的代码:

set PagesLink=description.Create
PagesLink("micclass").Value = "Link"
PagesLink("html tag").Value = "A"

Do Until DBMaintenanceRS.EOF
Set PagesCollection = .WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").ChildObjects(PagesLink) 'Get links to pages. 10 links to pages are showed in bottom of table.

print PagesCollection.Count

For pc = 0 To PagesCollection.Count-1 'start pages loop

For rc = 2 to .WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").RowCount-1 'start table rows loop
        For cc = 2 To .WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").ColumnCount(1) 'start table columns loop
            wCell = .WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").GetCellData(rc, cc)
            dbCell = DBMa

intenanceRS.Fields(cc-2)
                    If trim(dbCell) = trim(wCell) Then
                        Print "Pass"
                    Else
                        print "FAIL::: ID="&.WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").GetCellData(rc, 2)&"-Column='"&.WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").GetCellData(1, cc)&"'-Value="&wCell&"-=-VS DB: "&dbCell
                    End If

            Next

            cc=""
            wcell=""
            dbcell=""
            DBMaintenanceRS.MoveNext
        Next
    rc=""
    print pc&"-=-"& PagesCollection(pc).GetROProperty("innertext")

    If pc=0 Then
        If NOT(PagesCollection(pc).GetROPRoperty("innertext")="...") Then
            PagesCollection(pc).Click
        End If
Else
    PagesCollection(pc).Click
End If
.Sync
wait 1

Set PagesCollection = .WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").ChildObjects(PagesLink)
Next
print "Next 10 pages"
pc=0
Set PagesCollection = .WbfGrid("html tag:=TABLE","html id:=cphBody_GridView1").ChildObjects(PagesLink)
print DBMaintenanceRS.Fields(0)
Loop

1 个答案:

答案 0 :(得分:0)

你的行计数变量(rc)是全局计数行,但网页只包含行的当前窗口(例如21..40)所以你的想法因为第21行实际上是当前WbfGrid的第一行。

您需要为数据库行和WbfGrid行设置单独的计数器。