Micro Focus QTP (UFT) Forums
finding expected value in webtable - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: finding expected value in webtable (/Thread-finding-expected-value-in-webtable)



finding expected value in webtable - Anupama - 05-21-2018

Hi,

I am trying to retrieve cell data from particular column and compare it with expected parameter value. But the loop immediately returns fail as soon as the first match fails, Below is my code, What am I doing wrong?

Code:
Function VerifyHistory()
    Dim funcName : funcName = "VerifyHistory"        
    Dim setupFuncName : setupFuncName =   "SETUP|" & funcName

rowcnt = Browser("Br").Page("Pg").WebTable("Tbl").Rowcount
For i = 2 To rowcnt
actual= Browser("Br").Page("Pg").WebTable("Tbl").GetCellData(i,4)
    If Instr(parameter.Item("Activity"),actual)>0 Then
ResultOutput "Pass", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual

else
 ResultOutput "fail", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
    End If
     Next

End Function 

Thanks in advance.


RE: finding expected value in webtable - Ankur - 05-22-2018

Easiest would be to check using debugger present in the UFT's IDE. Check the rowcnt and other variables during debugging.


RE: finding expected value in webtable - Anupama - 05-22-2018

(05-22-2018, 03:08 PM)Ankur Wrote: Easiest would be to check using debugger present in the UFT's IDE. Check the rowcnt and other variables during debugging.
I did that and the count returns as 5 and the loops is traversing for 5 times, even of the expected value is found it prints the result for 5 times for both PASS and FAIL. However I am expecting it print only the results once (either pass/fail) based on the item availability.


RE: finding expected value in webtable - Ankur - 05-22-2018

ah ... it is doing exactly what you are asking it to do.

You need to put Exit For just after the pass condition. Something like this -  


Code:
Function VerifyHistory()
   Dim funcName : funcName = "VerifyHistory"        
   Dim setupFuncName : setupFuncName =   "SETUP|" & funcName

rowcnt = Browser("Br").Page("Pg").WebTable("Tbl").Rowcount
For i = 2 To rowcnt
actual= Browser("Br").Page("Pg").WebTable("Tbl").GetCellData(i,4)
   If Instr(parameter.Item("Activity"),actual)>0 Then
ResultOutput "Pass", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
Exit For
else
ResultOutput "fail", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
   End If
    Next

End Function



RE: finding expected value in webtable - Anupama - 05-22-2018

Hi Ankur,

I have tried that as well, but as mentioned if the expected is found at 3rd position then it is printing fail for 2 times , 3rd time it get passed and prints pass value and then Exits for. But I was expecting it to print pass/fail only once depending on the item availability.


RE: finding expected value in webtable - Ankur - 05-22-2018

You need to write your question more clearly.

Also, I see you have removed (edited) one of your responses above and it breaks flow of the conversation. Please edit it to make sure the conversation flows naturally , so that someone with a similar issue in future can understand the question and answer.


RE: finding expected value in webtable - Anupama - 05-23-2018

I am sorry for that. To make my question clear, let us say the count that I get is 5 . So the code should search the loop for 5 times and then return pass/fail only once based on the expected item availability within the table. However if the expected value is found at the 3rd iteration the result that is being displayed is like below.

Fail (since the item found in 1st iteration is not matching the expected)
Fail  (since the item found in 2nd iteration is not matching the expected)
Pass (since the item found in 3rd iteration is matching the expected)

and after printing result in the above way, the for loop exists. However the result I was expecting is, it should iterate through the loop and print PASS/FAIL only once.


RE: finding expected value in webtable - Ankur - 05-23-2018

Do you mean as soon as the FIRST pass/fail is encountered , the loop should exit ? If yes, use this code


Code:
Function VerifyHistory()
  Dim funcName : funcName = "VerifyHistory"        
  Dim setupFuncName : setupFuncName =   "SETUP|" & funcName

rowcnt = Browser("Br").Page("Pg").WebTable("Tbl").Rowcount
For i = 2 To rowcnt
actual= Browser("Br").Page("Pg").WebTable("Tbl").GetCellData(i,4)
  If Instr(parameter.Item("Activity"),actual)>0 Then
ResultOutput "Pass", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
Exit For
else
ResultOutput "fail", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
Exit For
 End If
   Next

End Function

if you want exactly 1 pass and 1 fail value, use flags to do some manipulation. 

Code:
Function VerifyHistory()
  Dim funcName : funcName = "VerifyHistory"        
  Dim setupFuncName : setupFuncName =   "SETUP|" & funcName
  Dim flagPass, flagFail

rowcnt = Browser("Br").Page("Pg").WebTable("Tbl").Rowcount
For i = 2 To rowcnt
actual= Browser("Br").Page("Pg").WebTable("Tbl").GetCellData(i,4)

  If Instr(parameter.Item("Activity"),actual)>0 Then
ResultOutput "Pass", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
flagPass = 1
else
ResultOutput "fail", "Expected:"&parameter.Item("Activity")&vbnewline,"Actual: "&actual
flagFail = 1
 End If

If (flagPass = 1 and flagFail = 1) Then
Exit For
End If

Next

End Function



RE: finding expected value in webtable - Anupama - 05-23-2018

Something similar to First scenario but not exactly on First encounter of Pass/Fail. I want the loop to search the whole web list for the expected value and then return pass or fail based on the item availability.