3 Answers, 1 is accepted
Hello Yan Jun,
You can iterate through the grid in a coded step and check for a specific content in any of the cells. Please check the example and details in this linked article and try it on your end.
I hope that will help you automate the test scenario. If you need further assistance, please share more details about your current code and what you want to achieve. I will do my best to help you automate it
Regards,
Plamen Mitrev
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi Plamen,
Thanks for the shared link. I have figured out how to loop through the table and verify each of the cell value now.
But I have another issue about verifying cell value. So I notice that if I use AssertContent to verify InnerText, if any 1 row of the value is found unmatched, then the execution of the loop in code will stop abruptly and will not continue to verify other rows.
May I know how do I overcome this issue? I would like to log error in the test result for that specific row that does not have matching value but at the same time continue to verify the other rows.
I have tried the following code but I keep having compilation error:
01.
for
(
int
i = 1; i <= itemCount; i++){
02.
03.
Object cellValue = invoiceTable.Rows[i].Cells[qtyIndex].InnerText;
04.
05.
if
(Assert.IsFalse(cellValue.Equals(
"10.00"
, ArtOfTest.Common.StringCompareType.Exact)) ==
true
){
06.
Exception ex;
07.
throw
new
Exception(
"Row "
+ i +
" ERROR: Quantity value does not match with Expected Result. \n\n"
+ ex.Message);
08.
}
09.
}
The compilation error:
error CS0176: Member
'object.Equals(object, object)'
cannot be accessed with an instance reference; qualify it with a type name instead
Please kindly advise if my code is wrong somewhere.
Thank you.
Regards,
Yan Jun
Hi Yan Jun,
I am happy to know that you can loop through the table and verify the content and I will gladly help you with the follow up question.
The test execution will stop if any of the test steps fails, including coded steps that have Assert verifications. So, to work around this, you need to surround the verification in a try -> catch block. This way your code should continue to loop through the whole table and make the specified verification. Please check the sample code below, which is recorded against this application.
foreach (HtmlTableRow r in Find.ByExpression<HtmlTable>("tagindex=table:0").AllRows)
{
foreach(HtmlTableCell c in r.Cells)
{
try {
c.AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Exact, "text to compare");
} catch {
Log.WriteLine("Did not match.");
}
}
}
Please adjust the above code to match the test scenario on your end and do not hesitate to contact us again, if you need further assistance.
Regards,
Plamen Mitrev
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.