Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparision Of whole 1 webtable to another
#1
Not Solved
Hi Team,

In one of the application, it is generating 1 webtable depending on the inputs we provide. So, the row the column are not fixed. The same webtable will generate on the another page. So, I need to compare these two webtables.
Is their any way that I can compare the whole webtable?
Reply
#2
Not Solved
You can try the following code to compare two different web tables:-

Code:
Dim TableMatched = True

Set Table1 = Browser("abcd").Page("efgh").WebTable("xyz")

Set Table2 = Browser("abcd").Page("efgh").WebTable("pqr")



       For rowcntr=1 to Table1.RowCount

                  For colcntr=1 to Table1.ColumnCount

                           If Table1.getCellData(rowcntr,colcntr) = Table2.getCellData(rowcntr,colcntr) Then

                                     TableMatched = TableMatched AND True

                            Else

                                     TableMatched = TableMatched AND False

                           End If

                  Next

       Next


if TableMatched Then

        Print "Table Matched"

Else

        Print "Table Not Matched"

End If
Reply
#3
Not Solved
Anand:

Question: if there is a difference between the two tables, do you need to know which cell(s) is different or simply that the two tables are not identical?

How many rows / columns will be in a table?

Your needs affect the programming that would be required.


Parke
Reply
#4
Not Solved
Anand:

I am including two subs which will find all cells that are different between the two web tables. I have hard coded the number of rows and columns. You will need to modify those values.

Both programs will print which rows and cells are different.

Method 1 using the standard OR technique. Method 2 uses the DOM technique. The article that caused me to work with DOM is http://qtpprashanth.blogspot.com/2011/03...h-qtp.html.

In my experiments the web tables had 20 rows and 6 columns. The OR technique took around 100 sec while the DOM method took around 5 sec.

hth,

Parke

Code:
Sub Compares_rows_of_two_web_tables
    startTime = timer
    Dim table1_arr(21)
    str = ""
    For nrow = 1 to 21
        For ncol = 1 to 6
            str = str & ";:" & Browser("Browser").Page("Page").Frame("frSheet").WebTable("1").GetCellData(nrow,ncol)
        Next
        table1_arr(nrow) = str
        str = ""
    Next
    
    'For i = lbound(table1_arr) to ubound(table1_arr)
    '    print "row " & i  & " is " & table1_arr(i)
    'Next
    
    Dim table2_arr(21)
    str = ""
    For nrow = 1 to 21
        For ncol = 1 to 6
            str = str & ";:" & Browser("Browser_2").Page("Page").Frame("frSheet").WebTable("1").GetCellData(nrow,ncol)
        Next
        table2_arr(nrow) = str
        str = ""
    Next
    
    'For i = lbound(table2_arr) to ubound(table2_arr)
    '    print "row " & i  & " is " & table2_arr(i)
    'Next
    
    For rowNum = 1 to UBound(table1_arr)
        If table1_arr(rowNum) <> table2_arr(rowNum) Then
            print "row " & rowNum & " are not the same"
        End If
    Next
    
    For rowNum = 0 to UBound(table1_arr)
        If table1_arr(rowNum) <> table2_arr(rowNum) Then
            print "row " & rowNum + 1 & " are not the same"
            tabl1_row_arr = split(table1_arr(rowNum),";:")
            tabl2_row_arr = split(table2_arr(rowNum),";:")
            For k = LBound(tabl1_row_arr) to UBound(tabl1_row_arr)
                If tabl1_row_arr(k) <> tabl2_row_arr(k) Then
                    print "for row, " & rowNum & ", cell " & k & " are not the same in the two tables."
                end If
            Next
        End If
    Next
    
    endtime = timer
    runTime = endTime - startTime
    print "runTime = " & runTime

End Sub    ''// Compares_rows_of_two_web_tables
Code:
Sub Compares_rows_of_two_web_tables_DOM_2
    
    Set oTable = Browser("Browser").Page("Page").Frame("frSheet").WebTable("1")
    'innertext =  oTable.Object.rows(3).cells(2).innertext
    'print innertext
    
    Dim table1_arr(20)
    str = ""
    For nrow = 0 To 20    
        For ncol = 0 to 5
            str = str & ";:" & oTable.Object.rows(nrow).cells(ncol).innertext
        Next
        startTime = timer
        table1_arr(nrow) = str
        str = ""
    Next
    
    Set oTable2 = Browser("Browser_2").Page("Page").Frame("frSheet").WebTable("1")
    'innertext =  oTable2.Object.rows(3).cells(5).innertext
    'print innertext
    
    Dim table2_arr(20)
    str = ""
    For nrow = 0 To 20    
        For n = 0 to 5
            str = str & ";:" & oTable2.Object.rows(nrow).cells(CInt(n)).innertext
        Next
        table2_arr(nrow) = str
        str = ""
    Next
    
    For rowNum = 0 to UBound(table1_arr)
        If table1_arr(rowNum) <> table2_arr(rowNum) Then
            print "row " & rowNum + 1 & " are not the same"
        End If
    Next
    
    'endtime = timer
    'runTime = endTime - startTime
    'print "runTime = " & runTime
    
    For rowNum = 0 to UBound(table1_arr)
        If table1_arr(rowNum) <> table2_arr(rowNum) Then
            print "row " & rowNum + 1 & " are not the same"
            tabl1_row_arr = split(table1_arr(rowNum),";:")
            tabl2_row_arr = split(table2_arr(rowNum),";:")
            For k = LBound(tabl1_row_arr) to UBound(tabl1_row_arr)
                If tabl1_row_arr(k) <> tabl2_row_arr(k) Then
                    print "for row, " & rowNum + 1 & ", cell " & k & " are not the same in the two tables."            
                End If
            Next
        End If
    Next
    
    endtime = timer
    runTime = endTime - startTime
    print "runTime = " & runTime

End Sub  ''// Compares_rows_of_two_web_tables_DOM_2
Reply
#5
Not Solved
BadrinarayananR

Thanks.

But these two webtables are not at same page. Sad.
Anyways, thanks for your response.



Parke - Thanks. But can I use these codes if these webtables are not at same page?
Reply
#6
Not Solved
Anand:

In math, the browser name, page title, etc, are just dummy variables. Your page might not have a frame and I would be surprised if your table was named "1". Adjust those "variables" to suite your needs.

As you might have noticed, I used two different browsers. I did this to make my programming easier. You would run the oTable part on the first page and the oTable2 on the second page. Just remember to set the names to what is in your OR.

hth,

Parke
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Genaralised code for checking the comparision of two xml files having child nodes. Ganta 4 3,827 11-18-2009, 07:26 PM
Last Post: Ganta

Forum Jump:


Users browsing this thread: 2 Guest(s)