Wednesday, 31 August 2011

Utility Objects in QTP

This article explains the details about the Utility objects in QTP. QTP objects are reserved objects that are useful to enhance the power of scripting. QTP offers the following utility objects.
Crypt Object: This object encrypts the strings to meet the SetSecure standards. This object provides only "Encrypt" method. Assume that a password to be shared between two tests. In this scenario we can't pass the password directly. If we do, it'll be violating the security standards.So, we can use Crypt.Encrypt("password'). The output of this syntax will be something like "88e8df8dsf8sdfusdfuosffsdsf".So; the password will not be readable by other users as well as meeting the security standards. We can also the create the instance of Crypt object in VBScript by using               Set eCrypt =CreateObject("Mercury.Encrypter") statement.
OptionalStep:This object is used to set some of the steps as optional.
Assume that the Test is recorded with the Security Check enabled browser. So, we'll have the following code in the recorded test.
Browser("Browser").Dialog("Security Warning").WinButton("Yes").click
The above step will fail when the same Test is executed with the browser in which the Security Warning check is not enable. In such kind of situation we can use the "OptionalStep" object.We can convert the above code as follows.
OptionalStep.Browser("Browser").Dialog("Security Warning").WinButton("Yes").click
The above step will be executed if the browser has the security check enabled.Otherwise it'll be proceeded to next without failing status in the Test result.
PathFinder Object: This object is used to find the absolute path of a file.QTP allows the settings of the file path in Tools > Options > Folders Tab. In some of the situations we need locate the absolute path of the file.Assume that we have a file named "test.txt" which is placed in "D:\Setup" path and also assume that we have "test.txt" file is placed in "D:\Support" path.In such kind of scenario, we want to determine which particular folder, a file resides in we can use PathFinder.Locate object.By executing the following code we'll get the absolute path of "text.txt" file.rpath = PathFinder.Locate("test.txt").
The above code will return the path as "D:\Setup\test.txt". Because "D:\Setup" has the higher priority that "D:\Support" folder.

Tuesday, 30 August 2011

Environment Variables in QTP

This article gives the information about the environment variables in QTP.
Environment variables are like global variables. The value of these variables can’t be changed until the value changed dynamically when running the script.
Environment variables are used to share/keep the same value for a variable across actions. These variables can hold the values like OS Name, OS verison, TestName, TestDir, LocalHostName, ProductName, Product Directory etc.
QTP has two types of environment variables. They are Built In and User Defined.The important point to remember is the environment variables are global to QTP tests only. But Windows environment variables are global to all processes running on the specified machine.
Setting up the Environment variables: Navigate to Test>Settings> Environment Tab and click on Variable Type drop down list and observe that two options “Built In” and “User Defined” are displayed.
Built In Variables: Built in variables holds the values like OS Name, OS Version, Host Name and Test Directory in which the selected Test resides etc.
User Defined Variables: We have two types of user defined environment variables. They are internal and external. Internal variables are created and saved within the selected test. The value of the internal variables can be changed during run time. External variables can be defined in an external environment file. The value of the external variables can’t be changed during run time.
Passing Objects using Environment Variables: We can pass the object using environment variables in two ways. 
The first method is to passing the string definition of an object and convert it to an object.
Example:
'String form an object
Environment("TestBrowser") = "Browser(" "CreationTime:=0")"

Dim browserObject

'Execute the following code to set "TestBrowser" to browserObject

Execute "set browserObject ="& Environment("TestBrowser")

browserObject.close

Second method is directly assign the environment variable to the object.
Example:
'String form an object

Environment("TestBrowser") ="Browser(" "CreationTime:=0" ")"

Dim browserObject

'Execute the following code to set "TestBrowser" to browserObject

Set browserObject "&" Environment("TestBrowser")
browserObject.close 
Loading the environment variables from external file: We can use Environment.LoadFromFile  to load the environment variables from an external file. QTP will always keep only the variables which are recently loaded.
Example: Assume that the environment varianle “Env_File01.xml” is loaded first and “Env_File02.xml” is loaded recently. QTP will have only the environment variables which are loaded from “Env_File02.xml” file. This is the limitation in QTP.

Monday, 29 August 2011

Object Identification in QTP

This article explains the details about the object identification in QTP.
Object identification is the crucial part of a test case. QTP doesn't record the object properties arbitrarily, rather there is a configuration that QTP follows while recording a selected combination of properties. These properties can be changed in case the application requires a different combination.
The combination can be changed by navigating to Tools > Object Identification. There are 3 different properties that QTP uses for object identification.
Mandatory Properties: These are all the properties always captured and saved for the object even if it's not possible to identify some of the objects without anyone of these properties. Ex: html tag, name and type
Assistive Properties:These properties are used if the mandatory properties are not enough to uniquely identify the objects.  QTP adds the assitive properties one by one, in order specified until the object can be uniquely identified. Ex: outertext
Ordinal Identifiers: If,after using all mandatory and assitive properties, the selected objects still can't be uniquely identified, QTP then uses ordinal identifier. 
User Defined Objects:QTP uses the name of the Window to identify the object type.In case the application doesn't use Standard Window class QTP might be unable to identify the Object. Ex: Checkbox
Assume that the check box is not a standard window object. We can make it as a Windows object by using the following mechanism.
01. Navigate to Tools > Object Identification window.
02.Then select the option "Standard Windows" from Environment dropdown box.
03. The select "WinCheckBox" option from "Test Object Classes" table.
04. Then click on "User Defined" button and observe that a new window is opened.
05. Click on the hand icon to read the object and then click on the checkbox in web page needs to be added.
06. Then map it to "CheckBox" and then click on "OK" button.
07.Once mapped QTP will thereafter be able to identify the object as a WinCheckBox.

Sunday, 28 August 2011

Object Repository modes in QTP

This article explains the different types of object repositories in QTP. There are two types of objects repositories in QTP.
Local/Per Action Object Repository: These type of repositories are local to the action in which in resides means other actions can't be access these repositories.We need to remember the following points when using Local object repositories.
01. Objects will be added to the Local object repository if the selected object doesn't already exist in object repository.
02. Renaming an object in object repository doesn't affect other scripts. The current script is automatically updated with the renamed object.
03. Script changes to be done if the object identification properties changes.
04. These type repositories can be used when not many test cases are working on the same screens of the applications.
Shared object repositories: These type of repositories can be shared across the actions means the objects can be accessed from any action. We need to remember the following points when using the shared object repositories.
01. Renaming the test object will have the serious impact in script means the script will not be updated automatically.
02.Manual script update is not required when the object identification property changed. 
03.Should be used when different test cases access the same type of object in the application.
04. Shared object repositories needs to backed up frequently. Because these type of repositories can grow huge.

Saturday, 27 August 2011

Working with Test Object Properties

The following example demonstrates the usage of Test Object Properties.
' Get the webedit object
Set oedit = Browser("aaa"). Page("bbb"). webedit("")
' Get the Test Object Properties
Set TOProps = oedit.GetTOProperties
' Get the count of Test objects
Dim i, ocount 
Set ocount = TOProps.count
' Loop through the test objecs
For i=0 to count-1 
'Get the name of the property
Set oname = TOProps(i).Name
'Get the value of the property
Set oval = TOProps(i).Value
' Display the values
MsgBox "Name ---> " & oname & " Value --->" &oval

We can also modify the value of test object properties at run time by using SetTOProperty method.Assume that the test object's name is "oldname" we can use the following syntax to modify the test object property.


 objectname.SetTOProperty "oldname", "newname"

Once the above code is executed the current value of the selected test object becomes "newname".

We can use GetROProperty method to get the value of the run time object property. 

Note: QTP doesn't provide a method to modify or set the run time object property values.

Object Repositories in QTP

Object Repositories in QTP are used to store the elements in the application under test(AUT) in the form of objects to uniquely identify an object at run time.We can use the object repository manager to view and modify the various properties of the object.
Objects can be added into object repository in any one of the following methods.

1. By recording the user interactions with the application under test.
2. By manually adding one or more objects.

Objects can be manually added by clicking the Add Objects button and then clicking on the object that needs to be added.

In some scenarios the objects will be appeared on the screen after a mouse click.To achieve this,hold the CTRL key prior to the mouse click. This will disable the object selection mode and allows us to perform the mouse click operation. Then release the CTRL key and add the object to the repository.

In some scenarios we may need to switch between the applications. We can achieve this by holding CTRL+ALT to disable the object selection mode. Then use ALT + TAB to switching between the applications. Once done, press the CTRL + ALT ky to enable the object selection mode and add the object.


Once the object is added the added object will be displayed in object selection window.The object selection window displays the hierarchy of all objects in the selected page. Select the required object and click on OK button to add the desired element.

The object selection window has the following options.
01. Only selected object
02. Selected object and its direct children
03. Selected object and all its descendants

If option 03 is selected, it'll add all the objects present on the same page.

We have two type of objects in QTP. Test Objects(TO) and Run Time Objects(RO).

Test objects are QTP defined classes which are used to represent the various objects in the application under test.

Run time objects are the actual objects in application under test on which the actions are performed.

Test Object Properties are those that QTP maintains in object repository for identifying a run time object during test execution. QTP allows the enumeration of all TO properties using GetTOProperties method. GetTOProperty and SetTOProperty methods are used to get and modify the test  object property values respectively.

Types of Actions in QTP

We have the following types of Actions in QTP.
Non Reusable Action: This type of actions can be called only once that too in which Test the action resides.
Reusable Actions: These type if actions can be called n-number of types in which Test it resides as well as from other actions.
External Reusable Actions: These type of actions are stored in other tests as well as these type of actions are read only in the calling test.

 
Back To Top