Showing posts with label QTP Screen Capture. Show all posts
Showing posts with label QTP Screen Capture. Show all posts

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.


Saturday, January 9, 2010

Working With Screen Capture in QTP

Converting PNG to JPG format

I have seen one question in Advanced QTP forum, that is the user needed to capture screenshot in JPG format instead of PNG.
QTP cannot capture snapshot(s) as JPG format, but we have an option to convert it using DOT Net Factory. I hope this code will be useful for all QTP users. So I have posted this in my blog.

Here is the code to convert from PNG to JPG

sImagePath="C:\Documents and Settings\TEMP\Desktop\cap.png"'Make sure to mention your destination path for snapshot

Desktop.CaptureBitmap sImagePath'Capturing as PNG format

Call ConvertJPG(sImagePath)

Function ConvertJPG(sBmpPath)

Set oBmp=DotNetFactory.CreateInstance("System.Drawing.Bitmap","System.Drawing",sBmpPath)
Set oDir=DotNetFactory.CreateInstance("System.IO.Path","mscorlib")
Set oFile=DotNetFactory.CreateInstance("System.IO.File","mscorlib")

oBmp(sBmpPath)

sNewFile = oDir.GetDirectoryName(sBmpPath)
sNewFile = sNewFile&"\" & oDir.GetFileNameWithoutExtension(sBmpPath)
sNewFile = sNewFile&"." &"JPG"
oBmp.Save(sNewFile)'Saving as JPG format

oBmp.Dispose()
oFile.Delete(sBmpPath)'Deleting the previous PNG file.

Set oDir=Nothing
Set oFile=Nothing
Set oBmp=Nothing
End Function