Wednesday, November 16, 2011

Work With Dictionary Objects

Dictionary Object


Dictionary Object stores data key, item pairs. A Dictionary object stores the items 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.

Adavntages of using it in QTP:
1. can be used as Global variable declaration. so that any test can access the values from it in the run time.
2. You can store and retrive any number of run time values in to dictonary.
3. It is one of the Parameterization technique we can use in QTP

Disadvantages:
we can not specify the values in the desingn time like Datatable , Action parameters, environment variable. Useful in RunTime only.

Add Method

Adds a key and item pair to a Dictionary

object. object.Add (key, item)

Arguments : object Required. Always the name of a Dictionary object.
key Required. The key associated with the item being added.item Required.
The item associated with the key being added.

Remarks
An error occurs if the key already exists.

Example - Add Method

Dim d ‘ Create a variable.
Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”

Items Method

Returns an array containing all the items in a Dictionary object.

object.Items( )
Remarks The object is always the name of a Dictionary object.The following code illustrates use of the Items method:

Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
a = d.Items ‘ Get the items.
For i = 0 To d.Count -1 ‘ Iterate the array.
s = s & a(i) & “
” ‘ Create return string.
Next
Msgbox s
Exists Method

Returns true if a specified key exists in the Dictionary object, false if it does not.

object.Exists(key)

Arguments

object Required. Always the name of a Dictionary object.
key Required. Key value being searched for in the Dictionary object.

Remarks

The following example illustrates the use of the Exists method.

Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
If d.Exists(“c”) Then
Msgbox “Specified key exists.”
Else
Msgbox “Specified key doesn’t exist.”
End If
Keys Method

Returns an array containing all existing keys in a Dictionary object.

object.Keys( )

Remarks

The object is always the name of a Dictionary object.

The following code illustrates use of the Keys method:

Dim a, d, i ‘ Create some variables.
Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
a = d.Keys ‘ Get the keys.
For i = 0 To d.Count -1 ‘ Iterate the array.
s = s & a(i) & “
” ‘ Return results.
Next
Msgbox s
Remove Method

Removes a key, item pair from a Dictionary object.

object.Remove(key)

Arguments
object Required. Always the name of a Dictionary object.
key Required. Key associated with the key, item pair you want to remove from the Dictionary object.

Remarks

An error occurs if the specified key, item pair does not exist.
The following code illustrates use of the Remove method:

Dim a, d ‘ Create some variables.
Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
d.Add “c”, “Cairo” …
d.Remove(“b”) ‘ Remove second pair.
RemoveAll Method

The RemoveAll method removes all key, item pairs from a Dictionary object.

object.RemoveAll( )

Dim a, d, i ‘ Create some variables.
Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
d.Add “c”, “Cairo” …
a = d.RemoveAll ‘ Clear the dictionary.

Friday, November 4, 2011

QTP Extensibility - dll (Addin Creation)

Inorder to develop the dlls you need to install VS.Net2005, then once you install the .Net Addin Extensibility for QTP you will get a QTP addin template in the VS.Net new Project templates dialog box. (Windows Application, Web Application, etc., QTP addin)

After selecting the QTP template u will b asked for the control for which u want to provide the support - u need to give the full name(available in the references tab of VS.net) of the control. Once you fill in the other wizards u will be getting a class with commented code u can follow the comments and write ur own code.

Once you build the dll an XML file will get generated in the solution explorer. Copy the content of the XML and paste it in the SWFConfig.xml file persent in the installation folder of QTP. Exit and launch the QTP.

Thursday, July 14, 2011

QTP on Vista "IE7" - Not able to recognize object

You will find in most of the time that QTP will not able to recognize objects on Windows Vista or Windows 7. You may be wondering what has happened?? There are two things one should remember before automating the application is: 1. Open the Web application after you start QTP. 2. If still the error exists, and QTP is not able to recognise the objects then you need to lower down the security settings of your browser to the initial where it will allow QTP to recognise the objects.

Tuesday, July 12, 2011

AOM to load Object Repository (Shared) at Runtime. How?

Reference : HP QTP Automation Object Model - What & Why?

Now to load shared object repository runtime, we need to use the AOM approach. You can write the script inside QTP however it is not the right approach and not intended to be used this way.

Advantage: Using this approach you can import the OR just like your datatable at runtime. This will give flexibility when you are designing an automation framework

Be sure of the path of the OR 'path of shared OR tsr file' where you have saved the file

You can now add the necessary step in the generated script (in the last Script looks like in the Launch.vbs):

Script:

Dim qtApp 'Declare the application Object Variable

Dim qtObjRep 'Declare the object repository object

Set qtApp = CreateObject("QuickTest.Application") 'Creating and setting the QuickTest Application object to qtApp

Set qtObjRep = qtApp.Test.Actions().ObjectRepository 'Get the object repository collection collection object for the test action

qtObjRep.Add "Path of the Shared OR .tsr file",1

OR

qtApp.Test.Settings.Resources.ObjectRepositoryPath = “Path of the shared OR .tsr file



HP QTP Automation Object Model - What & Why?

Testers can use Quick Test Automation Object model to drive/automate the QuickTest operations/features. The Quick Test Automation Object Model (AOM) provides classes, objects, methods and their properties which enable the automation tester to control the QuickTest features from another application.

For example
If you want to invoke QTP and execute a test you would write a small invocation script to invoke and execute a test. You can also write an automation script to run selected batch of tests. Advantage : This would help me creating a testing automation framework and in test management.

Creating Automation Program
The properties tab of the test settings dialog box, the General Tab of the options dialog box and the object identification dialog box each contains a "Generate Script" button. Clicking this button and saving it would create a .vbs file containing the current test settings.

You can now run the .vbs file to invoke QTP with the exact configurations that when script is generated, or you can copy and paste the selected lines from the generated file into your own automation script.

Generating the automation script from QTP Options:
1. Go to Tools -> Options
2. Select the General Tab
3. Click Generate Script and save it as Launch.vbs (can be any name given)

Generating the automation script from the Test Settings:
1. Go to Test -> Settings
2. Select the properties Tab
3. Click on generate script and save it as Launch.vbs (can be any name given)

Generating the automation script from the object identification settings:
1. Go to Tools-> Object Identification
2. Click Generate Script and save it as Launch.vbs (can be any name given)

The QTP automation object model reference file is the help file provided by HP, that provides detailed description, syntax information and examples for the object, method and properties in the Quick Test Automation object Model.