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.


Post a Comment

Back To Top