Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing a generic Iterator


This recipe will describe how to implement a mechanism that is able to execute any operation for objects of any class repeatedly, until a condition is met or until the whole queue of objects is processed. The condition can be any expression that results in a Boolean value.

Getting ready

Create a new function library (for instance, cls.Iterator.vbs), and associate it with your test. In this recipe, we shall use the code from the previous recipe, Implementing function pointers.

How to do it...

Proceed with the following steps:

  1. In the function library, write the following code:

    Class Iterator
        Public Default Function Run(ByRef oCollection, _
                    ByRef ptrFunction, _
                    ByVal dicArgs, _
                    ByVal sExitCondition)
    
            Dim count, items, ix, str, dicResults
     
            'Create a Dictionary to store the results for each iteration
            Set dicResults = CreateObject("Scripting.Dictionary")
            
            'Get the collection count...