Saturday 16 August 2014

Test Result Presentation Using QTP


Introduction
In QTP we have record and playback option where we can automate most of the scripts, Normally in almost all the cases we have to create a test result ppt with the details about executed test to upload in Quality Centre.

Scenario: Creation of Test Result PPT to upload in Quality Centre along with the test case during execution.

Step 1:
Declare a global variable to track number of images in Functional Library with Name imageNubmer and initialize it with zero
DimimageNumber
imageNumber = 0                                        

Step 2:
Call Sub Procedure CompleteScreenshotfor each page you need to be put in the test result presentation.
CompleteScreenshotbrowserName, pageName, location
browserName     – Name of the browser given in the Object Repository
pageName           – Name of page given in the Object Repository
location                - Location in file system you need the screenshots to be stored.

above mentioned code will create a png image at the specified location with the current imageNumber.


Step 3:
Call Sub Procedure CreatePPT after the action finished the current iteration of execution.
CreatePPTimageCount, filePath, filename, accountNum, testCaseId, testCaseName

Sub procedures involved:

Sub CompleteScreenshot(browserName, pageName, location)
          'variable Declaration
DimscrollHeight, counter
          counter = 0  
          On error resume next
            'fetch the scroll height of the document window
          scrollHeight = Browser(browserName).Page(pageName).object.body.scrollHeight
            'Scroll page by 600 pixels and take screenshot using captureBitmap function
          While counter <scrollHeight          
                   Browser(browserName).Page(pageName).Object.parentWindow.scroll 0,counter
                   Browser(browserName).Page(pageName).CaptureBitmap location & "\" &imageNumber& ".png", True
                   imageNumber = imageNumber + 1
                   counter = counter + 600
          Wend
          IfErr.Number<> 0 Then
                   Err.clear
                   On error goto 0
                   Reporter.ReportEventmicFail, “Screenshot Capture failed”, “Unable to capture the screenshot
          End if
End Sub




SubCreatePPT (imgCount, filePath, fileName, accountNum, testCaseId, testCaseName)
          DimimgFile, objCustomLayout, objPPT, objPres, objSlide, objShape, pptSlide

          On error resume next
          SetobjPPT = CreateObject("PowerPoint.Application")
          objPPT.visible = 1
          SetobjPres = objPPT.presentations.Add
          SetobjCustomLayout = objPres.SlideMaster.CustomLayouts.Item(7)
          SetobjSlide = objPres.Slides.AddSlide(1, objCustomLayout)
          objPres.Slides(1).select
          'Prepare the first slide containing details of test case.
          SetobjShape = objPres.Slides(1).Shapes.AddTable(2, 3, 5, 5,     objPres.PageSetup.SlideWidth - 10, 200)            
          objShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Account Number"
          objShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Test Case Id"
          objShape.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Test Case"
          objShape.Table.Cell(2, 1).Shape.TextFrame.TextRange.Text = accountNum
          objShape.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = testCaseId
          objShape.Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = testCaseName

          SetobjSlide = objPres.Slides.AddSlide(objPres.Slides.Count + 1, objCustomLayout)
          objPres.Slides(2).select                                             
          imgFile =filePath& "\0.png"
          'Add image to the Slide
          objPres.Slides(2).Shapes.AddPictureimgFile, False, True, 10, 10,700,500
                  
          Fori=1 toimgCount - 1       
                   SetpptSlide = objPres.Slides.Add(objPres.Slides.Count + 1, 12 )                   
                   imgFile =filePath& "\" &i& ".png"                      
                   pptSlide.Shapes.AddPictureimgFile, False, True, 10, 10,700,500                   
          Next              
'UnComment the code if you need to add the failure reason in the ppt.
'This requires user to declare a global variable failureReason and update it accordingly

REM    IffailureReason<> "" Then
                   'Add a text box stating the error scenario
REM             SetpptSlide = objPres.Slides.Add(objPres.Slides.Count + 1, 12 )
REM             Dim textBox1
REM             Set textBox1 = pptSlide.Shapes.AddTextbox(1, 10, 10, 200, 100)
REM             textBox1.TextFrame2.TextRange.Text = failureReason
REM             failureReason = ""
REM    End If
          objPres.SaveAsfilePath& "\" &fileName
          objPPT.quit
          IfErr.Number<> 0 Then
                   Err.clear
                   On error goto 0
                   Reporter.ReportEventmicFail, “PPT Creation failed”, “Unable to create PPT
          End if
          imageNumber = 0                       
End Sub

Advantages:
  • This function can be reusable in all test cases where we need to prepare the test result ppt.
  • Easily modifiable code to include the failureReason Functionality, if programmer tracks the failureReason within the code
  • Novice user can use the functions.



0 comments :

Post a Comment