Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
finding expected value in webtable
#1
Solved: 6 Years, 6 Months ago
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.
Reply
#2
Solved: 6 Years, 6 Months ago
Easiest would be to check using debugger present in the UFT's IDE. Check the rowcnt and other variables during debugging.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#3
Solved: 6 Years, 6 Months ago
(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.
Reply
#4
Solved: 6 Years, 6 Months ago
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
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#5
Solved: 6 Years, 6 Months ago
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.
Reply
#6
Solved: 6 Years, 6 Months ago
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.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#7
Solved: 6 Years, 6 Months ago
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.
Reply
#8
Solved: 6 Years, 6 Months ago
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
Reply
#9
Solved: 6 Years, 6 Months ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to match weblist data with expected values Anupama 5 2,903 05-18-2018, 12:15 PM
Last Post: Ankur
  ALM resource(datatable) not used when expected psova 1 3,303 09-04-2013, 02:45 PM
Last Post: psova
  Not finding Mercury tours website sekmet 0 2,107 11-03-2008, 11:02 PM
Last Post: sekmet

Forum Jump:


Users browsing this thread: 2 Guest(s)