Take screenshots
Screenshot of browser
getScreenshotAs()
See JavaDoc here, the following screenshot types are supported: BYTES, BASE64, FILE.
Alternatively, you can use the screenshotAsImage() method.
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<robotics-flow>
<robot driver="internet explorer" close-on-completion="true" name="webDriver">
<script></script>
</robot>
</robotics-flow>
<var-def name="link_url">
<s3 bucket='temp.bucket'>
<s3-put path="_r2d2/${'screenshot' + UUID.randomUUID() + '.png'}" acl="PublicRead">
<script return="screen"/>
Web-Harvest function
That is a generic function which takes browser screen capture and saves it to S3.
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config">
<function name="takeAndStoreScreenshot">
<script><![CDATA[
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import java.io.File;
String hitId = item.get(0).getWrappedObject().getSubmission().getAwsHitId().toString();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm'Z'");
String date = simpleDateFormat.format(new Date());
File screenshotFile = File.createTempFile("rpa-" + date, ".png");
]]></script>
<try>
<body>
<script></script>
<var-def name="screenShotPath">
<s3 bucket="${bucket_name}">
<s3-put path="rpa-screenshots/${bp_name}/${hitId}/rpa-${date}.png" acl="PublicRead"
content-type="image/png" content-disposition="inline">
<file action="read" path='${screenshotFile.getAbsolutePath()}' type="binary"/>
</s3-put>
</s3>
</var-def>
<log level="warn" message="Screenshot generated ${screenShotPath}."/>
</body>
<catch>
<script></script>
</catch>
</try>
<script></script>
<return>
<var name="screenShotPath"/>
</return>
</function>
</config>
Screenshot of Java applet
Full Screen - Sikuli Library
Taking Screenshot using Sikuli:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<var-def name="sikuliScreenshotAllScreen"><![CDATA[
import org.sikuli.script.*;
Screen screen = new Screen();
return screen.capture(screen.getBounds()).getFile();
]]></var-def>
<robotics-flow>
<robot driver="desktop">
<script></script>
</robot>
</robotics-flow>
<export include-original-data="true"></export>
</config>
Full Screen - AutoIt Script
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<robotics-flow>
<robot driver="desktop" close-on-completion="true" name="desktopDriver">
<script><![CDATA[
def filename = 'd:/_temp/screenshot___' + UUID.randomUUID() + '.png'
def script = "#include <ScreenCapture.au3>\n" +
"_ScreenCapture_Capture(\"${filename}\")\n"
executeScript(script, new String[0])
def res = executeGroovyScript(
"def bytes = new File('" + filename.replace('\\', '/') + "').bytes; \n" +
"return Base64.getEncoder().encodeToString(bytes);"
)
result = Base64.getDecoder().decode(res.toString())
executeGroovyScript("new File('" + filename.replace('\\', '/') + "').delete(); \n")
]]></script>
</robot>
</robotics-flow>
<var-def name="link_url">
<s3 bucket='temp.bucket'>
<s3-put path="_r2d2/${'screenshot-desktop' + UUID.randomUUID() + '.png'}" acl="PublicRead">
<script return="result"/>
Active window - standard Java library
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<var-def name="javaScreenshot"><![CDATA[
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import org.openqa.selenium.Point;
import org.openqa.selenium.Dimension;
Point pos = driver.manage().window().getPosition();
Dimension dim = driver.manage().window().getSize();
BufferedImage screenFullImage = new Robot().createScreenCapture(new Rectangle(pos.x, pos.x, dim.width, dim.height));
File file = new File("screenshot_${System.currentTimeMillis()}.png");
ImageIO.write(screenFullImage, "png", file);
return file.getAbsolutePath();
]]></var-def>
<robotics-flow>
<robot driver="desktop">
<script></script>
</robot>
</robotics-flow>
<export include-original-data="true"></export>
</config>