Posts: 13
Threads: 4
Joined: May 2018
Reputation:
0
05-21-2018, 05:16 PM
(This post was last modified: 05-21-2018, 05:18 PM by Anupama.)
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:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
else
ResultOutput "fail", "Expected:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
End If
Next
End Function
Thanks in advance.
Posts: 1,105
Threads: 18
Joined: Jan 2008
Reputation:
8
05-22-2018, 03:08 PM
Easiest would be to check using debugger present in the UFT's IDE. Check the rowcnt and other variables during debugging.
Posts: 13
Threads: 4
Joined: May 2018
Reputation:
0
05-22-2018, 03:56 PM
(This post was last modified: 05-23-2018, 11:42 AM by Anupama.)
(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.
Posts: 1,105
Threads: 18
Joined: Jan 2008
Reputation:
8
05-22-2018, 04:12 PM
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:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
Exit For
else
ResultOutput "fail", "Expected:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
End If
Next
End Function
Posts: 13
Threads: 4
Joined: May 2018
Reputation:
0
05-22-2018, 05:33 PM
(This post was last modified: 05-22-2018, 05:42 PM by Anupama.)
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.
Posts: 1,105
Threads: 18
Joined: Jan 2008
Reputation:
8
05-22-2018, 07:06 PM
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.
Posts: 13
Threads: 4
Joined: May 2018
Reputation:
0
05-23-2018, 11:39 AM
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.
Posts: 1,105
Threads: 18
Joined: Jan 2008
Reputation:
8
05-23-2018, 04:04 PM
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:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
Exit For
else
ResultOutput "fail", "Expected:"¶meter.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:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
flagPass = 1
else
ResultOutput "fail", "Expected:"¶meter.Item("Activity")&vbnewline,"Actual: "&actual
flagFail = 1
End If
If (flagPass = 1 and flagFail = 1) Then
Exit For
End If
Next
End Function
Posts: 13
Threads: 4
Joined: May 2018
Reputation:
0
05-23-2018, 06:20 PM
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.
|