Monday, 3 February 2014

Debugging in QTP


Debugging is the process of locating and fixing bugs in computer program code.
Before starting debugging in QTP, We need to install Microsoft debugger for debugging. This can be done during QTP Installation. Also we can install this manually later.
Pause:
To detect and isolate defects in a test or function library, you can control the run session using the Pause command. This will pause the test run and you can check for state of objects, and values in variable at the moment of pause to get the issue. You can temporarily suspend a run session by choosing Debug > Pause or clicking the Pause button. The Test execution will resume if we Press F5 or Run.

Step Into:
While navigation into a function definition from the function called in script. We can use Debug>Step Into or Press F11 or click on Step into button. Using Step Into, we can debug in the function called in script and run each step line by line in the function.

Step Over:
Step Over does debugging line by line in the script, but does not debug into a function called within script, but executes the function as a step and moves to next step in the Test. We can use Step Over using F10 Key or Debug>Step Over or icon for Step Over in the QTP.

Step Out:
Suppose we have step into a function as explained in Step To, and wants to come out of the function or Action, we use Step Out Option. We can use Step Over using shift + F11 Key or Debug>Step Out or icon for Step Out in the QTP IDE.

Run To Step:
You can instruct QTP to run from the beginning of the test or action or from the current location in the test and to stop at a particular step. This is similar to adding a temporary breakpoint to a step.
To select Run to Step, Insert your cursor in the step in which you want QuickTest to stop the run and choose Debug > Run to Step or press Ctrl+F10

Debug from Step
You can instruct QuickTest to begin your debug session from a particular step instead of beginning the run at the start of the test or action. Before you start debugging from a specific step, make sure that the application is open to the location.
To debug a test from step, Insert your cursor in the step where you want QuickTest to start the run and choose Debug > Debug from Step.

Using BreakPoints in QTP:
We can use breakpoints to suspend a run session and inspect the state of your application or mark a point from which to begin stepping through a test or function library.
Breakpoints are applicable only to the current QuickTest session and are not saved with the tests.
Test execution pauses at the step where we provide breakpoint. A breakpoint can be inserted using Debug > Insert/Remove Breakpoint or clicking Insert/Remove Breakpoint button or pressing F9 key on the step.
To enable\disable a breakpoint, i.e enable a checkpoint if disabled below or vice versa, Press Ctrl + F9 or select Debug > Enable/Disable Breakpoint
We can enable disable all breakpoint by selecting Debug > Enable/Disable All Breakpoints or click the Enable/Disable All Breakpoints button.

Debug Viewer in QTP:
We can use debug Viewer in QTP to view, set, or modify the current value of objects or variables in your test or function library, To view Debug Viewer, Choose View > Debug Viewer or click the Debug Viewer button.

Below are the tabs in Debug Viewer:

Watch Tab
This is used to view the value of any variable or an expression in the test. To add an expression, Click the expression and choose Debug > Add to Watch.

Variables Tab
QTP automatically displays the current value of all variables in the current action or function in the Variables tab—up to the point where the test or function library is stopped or paused. We can change value of a variable manually also in variables tab. This will be reflected in test.

Command tab
This is to execute a line of script to set or modify the current value of a variable or VBScript object in your test or function library.



Sunday, 2 February 2014

How to get distinct value from an array

In this post, we will check, how to get unique/distinct values from an array.
We will do that using very useful and optimum feature of QTP - Dictionary Object.

Here is the code--

Dim objDict, oldArray, val
Array1 = Array ("101", "201", "101", "301", "201", "401", "301")


Set objDict = CreateObject("Scripting.Dictionary")
objDict
.CompareMode = vbTextCompare

For each val in Array1
objDict
(val) = val
Next

Array2 = 
objDict.Items

For i=0 to ubound(Array2)
msgbox
 Array2(i)
Next 

How to get User Name of the machine

Here in this post we will quickly see how to get the User Name of the machine you are executing your test. It's useful specially in results of your test. If you have have more then one users/machines involved in the test execution, it'll help you to differentiate which tests have been executed on which machine..  

Function f_GetSystemUserName()
    Set oSystemInfo = CreateObject("ADSystemInfo") 
    Set oUser=GetObject("LDAP://" & oSystemInfo.UserName)
    f_GetSystemUserName= oUser.DisplayName
    Set oSystemInfo = Nothing
    Set oUser = Nothing
End Function    'End of function f_GetSystemUserName()

'Calling above function 
Msgbox f_GetSystemUserName()

Thursday, 30 January 2014

Different ways to associate function library to QTP Script

Most of the times, when you are creating test scripts or are designing a new QTP Framework, you would be trying to come up with reusable functions which you would have to store in the function library. Now, in order to use this function library with multiple test cases, you need to associate this function library with your test script. There are 4 methods to associate function library to QTP test.


Based on the type of framework you are using, you can use any of the following methods to associate function libraries to your QTP Script -
·         1) By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
·         2) By using Automation Object Model (AOM).
·         3) By using ExecuteFile method.
·         4) using LoadFunctionLibrary method.


Let’s see in detail how each of these methods can be used to map function libraries to your test scripts.
1. Using ‘File > Settings > Resources > Associate Function Library’ option from the Menu bar
This is the most common method used to associate a function library to a test case. To use this method, select File > Settings option from the Menu bar. This will display the ‘Test Settings’ window. Click on Resources from the left hand side pane. From the right hand side pane, click on the ‘+’ button and select the function library that needs to be associated with the test case.



2. Using AOM (Automation Object Model)
QTP AOM is a mechanism using which you can control various QTP operations from outside QTP. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.
Example: Using the below code, you can open QTP, then open any test case and associate a required function library to that test case. To do so, copy paste the below code in a notepad and save it with a .vbs extension.
'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True

'Open a test and associate a function library to the test
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries

'If the library is not already associated with the test case, associate it..
If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added
  objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case
End

3. Using ExecuteFile Method

ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file (function library) are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.
'Action begins
ExecuteFile "C:\YourFunctionLibrary.vbs"

'Other logic for your action would come here
'.....

4. Using LoadFunctionLibrary Method

LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.
'Some code from the action
'.....

LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs" 'Associate a single function library
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs" 'Associate more than 1 function libraries

'Other logic for your action would come here
'.....
This was all different way to associate function library to QTP test.




Wednesday, 29 January 2014

Selecting Test Case for Automation

It is impossible to automate all testing, so it is important to determine what test cases should be automated first. Tests at the system level comprise of a combination of Smoke & Regression test cases. The Test team needs to review all the test cases to determine which test cases are good automation candidates and which should be performed manually. Analyzing what to automate is one of the most crucial aspects of the Automation Testing.
The following types of test cases are preferred (but not limited to) choice for automation:
§  Tests that need to run for every build.
§  Tests that tend to cause human error.
§  Tests that use multiple data values for same action.
§  Identical tests that need to be executed using different browsers & on different OS.
§  Tests that take a lot of effort and time when manual testing.
§  Frequently used functionality that introduces high risk conditions.
§  Tests requiring a great deal of precision
Also above test cases have following characteristics:
·         Should be atomic and have a clear objective.
·         Provides good coverage.
·         Identifies the most number of defects.
·         Is well structured.
·         Is not ambiguous in any way.
·         Can be linked-back to a specific requirement in the requirement document.
The following types are not considered to be the good candidates for automation:
§  Test Cases that will only be executed once.
§  Test Cases used for Ad-hoc/random Testing.
§  Test Cases that are infrequently selected for execution.

§  Test Cases that will require manual intervention i.e. a task not possible to automate.

Different Methods to close all browser in QTP

There are many methods available to close all browser in QTP. Few of them are given below.
Method 1: Using ChildObjects     
Dim oDesc, x

'Create a description object
Set oDesc = Description.Create
oDesc( "micclass" ).Value = "Browser"

'Loop through the collection and close each browser
If Desktop.ChildObjects(oDesc).Count > 0 Then
    For x = Desktop.ChildObjects(oDesc).Count - 1 To 0 Step -1
        Browser( "creationtime:=" & x ).Close
    Next
End If

Method 2: Closing all browser except Quality Control
Dim oDesc, x
 
'Create a description object
Set oDesc = Description.Create
oDesc( "micclass" ).Value = "Browser"
 
'Close all browsers except Quality Center
If Desktop.ChildObjects(oDesc).Count > 0 Then
    For x = Desktop.ChildObjects(oDesc).Count - 1 To 0 Step -1
       If InStr(1, Browser("creationtime:="&x).GetROProperty("name"), "Quality Center") = 0 Then  
          Browser( "creationtime:=" & x ).Close
       End If
    Next
End If

SystemUtil has the following methods that can be used to close processes, including browsers:
§  CloseProcessByName
  SystemUtil.CloseProcessByName "iexplore.exe"
§  CloseProcessByHWND: Uses windows handle to close a window.
  Dim HWND: HWND = Browser( "title:=Google" ).GetROProperty( "HWND" )
  SystemUtil.CloseProcessByHWND HWND
§  CloseProcessByWndTitle: Uses window title to close it.
  SystemUtil.CloseProcessByWndTitle "Google", True
§  TSKill with SystemUtil
  SystemUtil.Run "tskill", "iexplore"
§  Process ID with SystemUtil
PID = Browser("title:=Google").GetROProperty("process id")
SystemUtil.CloseProcessByID PID

HP Quick Test Pro 11.5 New Fetures

HP QTP, the best functional testing tool, is recently comes with a new version release. This HP QTP new version is hit the market with the name “HP Unified Functional Testing (UFT) 11.5”.

HP QTP 11.5 is a combination of QuickTestPro (QTP), Service Test (ST) and Mobile Testing as well. This is the major change in QTP since it is available in the market. HP QTP 11.5 creates this major change because of the end to end testing needs in the current market. So based on the requirement HP QTP 11.5 provides the testing ability as a GUI testing tool i.e. QTP, API testing tool i.e. Service Test and Mobile Testing from a single interface and that’s why now there is a no need for download separate tools.

HP UFT 11.5 Features:

QTP IDE Update:
  • HP UFT IDE (Integrated Development Environment) supports to work on multiple tests at the same time.
  • HP Unified Functional Testing IDE supports for editing more than one action at the same time.
  • HP QTP 11.5 IDE has improved statement completion, improved dynamic lists of values, code folding and code snippets.
  • Image based objects / controls identification (Insight Recording for GUI test).
  • QTP Recording identifies the object based on images.
  • Image-based testing feature can allow us to test applications on non-windows operating system as well.
  • Enhanced support for GUI Testing Environment.
Browsers:
  • HP UFT 11.5 Recording feature supports for
    • Internet Explorer 9
    • Mozilla Firefox Versions 4 to Versions 10
  • HP UFT 11.5 Play back supports for
    • Internet Explorer 9
    • Mozilla Firefox Versions 4 to Versions 10
    • Google Chrome

GUI Test support Add-ins:
  • Standard
  • Java
  • .NET
  • WPF
New and Improve Support:
  • Delphi
  • Oracle 11g, PeopleSoft 8.5 and Siebel 
  • SAP CRM 7.0 and SAP GUI 7.2
  • Office (MSAA)
Improved Check points:
  • Checks the text in dynamically or accessed PDF file content.
  • Supports for including or excluding multiple areas within a bitmap.
  • Supports for locate a bitmap area anywhere within the run time bitmap image.
  • Select External bitmap file as the bitmap source.
Supports for Mobile applications testing:
  • Install Perfecto Mobile QTP Add-in (UFT Mobile) and automate Mobile applications.