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.