Tuesday, 7 August 2012

What is the Basic difference between the Actions and Functions in QTP.

  • In QTP and Action both provides code modularity , And you can perform all the same things with Functions as you are able to do with actions.

– But Action can contains Object Repository, Data table, Active screen etc. whereas function do
not have these features.

– Action can be made Reusable / Non-Reusable as per need, where as Functions are written for
their re-usability only.

– Action is internal to QTP whereas Function is just lines of code with some/none parameters and
and a single return vale.( Can also return an array too)

--- But as per time complexity Function works faster than its respective action. Having a single
script that just calls multiple function appears to load and run faster than having a script that
calls multiple actions for performing the same intended thing.

--- Action Parameter have default values (From Action whereas VB script function do not have any
default values.

---- In my opinion , Action is mainly for navigation purpose and field entries where as Functions
are for checking validation for specific fields. For example , with the help of fuction we can we
verify in the date field (WebEdit) entered date is in what Format(MMDDYY orDDMMYY)
and it can be reused for all the date fields present in the application . There is no need to write
same code multiple times in the action.

How To define a Function and Call it :

Function Testfunction()
Print "Function test"
End Function


Function TestDemo(a,b)
myfunction2=a+b 'assign value to function name
End Function

 Call Function::--

Call Testfunction() 'calling 1st function, without any return value

Store=TestDemo(argument1,argument2) 'calling 2nd function, with a return value

the Function TestDemo returns a value that will be stored in the variable "abc". :


---- There is big disadvantage of using function is that partially from the library ("Run from step" option is not available) you are not allowed to run it partially while action can be executed from any step. This can make a significant difference for developing and maintaining of test scripts.


Function libraries should only be used as auxiliary resources, not as main script drivers. A function library should only contain code that repeats often in your tests (counters, reading values from a table, waiting for a browser to load etc.). Something to be done instead of typing that piece of code over and over again.

Wednesday, 13 June 2012

Automation Object Model

SOURECE QTP HELP FILE

We can use QTP Automation Object Model (AOM) to write scripts that automate QTP operations .The Quick Test AOM provides objects, methods, and properties that we can use to control Quick Test from other application .

*Here is the example how we can create the QuickTest application object and automate some basic operations of QTP :-

Dim qtApp=CreateObject(“QuickTest.Application”)   ‘ Create the application Object
qtApp.Launch  ‘ Start Quick Test
qtApp.Visible=True   ‘ Make it visible
qtApp.Options.DisableVORecognition = False
qtApp.Options.AutoGenerateWith = False
qtApp.Options.WithGenerationLevel = 2
qtApp.Quit

We can also create the object for Action,Action Parameter, Addin ,DataTable,Object Repositories etc. and successfully automate their operation from outside the QTP .

*Here is the example that opens QTP Test with associated addins:-

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim blnNeedChangeAddins ' Declare a flag for indicating whether the test's associated add-ins are currently loaded
Dim arrTestAddins ' Declare the variable for storing the test's associated add-ins

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

arrTestAddins = qtApp.GetAssociatedAddinsForTest("C:\Tests\Test1") ' Create an array containing the list of addins associated with this test

' Check if all required add-ins are all already loaded
blnNeedChangeAddins = False ' Assume no change is necessary
For Each testAddin In arrTestAddins ' Iterate over the test's associated add-ins list
    If qtApp.Addins(testAddin).Status <> "Active" Then ' If an associated add-in is not loaded
        blnNeedChangeAddins = True ' Indicate that a change in the loaded add-ins is necessary
        Exit For ' Exit the loop
    End If
Next

If qtApp.Launched And blnNeedChangeAddins Then
        qtApp.Quit ' If a change is necessary, exit QuickTest to modify the loaded add-ins
End If

If blnNeedChangeAddins Then
    Dim blnActivateOK
    blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescription) ' Load the add-ins associated with the test and check whether they load successfully.
    If Not blnActivateOK Then ' If a problem occurs while loading the add-ins
        MsgBox errorDescription ' Show a message containing the error
    WScript.Quit ' And end the automation program.
    End If
End If

If Not qtApp.Launched Then ' If QuickTest is not yet open
    qtApp.Launch ' Start QuickTest (with the correct add-ins loaded)
End If
qtApp.Visible = True ' Make the QuickTest application visible

qtApp.Open "C:\Tests\Test1" ' Open the test
Set qtApp = Nothing ' Release the Application object

Friday, 6 April 2012

Checkpoint and its Type


It is a specialized step that compares two values and and are given in the result .  A checkpoint used as Verification and compares the actual Results from the   expected results in a test plan.If two values in a checkpoint gets matched then the checkpoint passes or else it will get fail .This enables you to identify whether your Web site or application is functioning correctly. When we add a checkpoint, the test  adds a checkpoint to the current row in the Keyword View and adds a  CheckPoint statement in the Expert View. When we run the test , then it compares the expected results and the actual results.  You can view the results of the checkpoint in the Test Results window. These are similar to the  conditional statements(like If, if else,for, while etc).You can add checkpoints during a recording session or while editing your test or component . Checkpoints are stored in Local Object Repository.       

                  

When we Click on Record Button then all the checkpoints in Insert tab will get enabled.

Types Of Checkpoints
---------------------------------
1.Standard checkpoint

2.Text CheckPoint

3.Text Area CheckPoint

4.Bitmap CheckPoint

5.Database CheckPoint

6.Accessibility CheckPoint

7.XML CheckPoint (From Resource)

8.XML CheckPoint (From Application)

Standard Checkpoint :
--------------------------------


 It  checks the property  of the object in the web application .It checks a variety of objects such as buttons, radio buttons, webedits,WinButtons, lists.... etc.It compares the expected values of the object to the actual value during recording and run time .

Ex:  Browser("BrowserName").Page("PageName").Link("LinkName").Check CheckPoint("Comments")

 
Text Checkpoint :
------------------------       

In the Text Checkpoint we can define which text to be checked and as well as which is displayed before and after the checked text. This Verifies whether the text string is placed in appropriate place in the Web or Windows application .


There is a button called Configure in Text checkpoint Properties ,where we can edit the Text with  : Checked Text ,Text Before,Text After .It Displays the Checked text in Red and the Text Before and Text After in Blue.Edit the text and click Ok . It will be recorded and in the Expert View it will be displayed .It can be used for Windows or Web Application
Ex:Browser("BrowserName").Page("PageName").Check CheckPoint("The Text we are going to check")
Text Area Checkpoint :
----------------------------------
It is also simillar to Text Checkpoint . It verifies that the Text string is placed in Appropriate place in Windows Application. Here we can drag how much area in the Text to be taken in Windows Application .In order to devide or separate the captured Text, we need to use Configure button ( Checked Text ,Text Before,Text Before ).It is Applicable only for Desktop Application . Make sure to change the record and run settings to Windows Application.
Ex :Window("Desktop ApplicationName").CheckCheckPoint("The text what we are  going to check")

Bitmap Checkpoint :
-----------------------------

It is nothing but  checking  an area of a Web page or application as a bitmap. When we create a test ,then we need to specify the area that to be  checked. Here QTP captures tghe specified object as bitmap and inserts the checkpoint .Here it compares the selected areas of the object displayed in the application when recorded.After we select the bitmap, the image can be viewed in Bitmap checkpoint properties. 



In the Bitmap properties we have two options as Check entire bitmap and check only selected area. In Check entire bitmap the whole image  will be displayed where as in check only selected area can be edited there itself .



Specify the checkpoint timeout and click OK then a statement will displayed in expert view.
Ex:Window("Desktop ApplicationName").WinObject("Internet Explorer_Server").        Check CheckPoint("Internet Explorer_Server")
Database Checkpoint :
----------------------------------

It is used to test the contents of the database accessed by application under test. It stores the expected data and compares this with the data stored in the database. When we  use this checkpoint  in test, it connects  and sends the query to the database to retrieve the  data while recording. It compares the current dat with expected data and give the result as pass or fail.

When we go for database checkpoint then we need to go through Database query wizard.We have two query defination . For this we need to create Query for Create query using Microsoft Query or Specify SQL statement manually .
 Accessibility Checkpoint :
------------------------------------

It is the one which identifies areas of your Web site that may not conform to the World Wide Web Consortium (W3C) Content Accessibility Guidelines. We can add a checkpoints either while recording or editing the test.This is designed to find out the common areas in web site.It is supported for web add-in environment .
It is used to check for Activex check,Alt property check,Applet check,Frame Titles chek,Multimedia check,server-side check,Tables check.
 XML Checkpoint :
----------------------------

It is nothing but XML (Extensible Markup Language) This is the one which is used to check the data of XML documents in XML files or in web pages and frames .We can create XML file checkpoints in order to directly access and verifyspecified XML files in the system. It can be created  while  recording or editing your test or component.




In QTP, For  XML checkpoint(From Application) it cannot be used without using Record button.But wheras for XML CheckPoint(From Resource) Record is not used for checkpoint.  
Ex:1) XMLFile("Xml file").Check CheckPoint("Name of the file")
2)Browser("BrowserName").Page("PageName").WebXML("http:/www.abc.comXML/s").Check CheckPoint("http://www.abc.com/XML/simple.xml")

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.