The capture image method

Occasionally, users might want to capture just the WebElement or MobileElement on the screen under test for later comparison. The following methods will capture just the specific image of the web, or MobileElement:

/**
* imageSnapshot - method to take snapshot of WebElement
*
* @param element - The Web or Mobile Element to capture
* @return File
* @throws Exception
*/
public static File imageSnapshot(WebElement element) throws Exception {
WrapsDriver wrapsDriver = (WrapsDriver) element;
File screen = null;

// capture the WebElement snapshot
screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver())
.getScreenshotAs(OutputType.FILE);

// create Buffered Image instance from captured screenshot
BufferedImage img = ImageIO.read(screen);

// get the width/height of the WebElement for the rectangle
int width = element.getSize().getWidth();
int height = element.getSize().getHeight();
Rectangle rect = new Rectangle(width,height);

// get the location of WebElement in a point (x,y)
Point p = element.getLocation();

// create image for element using location and size
BufferedImage dest =
img.getSubimage(p.getX(), p.getY(), rect.width, rect.height);

// BMP,bmp,jpg,JPG,jpeg,wbmp,png,PNG,JPEG,WBMP,GIF,gif

ImageIO.write(dest,"png",screen);

return screen;
}
/**
* captureImage - method to capture individual WebElement image
*
* @param image - the image to capture
* @throws Exception
*/
public static void captureImage(String image) throws Exception {
WebDriver driver = CreateDriver.getInstance().getCurrentDriver();

WebElement getImage = driver.findElement(
By.cssSelector("img[src*='" + image + "']"));

image = image.replace(".","_" + Global_VARS.DEF_BROWSER + ".");

FileUtils.copyFile(imageSnapshot(getImage),
new File(Global_VARS.BITMAP_PATH + image));
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.250.1