Thursday, June 16, 2011

Verify all WebCheckBoxes are checked in a WebTable

When testing a web application I wanted to check if all checkboxes in a webtable are checked.
Here is one simple solution that worked for me:

'count table rows
webtable_rows=Browser("version:=internet explorer 8").Page("title:=test*.*").WebTable("class:=rgMasterTable").RowCount


'count checked checkboxes
Dim oDesc
Dim colObject
Set oDesc=Description.Create
oDesc("micclass").value="WebCheckBox"
oDesc("checked").value=1
Set colObject=Browser("version:=internet explorer 8").Page("title:=test*.*").WebTable("class:=rgMasterTable").ChildObjects(oDesc)
checked_count=colObject.count

'if checked checkboxes number is equal to the rows number then all checkboxes are checked (in my case each row has a checkbox with property "checked" equal to 1 when checked and 0 when unchecked)
If webtable_rows=checked_count then
    reporter.ReportEvent micPass, "All rows selected",""
else
    reporter.ReportEvent micFail, "Not all rows are selected",""
End If

Note: Initially I wanted to do a for i=1 to webtable_rows and verify the checkbox on each row is checked, but I did not manage to make it work like this.

No comments:

Post a Comment