<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cloud Testing Blog &#187; AWT</title>
	<atom:link href="http://www.cloudtesting.com/blog/tag/awt/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cloudtesting.com/blog</link>
	<description>Automated Functional, Cross Browser and Load Testing for Websites</description>
	<lastBuildDate>Tue, 23 Aug 2011 18:41:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Capturing screen shots of browsers with Selenium and Cloud Testing – Part 2</title>
		<link>http://www.cloudtesting.com/blog/2009/06/26/capturing-screen-shots-of-browsers-with-selenium-and-cloud-testing-part-2/</link>
		<comments>http://www.cloudtesting.com/blog/2009/06/26/capturing-screen-shots-of-browsers-with-selenium-and-cloud-testing-part-2/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 10:39:27 +0000</pubDate>
		<dc:creator>Phil Smith - Cloud Testing</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[AWT]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[Screen]]></category>

		<guid isPermaLink="false">http://blog.cloudtesting.com/?p=332</guid>
		<description><![CDATA[In Part 1 of this article, we covered the basics of capturing screenshots with Selenium using the captureScreenshot() and captureEntirePageScreenshot() methods. In this part, we cover the use of the Java Robot. Java Robot The Java Robot, part of the AWT (Abstract Windowing Toolkit) allows developers to interact with the GUI in an automated manner, [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://blog.cloudtesting.com/2009/06/24/capturing-screen-shots-of-browsers-with-selenium-and-cloud-testing-part-1/">Part 1 of this article</a>, we covered the basics of capturing screenshots with Selenium using the <span style="color:#000000;">captureScreenshot() and captureEntirePageScreenshot() methods. In this part, we cover the use of the Java Robot.</span></p>
<h2><span style="color:#000000;">Java Robot</span></h2>
<p><span style="color:#000000;">The Java Robot, part of the AWT (Abstract Windowing Toolkit) allows developers to interact with the GUI in an automated manner, sending keyboard comands, moving the mouse, clicking buttons, and most importantly for us, taking a screenshot.</span></p>
<h3><span style="color:#000000;">Taking a screenshot with the Robot<br />
</span></h3>
<p><span style="color:#000000;">In the example below, we create a bufferedImage object which contains a full screenshot, and then write it out as a PNG.</span></p>
<p><span style="color:#000000;"><br />
</span></p>
<pre style="padding-left:30px;">import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.event.KeyEvent;
import java.io.File;</pre>
<pre style="padding-left:30px;"><span style="color:#000000;">...
</span></pre>
<pre style="padding-left:30px;">BufferedImage bufferedImage;
final Rectangle captureSize;
final Robot robot = new Robot();

// calculate what we want to capture
captureSize =
    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());</pre>
<pre style="padding-left:30px;">//capture image
 bufferedImage = robot.createScreenCapture(captureSize);</pre>
<pre style="padding-left:30px;">// write the image out to a file
ImageIO.write(bufferedImage, "png", new File("screenshot.png"));</pre>
<p>This is very similar to the <span style="color:#000000;">captureScreenshot() command in Selenium, in that it is a direct screenshot of the OS window, taskbar and all:</span></p>
<p><span style="color:#000000;"><img class="aligncenter size-medium wp-image-335" title="java_robot_screenshot" src="http://cloudtesting.files.wordpress.com/2009/06/java_robot_screenshot.png?w=300" alt="java_robot_screenshot" width="300" height="224" /></span></p>
<h3><span style="color:#000000;">Scrolling the window with the Robot<br />
</span></h3>
<p>If we want to see what is further down the page, we can ask the Robot to press the <em>PAGE DOWN</em> key for us.</p>
<pre style="padding-left:30px;">robot.keyPress(KeyEvent.VK_PAGE_DOWN);</pre>
<p>Once we have pressed the PAGE DOWN key, we can take another screenshot using the Robot, as we did in first part. We then end up with the following:</p>
<p><img class="aligncenter size-medium wp-image-336" title="java_robot_screenshot2" src="http://cloudtesting.files.wordpress.com/2009/06/java_robot_screenshot2.png?w=300" alt="java_robot_screenshot2" width="300" height="224" /></p>
<p>If you want to move up or down using the <em>UP</em> and <em>DOWN</em> keys, rather than a page at a time, you can use the following commands.</p>
<pre style="padding-left:30px;">robot.keyPress(KeyEvent.VK_DOWN);</pre>
<p>or</p>
<pre style="padding-left:30px;">robot.keyPress(KeyEvent.VK_UP);</pre>
<h3>Image manipulation</h3>
<p>If you want to snip off the taskbar, title bars, scroll bars this can easily be done using methods of the bufferedImage class before writing out the image.</p>
<p>Multiple screenshot images can also be stitched together to create a larger image &#8211; this is performed in the <a href="http://www.cloudtesting.com">Cloud Testing service</a>, and will be covered in future articles.</p>
<p>See also</p>
<ul>
<li><a href="http://blog.cloudtesting.com/2009/06/24/capturing-screen-shots-of-browsers-with-selenium-and-cloud-testing-part-1/">Part 1 &#8211; Selenium screenshot basics</a></li>
<li><a href="http://blog.cloudtesting.com/2009/06/26/capturing-screen-shots-of-browsers-with-selenium-and-cloud-testing-part-2">Part 2 &#8211; Advanced screenshots with the Java Robot</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudtesting.com/blog/2009/06/26/capturing-screen-shots-of-browsers-with-selenium-and-cloud-testing-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

