Sunday, 15 January 2012

Utility Objects


QTP Provides the several utility objects to enhance the power of scripting.Utility Objects are the reserved objects in QTP.These objects can be used in reporting preferences during run time.

There are various Types of Utility Objects:

1)Crypt Object
2)DataTable Object
3)Description Object
4)DotNetFactory Object
5)DTParameter Object
6)DTSheet Object
7)Environment Object
8)Extern Object
9)LocalParameter Object
10)MercuryTimers Object (Collection)
11)MercuryTimer Object
12)Parameter Object
13)PathFinder Object
14)Properties Object (Collection)
15)QCUtil Object
16)RandomNumber Object
17)Recovery Object
18)Reporter Object
19)RepositoriesCollection Object
20)Repository Object
21)Services Object
22)Setting Object
23)SystemMonitor Object
24)TextUtil Object
25)TSLTest Object
26)XMLUtil Object

Lets discuss some of them :-

1) Crypt Object

It is used to encrypt a string which can be protected .It uses the Encrypt method .

Ex: User_Name=Crypt.Encrypt("Jhon")  'It will show the string in a encrypted format'
       Msgbox User_Name

2) DataTable Object

It is used to retrieve the values from the datatable.It uses different methods like a)AddSheet b)DeleteSheet c)Export d)ExportSheet e)GetCurrentRow f)GetRowCount etc .

Ex: DataTable.GlobalSheet.AddParameter "Name","James"

3)Description Object

Generally description object is used to store a set of properties for a particular class which can be accessed by description object.

Ex:  Set W_Edit=Description.Create()
       W_Edit("name").Value="q"                               
       Browser("Google").Page("Google").WebEdit(W_Edit).Set "Mindfire"

4)DotNetFactory

DotNetFactory is used to create an instance of .Net Objects and access its methods and properties.Its associated method is CreateInstance method.

Ex: Set Create_Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form",  "System.Windows.Forms")         'It will create an instance of a blank Windows form object'
Create_Form.Show                    'It displays the form on the screen'


5)DTParameter Object

It is a parameter which can be accessed during run time by following methods or properties:
>DTSheet.AddParameter
>DTSheet.GetParameter

Ex:Show_Param=DataTable.LocalSheet.AddParameter("UserName","Mindfire")
      msgbox Show_Param

6)DTSheet Object

It is a Sheet which can be accessed during run time by following methods or properties:
>DataTable.AddSheet
>DataTable.GetSheet
>DataTable.GlobalSheet
>DataTable.LocalSheet

Ex: Show_Param=DataTable.GetSheet("mysheet").AddParameter("UserName","Mindfire")
       msgbox Show_Param

7)Environment Object

QTP Environment variables are special type of variables whose values persist across and are shared by all actions in a test.QTP environment variables can be used to share information across actions,recovery scenarios and libraries.

Ex: Environment.Value("My_Var")=10  
       My_Var=Environment.Value("My_Var")

8)Extern Object

Extern is a reserved object in QTP which is instantiated and is used to call external procedures from an external dynamic-link library (DLL).Its associated method is Declare().It is used as a reference to external procedures in DLL.

9)LocalParameter Object

A local Parameter is used to parametrize the value of a step in a business component.

Ex: Par_Val=Parameter.Item("UserName")
       Msgbox Par_Val


Tuesday, 3 January 2012

Step Into, Step Over and Step Out:-

Create a new test and function library as mentioned below .Give a breakpoint at line no. 8 as shown below.
 


Example of Step Into –

Run the test and it will pauses at line no 8,

Now press F11 (Step Into), line no. 8 gets executed and cursor will go to the next line “first line inside the function”. Again if we press F11 line no. 2 gets executed and cursor will go to the next line.
So, Step into (F11) only executes the current line and if current line calls a function, the cursor will go to the first line of called function.

Example of Step Out –

Run the test again and when test pauses at line no.8 ,press F11, Line no.8 gets executed the cursor will go to the first line of Action function .Now Press Step Out(Shift+F11) and all the lines inside the function will get executed .
Now run the test again by un commenting the lib function inside Action function.


The test pauses at line no. 8 and we need to press F11 and the cursor will go to first line of Action function .If we press (Shift+F11) ,line no. 2, 3,4 will get executed and cursor will go to the first line of lib function and test will again pauses there .


Now if we press (Shift+F11) the full lib function and remaining two lines (5, 6) of Action function will get executed.
So, Step Out can be only used after the step into (to enter into the called Action or Function) operation .Step out runs till the end of the called Action or Function library and then return to the calling Action of function and pauses the test.

Example of Step Over –

Run the test and when test pauses at line no. 8, press Step Over (F10), It will execute the full Action function at one go, Since Action function contains lib function, so lib function will also get executed.

So, Step Over runs the current step and if current step calls any library, the called library gets executed in its entirety. Step Over does not show the library while running it.