Skip to main content

Posts

Showing posts from 2012

PDF Automation in QTP

                                                                            The most challenging issue with PDFs is that it could be of any kind, not just a tabular data; it could have plain text, images or even forms to fill up. So this makes a tester’s life a bit difficult, never mind, we will definitely find an easy of do it… Although there are already some better approaches we have to deal with PDF documents but I found many of us are facing so many difficulties using this. There are lots of queries coming at QTP forums asking for an easy way of doing it with PDFs. keeping those in my mind I started creating this API mainly for comparing two PDF documents, and added few more features in it. We will see all of them later in this article. LearnQuickTestPDF API works with iTextSharp. Sometime back when I was involved in a PDF project I found this really useful library which does a great deal to ease the burden of manipulating PDF documents.It provides all of the

Keep your windows machine Unlock while QTP Running.

Below are the Few ways to  Keep your windows machine Unlock: Way 1: Install the Caffeine 1.4 software on machine where u run the scripts.  =========================================================================== Way 2: Create a .vbs file with the below code and run the script using task scheduler Const DELAY_MINUTES = 10 Wscript.Sleep DELAY_MINUTES * 60000 Do    CreateObject(“Wscript.Shell”).SendKeys “+”    Wscript.Sleep DELAY_MINUTES * 60000 Loop ===========================================================================  Way 3: Create a .vbs file with the below code and run the script Const micVoid = 0 Const micByte = 26 Const micLong = 3 Const KEYEVENTF_KEYUP = &H2 Set Extern = CreateObject("Mercury.ExternObj") extern.Declare micVoid, "keybd_event", "user32", "keybd_event", micByte, micbyte, miclong, micLong Extern.Declare micVoid, "Sleep", "kernel32", "Sleep", micLon

Read Outlook mail attachment and Body using Vb Script or QTP

Set olApp = CreateObject("Outlook.Application") Set olns = olApp.GetNameSpace("MAPI") Set ObjFolder = olns.GetDefaultFolder(6) j = 0 For each item1 in ObjFolder.Items        iattachCnt = item1.Attachments.Count     Print "Attachments Count: " & iattachCnt     For i = 1 to iattachCnt         Print "FileName :    " & item1.Attachments(i).FileName         Print "Display Name:   " & item1.Attachments(i).DisplayName         Print "Size: " & item1.Attachments(i).Size     Next     Print " Body : " & item1.body     Print "--------------------------------------Mail Num - " & j & " -----------------------------------------------"     j = j+1    Next

How to get installed programs from Registry

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE strComputer = "." strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" strEntry1a = "DisplayName" strEntry1b = "QuietDisplayName" strEntry2 = "InstallDate" strEntry3 = "VersionMajor" strEntry4 = "VersionMinor" strEntry5 = "EstimatedSize" Set objReg = GetObject("winmgmts//" & strComputer & "/root/defaultStdRegProv")                                        (oR )   Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _     & strComputer & "\root\default:StdRegProv") objReg.EnumKey HKLM, strKey, arrSubkeys Print  "Installed Applications" & VbCrLf For Each strSubkey In arrSubkeys   intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _    strEntry1a, strValue1)   If intRet1 <> 0 Then     objReg.GetStringValue HKLM, strKey & strSubkey, _      str

How to get installed programs in Control Panel

Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile("c:\software.txt", True) strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colSoftware = objWMIService.ExecQuery _     ("Select * from Win32_Product") objTextFile.WriteLine "Caption" & vbtab & _     "Description" & vbtab & "Identifying Number" & vbtab & _     "Install Date" & vbtab & "Install Location" & vbtab & _     "Install State" & vbtab & "Name" & vbtab & _     "Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _         & "Version" For Each objSoftware in colSoftware     objTextFile.WriteLine objSoftware.Caption &a

How to Read or Select Context Menu or Right Click Menu using QTP.

Select The Item in Right Click Menu or Context Menu: Window("sampleWindow").WinMenu("MenuObjType:=1).Select"File;New" Here MenuObjtype can be 1 r 2 r 3 .......n Check wether the Item is Exist or Not: If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("1","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If                                         Or If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("File","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If Get the Items in Context Menu: For i = 1 to 10 Print  Window("sampleWindow").WinMenu("MenuObjType:=" & i).GetItemProperty("1","Label") Then Next

Broad comparison among QTP and Selenum

# Selenium QTP 1 Open source Paid tool 2 Works on all OS Works on Windows 3 Tests only Web applications Tests web and desktop applications 4 Works on almost all browsers Works on IE ,Firefox and Chrome(Partially) 5 Code can be made in any one of languages such as Java, C#, Ruby, Python, pearl, php etc Uses Vb Script 6 No object repository Has got an object repository 7 IDE sometimes does not record some events Recording is a little reliable events 8 Core engine is java script and is very strong Core engine is not java script based

Broad comparison among QTP and Selenium

Sr. What HP QTP has What Selenium has 1 QTP is ideally suited for browser based testing Selenium too can very well do browser based testing 2 QTP is licensed software & requires license costs that are quite a bit. Selenium is an open source tool that doesn’t cost anything 3 QTP is quite easy to use. It is quite easy to edit the script, parameterize, navigate, playback & validate the results. For using Selenium one needs to have programming skills. 4 QTP is quite easy to learn in a short time. Selenium needs quite a bit of expertise compared to QTP. 5 QTP offers great benefit of the support for Business Process Testing. Selenium users don’t enjoy such benefits 6 QTP comes powered with several add-ins by which user can comfortably work with Web, Windows,

Selenium useful Links

For Documentation : http://seleniumhq.org/docs/01_introducing_selenium.html http://www.seleniumwiki.com/   Sample Script using Testng-eclipse: http://www.seleniumwiki.com/selenium-rc/sample-selenium-rc-script-using-testng-eclipse/

how to read CAPTCHA from QTP

Can we read Captcha images from QTP???  Yes!!!! Solution:   *** Need to Zoom the Application upto 400%(Worked for me) and try to execute the below code  *** Captcha image should be visible on your desktop shwnd = Browser("Browser Name").GetROProperty("hwnd") mtxt =  Window("hwnd:=" & shwnd,"index:=0").GetVisibleText Print mtx

Working on CAPTCHA Images in QTP

Note :            *** Need to Zoom the Application upto 400% and try to execute the below code           *** Captcha image should be visible on your desktop shwnd = Browser("Browser Name").GetROProperty("hwnd") mtxt =  Window("hwnd:=" & shwnd,"index:=0").GetVisibleText Print mtxt

Download Test Resource From QC Using QTP

'########################################################################### '* Function Name: QCGetResource '* Designer: Jay '* Date 09-May-2012 '* This script will Download QC Test Resource to a local dir '########################################################################### Function QCGetResource(resourceName,saveTo)     Set qcConn = QCUtil.QCConnection     Set oResource = qcConn.QCResourceFactory     Set oFilter = oResource.Filter     oFilter.Filter("RSC_FILE_NAME") = resourceName     Set oResourceList = oFilter.NewList     If oResourceList.Count = 1 Then         Set oFile = oResourceList.Item(1)         oFile.FileName = resourceName         oFile.DownloadResource saveTo, True     End If         Set qcConn = Nothing     Set oResource = Nothing     Set oFilter = Nothing     Set oFlieList = Nothing     Set oFile = Nothing End Function

How to run Excel Macro in QTP

Function RunMacro(sPath, sMacroName, sArg1, sArg2)    Set xlApp = CreateObject("Excel.Application")    Set xlWbk = xlApp.Workbooks.Open(sPath)    RunMacro = xlApp.Run(sMacroName, sArg1, sArg2)    xlApp.Quit End Function ***your macro in VBA should be public

Get QC Parameters from Test cases using QTP

'###################################################### '#  FunctionName : getQCParameters '# Purpose: To get  the QC Parameters from Test cases using QTP '# Created By :  Jay '###################################################### Function getQCParameters(strNodeByPath)     On Error Resume Next     'strNodeByPath =  "Subject\02 - System Test\TestCases\Reports\Client Reports"     Set TDC = QCUtil.QCConnection     set TSfact = TDC.TestSetFactory     Set TreeMgr = TDC.TreeManager     Set TestTree = TreeMgr.NodeByPath(strNodeByPath)     Set TestFactory = TestTree.TestFactory     Set TestList = TestFactory.NewList("")     Dim NodesList()     ReDim Preserve NodesList(0)     NodesList(0) = TestTree.Path                              Dim Row, Node, TestCase     irow = 1     For Each Node In NodesList            Set TestTree = TreeMgr.NodeByPath(Node)         Set TestFactory = TestTree.TestFactory         Set TestList = TestFactory.NewList(""

In QTP Excel ADODB Connection Tips

Column headings         By default, it is assumed that the first row of your Excel data source contains columns headings that can be used as field names. If this is not the case, you must turn this setting off, or your first row of data "disappears" to be used as field names. This is done by adding the optional HDR= setting to the Extended Properties of the connection string. The default, which does not need to be specified, is HDR=Yes . If you do not have column headings, you need to specify HDR=No ; the provider names your fields F1, F2, etc. Because the Extended Properties string now contains multiple values, it must be enclosed in double quotes itself, plus an additional pair of double quotes to tell Visual Basic to treat the first set of quotes as literal values NOTE : Special characteristics can’t be accessed using ADODB Connection with Excel. deleting Excel data       You are more restricted in deleting Excel data than data from a relational data

Select Excel Data with Code using ADO Object

Your Excel data may be contained in your workbook in one of the following: An entire worksheet. A named range of cells on a worksheet. An unnamed range of cells on a worksheet. Specify a Worksheet To specify a worksheet as your recordsource, use the worksheet name followed by a dollar sign and surrounded by square brackets. For example: strQuery = "SELECT * FROM [Sheet1$]" You can also delimit the worksheet name with the slanted single quote character (`) found on the keyboard under the tilde (~). For example: strQuery = "SELECT * FROM `Sheet1$`" Microsoft prefers the square brackets, which are the standing convention for problematic database object names. If you omit both the dollar sign and the brackets, or just the dollar sign, you receive the following error message: ... the Jet database engine could not find the specified object If you use the dollar sign but omit the brackets, you will see

How to convert Excel column numbers into alphabetical characters

 The ConvertToLetter function works by using the following algorithm: Divide the column number by 27, and then put the resulting integer in the variable "i". Subtract the column number from "i" multiplied by 26, and then put the result in the variable "j". Convert the integer values into their corresponding alphabetical characters, "i" and "j" will range from 0 to 26 respectively. For example: The column number is 30. The column number is divided by 27: 30 / 27 = 1.1111, rounded down by the Int function to "1". i = 1 Next Column number - (i * 26) = 30 -(1 * 26) = 30 - 26 = 4. j = 4 Convert the values to alphabetical characters separately, i = 1 = "A" j = 4 = "D" Combined together, they form the column designator "AD". The following VBA function is just one way to convert column number values into their equivalent alphabetical charac

Compare two Excel files Row wise with ADODB Connection in QTP.

Function Comparedata(strFileName1,strFileName2,ColumnName)       Dim iShtCnt1,iShtCnt2,strSheetName,strSQLStatement1,iCurRow,Query,iColCnt,iCol,curColName,curColValue,CurQuery    Dim bFound,j,strSQLStatement2,RecSet2,iRecordCnt     Set oBook1 = oExcel.Workbooks.Open(strFileName1)     Set oBook2 = oExcel.Workbooks.Open(strFileName2)     iShtCnt1 = oBook1.Sheets.Count     iShtCnt2 = oBook2.Sheets.Count     If iShtCnt1 <> iShtCnt2 Then Reporter.ReportEvent micFail,"Compare Report - Sheets Count Mismatch":Exit Function     oBook1.Close     oBook2.Close     oExcel.Quit     Set oExcel = Nothing     Set objCon2 = ConnectToExcel(strFileName2)     For i = 1 to iShtCnt1         strSheetName = allSheetNames(i-1)         strSQLStatement1 = "" & "SELECT * FROM [" & Left(strSheetName,31) & "$]  WHERE ["  & ColumnName & "] IS NOT NULL AND ["  & ColumnName & "] <> ' '"         Set RecSet1 = GetC

HP QTP 11 - New Enhancements

HP QTP 11 now offers the following enhancements in its existing features: New Object Spy Functionality Compare, Merge, and Export Object Repositories with Checkpoints and Output Values Add Images to Your Run Results New Dual Monitor Support New Web Test Object Operations New WpfTable Test Object Hide the Keyword View Enable Running QTP Tests on Minimized RDP Session Windows See Version Control Status of Tests, Components, and Function Libraries at a Glance Business Process Testing Enhancements Web Add-in Extensibility Enhancements Get Critical Updates Using the New HP Update Tool Extended Trial Period for QuickTest Seat License Updated QuickTest Asset Upgrade Tool for HP ALM and Quality Center Source: HP QuickTest Professional Help

QTP ALL Versions

QTP Versions: 11.0 - Released in 2010 10.0 - Released in 2009 9.5 - Released in 2008 9.2 - Released in 2007 9.1 - Released in 2007 9.0 - Released in 2006 8.2 - Released in 2005 8.0 - Released in 2004 7.0 - Never released. 6.5 - Released in 2003 6.0 - Released in 2002 5.5 - First release. Released in 2001

How to Get the Inner Html of a WebPage

'###################################################### '#  FunctionName : GetPageInnerHtml '# Purpose: To get  the innerhtml of a WebPage '# Created By :  Jay '######################################################     Sub GetPageInnerHtml()     On Error Resume Next     Set oPage = Browser("name:=XXXX").Page("title:=XXXX")        Print oPage.object.body.innerhtml        If Err.number <> 0 Then Reporter.ReportEvent micfail,methodname,Err.number & " - " & Err.description End Sub E.g: Call GetPageInnerHtml()

How to Get Properties for All Objects From WebPage using Tag Name

'###################################################### '#  FunctionName : GetAllitemsbyTageName '# Purpose: To get  all the objects by Tag Name '# Created By :  Jay '# Parameters : '# Notes: '# Last  Updated: '# Revision History: '######################################################      Function GetAllitemsbyTageName(sTagName)     On Error Resume Next     Set oPage = Browser("name:=XXXX").Page("title:=XXXX")     Set oAllChild=oPage.Object.getElementsByTagName(sTagName)     iChildCnt = oAllChild.length     Print "Count - > " & iChildCnt     If iChildCnt >=1 Then               For i = 0 to iChildCnt -1                            Print "================================ " & i & "     ======================================="                 Print "Outer Html - > " & oAllChild(i).outerhtml                 Print "innerhtml- > " & oAllChild(i).innerhtml 

How to Use Dll Files in QTP Scripts

How to Use Dll Files in Our QTP Scripts:   1.       Use the QuickTest Extern object to declare an external function.  The following example declares a call to a function called GetForegroundWindow , located in user32.dll :  extern.declare micHwnd, "GetForegroundWindow", "user32.dll", "GetForegroundWindow"  2.       Call the declared function, passing any required arguments, for example: hwnd = extern.GetForegroundWindow().  In this example, the foreground window's handle is retrieved. You can enhance your function library if the foreground window is not in the object repository or cannot be determined beforehand (for example, a window with a dynamic title). You may want to use this handle as part of a programmatic description of the window, for example: Window("HWND:="&hWnd).Close  Source: HP QTP help