Welcome To Automation Testing

Before starting with tips of automation of SAP using QTP Let me give a small introduction of SAP and QTP.

SAP stands for System Applications and Products. It is the name of both the online financial and

Administrative software and the company that developed it. SAP is made up of individual modules that perform various organizational system tasks.



Quick Test Professional (QTP) is an automated functional Graphical User Interface (GUI) testing tool that allows the automation of user actions on a web or client based computer application.

It is primarily used for functional regression test automation. QTP uses a scripting language built on top of VBScript to specify the test procedure, and to manipulate the objects and controls of the application under test. It supports many applications through the support of add-ins.



We will be using SAP add-in with QTP to work on the SAP automation.

Saturday 17 November 2012

Get unique items from an array/Remove duplicate items from an array


There may be multiple ways to get unique elements from an array; I found using dictionary object to do the task is simple and the best. Let me first talk about dictionary objects.
A Dictionary object is a kind of array with items and keys. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.
I would be using dictionary object’s “CompareMode” property to get the unique elements from the array. Below code explains how comparemode works and how it will be useful in removing duplicate items.

Dim d
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare
d.Add "a", "Athens"   ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
d.Add "B", "Baltimore"   ' Add method fails on this line because the
                                                ' letter b already exists in the Dictionary.

This means if Comparemode is set to text compare, duplicate items cannot be added to dictionary objects. Same logic we will be using in our function. We will keep on adding the array items to dictionary objects. As CompareMode is set to vbTextCompare, duplicate items will not be added. Hence at last we will get a dictionary objects with unique/No duplicate items. We can then assign the dictionary object items to an array.

Public Function Remove_Duplicate_Items_From_Array(arrayName)

                'Create a dictionary object
                Set objDict = CreateObject("Scripting.Dictionary")
                objDict.CompareMode = vbTextCompare

                'iterate through the values
                For each val in arrayName
                      objDict(val) = val
                Next
               
                newArray = objDict.Items            ‘Assign the itesm to array
                Remove_Duplicate_Items_From_Array=newArray
               Set objDict=Nothing ' Release object
End Function