Friday, May 27, 2011

How To Use Descriptive Programming In QTP Continued..


When And Where To Use Descriptive Programming:

In this article we will continue to learn "when and where to use Descriptive Programming in QTP?". What are the scenarios where one should use descriptive programming (Programmatic descriptions):
Just to list major scenarios below:


1. When object is not saved in Object Repository:

Descriptive Programming can be very useful if one want to perform an operation on an object that is not stored in the OR (Object Repository).

2. When many objects with same properties available in AUT (Application Under Test):

Descriptive Programming is also used in case where one has to perform the same operation on several objects with certain identical properties.

3. To handle dynamic objects:

It can also be used to perform an operation on an object whose properties match a description that one determines dynamically during the run session.
  
Here is an example to illustrate:
If there are multiple links in a particular section with different names, so it is not recommended to store all links in OR, better is to create properties collection and pass the name as parameter for “innertext”

 


Function clickLink(varLinkName)
 Set objDesc = description.Create()
 objDesc ("micclass").value = "Link"
 objDesc ("html tag").value="A"
 objDesc ("innertext").value = varLinkName
 Set objChild = Browser("Browser").Page("Page").ChildObjects(objDesc)
 objChild(0).Click
End Function

clickLink "Link1"
clickLink "Link2"


How To Use Descriptive Programming (Programmatic Description) In QTP Basics


Types Of Descriptive Programming:

Before starting to play with Descriptive Programming,one needs to understand the types of Descriptive Programming (programmatic descriptions).
Descriptive Programming can be of two types, Static and Dynamic:

1. Static Descriptive Programming:

    Example:
     
    
    
    Browser("Browser").Page("Page").WebEdit("Name:=Employee", "Index:=3").Set "John" 
    
    
    

    2. Dynamic Descriptive Programming: 

     One adds a collection of properties and values to a Description object, and then enters the Description object name in the statement.
    Example:
     
    
    
    Set objDesc = description.Create()
    objDesc ("micclass").value = "Link"
    objDesc ("html tag").value="A"
    objDesc ("innertext").value = "ClickHere"
    Set objChild =Browser("Browser").Page("Page").ChildObjects(objDesc) 
    
    
    

    Thursday, July 29, 2010

    How To Compare Two PDF Files

    Comparing two PDF files using Quick Test Professional is bit tricky. Lets do it. As we know to compare two files first thing one would require is to get the contents of file thus require file handling and then the logic to compare content. It can be done in two steps:

    (1) Opening the pdf files and getting their text content from clipboard

    (2) Comparing the two strings containing text contents.

    Here is an example:

     
    
    
    Dim varPath1, varPath2, str1, str2
    varPath1 = "C:\first.pdf"
    varPath2 = "C:\second.pdf"
    
    str1= getPDFText (varPath1)
    str2= getPDFText (varPath2)
    
    if StrComp(str1,str2,0) <> 0 Then
     msgbox "PDF files do not have same text content"
    else
     msgbox "PDF files have same text content"
    end If
    
    Public Function getPDFText (varPath)
    
     Dim MyClipboard
    
     SystemUtil.Run varPath
     
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micAltDwn + "t" + micAltUp
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type "s"
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micDwn
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type "Enter"
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micCtrlDwn + "a" + micCtrlUp
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Type micCtrlDwn + "c" + micCtrlUp
    
     Set MyClipboard = CreateObject("Mercury.Clipboard")
    
     getPDFText = MyClipboard.GetText
    
     MyClipboard.Clear
    
     Set MyClipboard=Nothing
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Activate
    
     Window("regexpwndtitle:=Adobe Reader","regexpwndclass:=AdobeAcrobat").Close
    
    End Function