Entire scrollable web page image capture during runtime using SnagIt

181 views
Skip to first unread message

Walt

unread,
Apr 2, 2008, 10:13:04 AM4/2/08
to Watir General
In the past I have used the screen capture module which uses Paint and
found it very effective for scanning hundreds of web pages for
cosmetic defects, with the downside that it didn't capture the whole
page. My workaround was to capture the bottom of the page too, which
resulted in overlaps for short pages, and gaps for very long pages.
Although not perfect, this was still a major time saver after a major
CSS change.

A colleague recently forwarded an old post that included a code
snippet (from david goodine) and unanswered questions about the SnagIt
COM interface.

Reading the COM documentation (see link below) I modified the code and
got it to capture a complete image of a scrollable webpage. I rolled
this into our smoke test script which runs after every build and
capture each and every page to the network drive. Post execution,
anyone on the QA or UA team can review the screen shots for fixes,
enhancements or scan for cosmetic issues.

Within the main script:

$screenCaptureFolder = 'C:\temp'

# This only has to be done once.
$ie.bring_to_front
$ie.maximize
screenCapture(yourdesiredfilename)

In your method library:

def screenCapture(filename)
# this method will use SnagIt to capture and save a screenshot to
a directory
require 'win32ole'
# create snagit ole object:
snagit = WIN32OLE.new('Snagit.ImageCapture')
# set properties for the capture
snagit.Input = 1 #capture a window
# arbitrary X & Y locations within the scrollable portion of the
browser.
snagit.InputWindowOptions.XPos = 350 # select XPosition for
window ID
snagit.InputWindowOptions.YPos = 350 # select YPosition for
window ID
snagit.InputWindowOptions.SelectionMethod = 3 # Capture window
under the X, Y point specified above.
snagit.AutoScrollOptions.StartingPosition = 3 # set scroll to top
and left
snagit.AutoScrollOptions.AutoScrollMethod = 3 # set autoscroll to
vertical and horizontal
snagit.Output = 2 #output to a file
snagit.OutputImageFile.Filename = filename
snagit.OutputImageFile.Directory = $screenCaptureFolder #
set directy where filename will be saved
snagit.OutputImageFile.FileNamingMethod= 1 # set naming method
to fixed
snagit.OutputImageFile.ColorDepth = 16 # set color depth
snagit.OutputImageFile.FileType = 3 # set file type to
jpeg
# do the capture
snagit.Capture
# verify that capture is done, then return
while !snagit.IsCaptureDone
if snagit.IsCaptureDone then
return
end
end
return
end # screenCapture

Download the SnagIt COM Server User's Guide from
http://www.techsmith.com/snagit/accessories/comserver.asp

To change the properties above for your needs, refer to the User Guide
which maps the options to the corresponding integers.
Confirmed on SnagIt Ver 8.2.3 (Com Server available after Ver 6.2 -
from TechSmith website)

I'm considering adding this to my over night regression scripts to
capture pages where an error has occurred so I can get a visual of
what happened the next morning.

Walt Mamed

marekj

unread,
Apr 28, 2008, 11:32:56 AM4/28/08
to watir-...@googlegroups.com
Hi Walt,
I looked at your code and wondered why you chose the SelectionMethod = 3 for point and XPos and YPos..

I tried to implement Snagit for my Watir tests by using the Input = 1 for active window to capture the IE browser.
I expected the following code to capture the browser document window and scoll it to the bottom but instead it captures just the visible portion of the windws - The Window Frame, menu, toolbars and only visible portion of the document area.

snagit.Input = 1
snagit.InputWindowOptions.SelectionMethod = 1
snagit.InputWindowOptions.Handle = $ie.hwnd
snagit.AutoScrollOptions.AutoScrollMethod = 3
snagit.AutoScrollOptions.StartingPosition = 3


so I wonder if you have ran across this problem and just decided to use the point reference
I noticed that if I change my options to a point like your code it indeed captures the IE document and scrolls it to the bottom but discards the toolbar, address bar and all other parentWindow images, it caputres just the scrollable DOM display.
I would appreciate your thoughts on that.
Thanks

marekj

www.testr.us | semantic test objects modeling in watir

Walt

unread,
Apr 28, 2008, 4:42:53 PM4/28/08
to Watir General
Hi marekj,

I too started with the active window and discovered that you need to
supply the proper HWND (handle) of the client area. On the SnagIT
site there was a reference to this being the challenge and Microsoft
has not provided any easy ways to get this. Their suggestion was to
do your own newsgroup search and find a solution that met your needs.
I did some research, used AutoIT Window Info, etc and did not find a
solution.

The alternative was to use the point method and specify X & Y coords,
which is what I resorted to. Since I was only interested in the
scrollable page content, this method has met my needs perfectly and
reliably.

Thanks for asking!

Walt
Reply all
Reply to author
Forward
0 new messages