Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Understanding Extern, Crypt and Environment Utility objects in QTP

In this post, We  will discuss about following utility objects in QTP.

Crypt Object
Environment Object
Extern Object


1. Crypt Object 


 Crypt object is used to encrypt the string. An encrypted string is generated for the provided string during Crypt.Encrypt method. This is useful for providing Password details and entering data in a field as setsecure.

Syntax : crypt.encrypt(strPass)


If we want to use this method through VBScript, we can create an instance of object using

Set crypt= CreateObject("Mercury.Encrypter")


2. Environment Object


Environment Object enables QTP to retrieve information  from the environment variables defined in QTP, Add new environment variables, and loading environment variables from external file.

Below are described the properties and method for Environment object.


Environment.value(EnvName) = EnvValue  will set the value of environment variable EnvName as EnvValue.


envVal = Environment.value(EnvName) will get the value of environment variable envName in variable envVal.


Environment.ExternalFileName will returns the ExternalFileName associated with the test.Will return “” if no externalfile is associated.


Environment.LoadFromFile(FileName) will load external user defined environment variables from the file specified.


3. Extern Object


By defining methods using extern object in QTP, we can call functions from external libraries. This is very useful to run functions from external DLL’s.

Using Extern Object

a. Declare Extern defintion

The syntax for declaring an extern object is as follows:

Extern.Declare micHwnd,UserProcedureName,DLLName,ProcedureinDLL, micString, micint


The above declaration declares user defined procedure UserProcedureName from procedure ProcedureinDLL in the DLL specified in DLLName. Next arguments are the datatype of various argument to be used when calling the procedure defined in extern.declare.


e.g : Extern.Declare micLong, "InternetOpen", "Wininet.dll", "InternetOpenA", micString, micDWord, micString, micString, micDWord will call InternetOpenA procedure from DLL  “Wininet.dll” on calling the method “InternetOpen”.Similarly other procedure from DLL can be declared using extern.declare.


b.Using procedure defined in Extern.declare

 Once we have defined the procedures using Extern.declare, we can call as shown below:

objIEOpen= Extern.InternetOpen("QTP_FTP", 1, vbNullChar, vbNullChar, 0).

Note we have to provide arguments with data type as defined during extern declaration above.
This will execute the procedure in DLL as specified in extern.declare.


No comments:

Post a Comment