Thursday, January 21, 2010

Screen Capture Of Lengthy Web page using Snag IT Scroll Method and QTP

If you have SnagIT and QTP together in your machine, then you will be able to take screen capture of a lengthy web page.

Try the below code and you should have both QTP and SnagIT in your machine. If you don't have SnagIT, please download the trial version of SnagIT and try the code.

Function Capture_Scroll_Image
Set objShell = CreateObject("WScript.Shell")
Set oSnag = CreateObject("SNAGIT.ImageCapture")


oSnag.Input = 1
oSnag.Output = 2
oSnag.OutputImageFile.FileNamingMethod = 2
oSnag.OutputImageFile.Directory = "C:\Documents and Settings\Desktop"'Make sure to specify your file path where you need to save your screen capture file.


oSnag.EnablePreviewWindow = False
oSnag.AutoScrollOptions.AutoScrollMethod=3
oSnag.OutputImageFile.LoadImageDefaults 5
oSnag.Capture()


wait(2)


objShell.SendKeys "{ENTER}"


Do Until oSnag.IsCaptureDone
Loop


Set
oSnag=Nothing

Set objShell=Nothing
End Function

SystemUtil.Run "Iexplore.exe","http://www.google.co.in"

Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"
Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click
Browser("name:=QTP - Google Search").Sync


Call Capture_Scroll_Image'Calling the function to capture lengthy web page

Browser("name:=QTP - Google Search").Close


After running the script you will get the lengthy screen capture of the web page as same as below.


4 comments:

  1. This code doesn't capture the scrolling window.

    ReplyDelete
  2. Hi
    Is there a way to export this image to qtp results and not saved in folder. Our results will be saved in QC, I need to implement this with the QTP screenshots

    ReplyDelete
  3. Great job! One more question, the output file name is SNAG-0000.png. Can I give a specific name other than auto-assigned name?

    ReplyDelete
  4. I tried using the same code but after executing capture Snagit is taking focus over all other applications so QTP does not run. Can you please let me know how to fix this? Did you have any settings for Snag it to handle this?

    Thanks

    ReplyDelete