Tuesday, September 4, 2012

To capture application screenshot and display it in test results

Hey folks,

A common feature that QTP testers are often asked to implement is to capture the application screenshot every time an error occurs during test run. This is definitely a good to have feature in your automation framework because -
a) When a script fails, you would have a proof that it failed due to an application issue and not due to your script, and
b) with the error screenshot, the developers usually find it easier to identify/fix the issue.

QTP provides a method called CaptureBitmap that can capture the image of either an object within the application or the entire screen/desktop and save it in any desired location. The image is saved as .png or .bmp file depending upon the file extension provided during the function call. The object is captured as it appears in the application when the method is performed. If only a part of the object is visible, then only the visible part is captured

Function fnDisplayBitmapInTestResults
URL="www.gmail.com"

 SystemUtil.Run "iexplore.exe", URL
browsernm=".*gmail.*"
Pagenm=".*gmail.*"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)
wait(5)
currobj.CaptureBitmap "d:\Test.bmp"
Reporter.ReportEvent micDone ,"Image", "Image", "D:\Test.bmp"
End Function

call  fnDisplayBitmapInTestResults

Notes:
1. You cannot load images from Quality Center.
2. If you include large images in the run results, it may impact performance.
3. If you specify an image as a relative path, QTP will first search the Results folder for the image and then the search paths specified in the Folders pane of the Options dialog box

4 Different Ways to Associate Function Libraries to your QTP Scripts

4 Different Ways to Associate Function Libraries to your QTP Scripts
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 scripts. This article explains the 4 methods that will help you in associating the function libraries in QTP Test Cases.

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 -

  • By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
  • By using Automation Object Model (AOM).
  • By using ExecuteFile method.
  • using LoadFunctionLibrary method.

Friday, August 31, 2012

Advantages and Disadvantages of using DataTable as a Data Source

Advantages and Disadvantages of using DataTable as a Data Source

Advantages
  • a) The main advantage of this method is that it is very each to script for taking data from the datatable.
  • b) Another advantage is that you can use the ‘Run on all rows’ setting to run the same script for multiple data without making any changes in the script.
Disadvantages
  • a) This concept can’t be used for complex frameworks where you need to reuse the same set of data for different test cases.
  • b) This method also doesn’t work with modular framework where the test data needs to be grouped based on the functions rather than test cases.

Tuesday, August 14, 2012

Excel Formatting using QTP

Hey folks,

Here, I try to write code for excel formatting. Code is fetching excel files from the folder and do formatting of Font, Size etc. It count the number of excel files from the folder and do formatting on each file and save it. This type of example helps when user wants to do same kind of formatting on each file in folder.

Set xlApp = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
 PathofFolder="D:\Trupti\Copy of Testcases"
 Set oFolder = fso.GetFolder(PathofFolder) ' to get the folder
 Set oFiles = oFolder.Files
 NumberOfFiles = oFiles.Count ' to get the count of files
 msgbox "no of files" &NumberOfFiles
 For Each oFile In oFiles
 On Error Resume Next
 If InStr(1, lcase(oFile.path),".xls") > 0 then ' to check the type of file
            Set xlbook = xlApp.Workbooks.Open(oFile.path)
            set xlSheet=xlbook.WorkSheets.item(1)
            xlSheet.Activate
            xlApp.Visible=True
            xlSheet.Cells.Select ' to select all the active cells
            'xlApp.Selection.ClearFormats
            With xlApp.Selection
                    .Font.Name="Calibri"
                    .Font.Size=11
                    .HorizontalAlignment = -4131 '-4131 letf align, -4152 right align, -4130 justify, -4108 center
                     .VerticalAlignment = -4160 ' -4160 top align, -4107 bottom align, -4108  center, -4130 justify
                     .WrapText = True
                    ' .Borders(1).linestyle=1
            End With
            xlSheet.Rows("1:1").Font.Size=14            'select the first row and change the font size of it
            xlbook.SaveAs oFile.path, 51
 end If
 Err.clear
 Next
xlApp.Quit
Set xlApp = Nothing
Set xlbook = Nothing
set xlSheet = Nothing    

Thanks,
Trupti