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.

Tuesday 18 December 2012

CreateObject in QTP/vbScript


CreateObject is function which creates a reference to the specified object. You can then use the reference object to access the methods/properties of the specified object.

As createobject returns a reference to object, you must use Set to assingn it to a variable.

Set objExcel=CreateObject(“Excel.Application”)
‘Adding a workbook
Set objWorkBooj= objExcel.Workbooks.Add
‘Activating the sheet
Set objSheet=objWorkBook.Worksheets("Sheet1")
‘Writing values to excel
objExcel.Cells(row,column)=<”Your value>”

Below is the list of most commonly used objects. I hope you find it useful.

S.No
Object
Description
1
Set ObjectName= CreateObject("Wscript.shell")
Provides access to the native Windows shell. Provides functions to read system information and environment variables, to work with the registry and to manage shortcuts.
2
Set ObjectName = CreateObject("WScript.Network")
Provides access to the shared resources on the network to which the computer is connected.
3
Set ObjectName = Createobject("Excel.Application")
Perform operations on MS Excel.
4
Set ObjectName = CreateObject("Word.Application")
Perform operations on MS Word.
5
Set ObjectName = CreateObject("Outlook.Application")
Perform operations on MS Outlook.
6
Set ObjectName = CreateObject("InternetExplorer.Application")
Perform operations on Internet Explorer.
7
Set ObjectName = Createobject("QuickTest.Application")
Perform operations on Quick Test Professional (QTP).
8
Set ObjectName = CreateObject("QuickTest.UpdateRunOptions")
A collection of properties that indicate preferences for the Update Run in QTP.
9
Set ObjectName = CreateObject("QuickTest.RunResultsOptions")
A collection of properties that indicate preferences for the run results in QTP.
10
Set ObjectName = CreateObject("Scripting.FileSystemObject")
To work with the Windows file system structure: files, folders, drives.
11
Set ObjectName = CreateObject("Mercury.DeviceReplay")
Perform mouse or key operations exactly as they occur on the mouse or keyboard drivers.
12
Set ObjectName = CreateObject("Mercury.ObjectRepositoryUtil")
Perform an operation on QTP Object Repository.
13
Set ObjectName=CreateObjcet("Scripting.Dictionary")
Creates a dictionary object
14
Set ObjectName=CreateObject("vbScript.RegExp")
Creates a regular expression object
15
Set ObjectName = CreateObject("Mercury.FileCompare")
To compare two files.
14
Set ObjectName = CreateObject("Mercury.Clipboard")
Perform clipboard functionality.
15
Set ObjectName = CreateObject("Msxml2.DOMDocument")
Creates a DOMDocument object to perform operations related to XML document.
16
Set ObjectName = DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])
Returns a COM interface for a .NET object.
17
Set ObjectName = Createobject("shell.application")
To instantiate the Shell object, to program the Shell which can be used to access the file system, to launch programs, and to change system settings.
18
Set ObjectName= Createobject("TDApiOle80.TDConnection.1")
An object that enables to manage the Quality Center connection and retrieve the TDOTA object, which provides full interaction with Quality Center.
19
Set ObjectName = CreateObject("Microsoft.XMLDOM")
To access and manipulate XML documents via the XML DOM implementation, as exposed by the Microsoft XML Parser.
20
Set ObjectName = XMLUtil.CreateXML()
Creates and returns an object of type XMLData. If a root name is specified, a new document is created containing the specified root tag.
21
Set ObjectName = CreateObject( "AcroExch.App")
Acrobat OLE Automation Objects.
Set ObjectName = CreateObject( "AcroExch.AVDoc")
Set ObjectName = CreateObject( "AcroExch.PDDoc")
Set ObjectName = CreateObject( "AcroExch.HiliteList")
Set ObjectName = CreateObject( "AcroExch.PDBookmark")
Set ObjectName = CreateObject( "AcroExch.Rect")
22
Set ObjectName = CreateObject("ADODB.Connection")
Creates an instance of the ADO connection to connect to database.
23
Set ObjectName = CreateObject("ADODB.Recordset")
Creates an instance of the recordset object. To be able to read database data, the data must first be loaded into a recordset.
24
Set ObjectName =CreateObject("msscriptcontrol.scriptcontrol")
Perform operations to MS Windows Scripting Engine.
25
Set ObjectName = CreateObject("SAPI.SpVoice")
Auditory voice feedback during a test run, done by utilizing the Microsoft Speech API.
26
Set ObjectName = CreateObject( "UserAccounts.CommonDialog")
Object to provide users with a standard File Open dialog box
27
Set ObjectName = CreateObject("CDO.Message")
Windows CDO object is suitable for creating and sending automated emails.

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