Flickering issue of IE browser while taking screenshot in Selenium WebDriver Handled Using java.awt.Robot Class

9:53 PM 0 Comments


import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/*
 * 
 * Taking a screenshot using Robot class in java rather than 
 * TakesScreenshot Interface in Selenium Webdriver.
 *
 */

public class CaptureFullScreen {

public static void main(String[] args) throws AWTException {
try 
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");

//Implementing the Robot Class
Robot robot = new Robot();
String format = "jpg";  
String imgFileName= new SimpleDateFormat("mm-dd-yyyy_HH-ss").
format( new GregorianCalendar().getTime());
System.out.println(new GregorianCalendar().getTime());

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, format, new File("d:\\"+imgFileName+".jpg"));

System.out.println("Screenshot Saved in today's date format in d:\\");
catch (  IOException ex)
{
System.err.println(ex);
}
}
}

Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

0 comments: