1. ## Verify Sequence

Hi all,
if anybody can help me on this one. I have table loaded to qtp with specific ids and name related to it. In qtp I need to write a code that, when I run script it will get all transactions that on the screen and then need to verify if those transactions in the sequnce provided in the table that was loaded previously.
For example

Table
001 Purchase
007 Payment
002 Purchase
003 Late fees
010 Cash

On the screen:

002 Purchase
010 Cash

This point should pass, if :

010 Cash
002 Purchase

Then this will be not in sequence.

I hope I explained. I do have table of about 300. What would be the best way to go about, anybody? Thnx in advance

2. ## Re: Verify Sequence

Load both lists of items into two arrays. arSequence would contain the preloaded list of all the items int he right sequence. arItems would contain the items in whatever order you find them on the screen.

Then step through arItems one at a time, searching for it in arSequence. The trick is, begin each search in arSequence at the point where the last one was found. So if the first item in arItem was found at position 3 in arSequence, then when you look for the second item, begin your search in arSequence at 4 instead of 0. If you find the second item at position 5, then you will begin searching for the third item at position 6.

If you reach the end of arSequence before you have found everything in arItem, then your test fails. If you find everything in arItem without running out of arSequence, then your test passes.

It's a bit tricky to code that, but not too hard, and all in all, an interesting exercise in nesting loops and using iterative searches.

3. ## Re: Verify Sequence

Thank you for reply, I will look into this one, at least I have some ideas. thnx again

4. ## Re: Verify Sequence

Hi denka,
Here's one way to do it by putting your sequence into a hash (dictionary object). <font class="small">Code:</font><hr /><pre>'**************************************
Function checkOrder( oD, aA, aScreen)
dim iPrevious: iPrevious = -1

For each e in aScreen
If not iPrevious &lt; oD(e) then
msgbox join(array("Screen error", aA(iPrevious), "index", iPrevious, "not less than", e, "index", oD(e)))
end if
iPrevious = oD(e)
Next
End Function

'
'Test code
'
Dim oD: set oD = CreateObject("Scripting.Dictionary")
Dim aA: aA = Array("001 Purchase", _
"007 Payment",_
"002 Purchase",_
"003 Late fees",_
"010 Cash")
For i = 0 to ubound(aA)
Next
Dim aScreen1: aScreen1 = Array("002 Purchase",_
"010 Cash")
call checkOrder( oD, aA, aScreen1)
'
Dim aScreen2: aScreen2 = Array("010 Cash",_
"002 Purchase")
call checkOrder( oD, aA, aScreen2)
</pre><hr />
Regards,
M.

5. ## Re: Verify Sequence

nice approach, is there a way to load table and assign to array automatically instead of hardcoring to the script. Values might change.

6. ## Re: Verify Sequence

[ QUOTE ]
nice approach, is there a way to load table and assign to array automatically instead of hardcoring to the script. Values might change.

[/ QUOTE ]

You could declare an array with the row count in the table and then set value from table into the array.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.