use of com.seleniumtests.driver.screenshots.SnapshotTarget in project seleniumRobot by bhecquet.
the class PageObject method captureElementSnapshot.
/**
* Capture a portion of the page by giving the element to capture
* @param snapshotName the snapshot name
* @param element the element to capture
* @param checkSnapshot if true, will send snapshot to server (when seleniumRobot is configured for this) for comparison
*/
public void captureElementSnapshot(String snapshotName, WebElement element, SnapshotCheckType checkSnapshot) {
SnapshotTarget snapshotTarget = new SnapshotTarget(element);
ScreenShot screenShot = screenshotUtil.capture(snapshotTarget, ScreenShot.class, computeScrollDelay(checkSnapshot));
// check SnapshotCheckType configuration is compatible with the snapshot
checkSnapshot.check(snapshotTarget);
storeSnapshot(snapshotName, screenShot, checkSnapshot);
}
use of com.seleniumtests.driver.screenshots.SnapshotTarget in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCaptureElement.
/**
* Test if we succeed in capturing a single element
* @throws IOException
*/
@Test(groups = { "it" })
public void testCaptureElement() throws IOException {
driver.manage().window().maximize();
WaitHelper.waitForSeconds(1);
// get cropped picture
String filePath = generateCaptureFilePath();
BufferedImage image = new ScreenshotUtil(driver).capture(new SnapshotTarget(DriverTestPage.table), BufferedImage.class, false, false).get(0);
FileUtility.writeImage(filePath, image);
// should be 100 be may depend on browser / version
Assert.assertTrue(image.getHeight() < 105 && image.getHeight() > 95);
// should be 72 be may depend on browser / version
Assert.assertTrue(image.getWidth() < 75 && image.getWidth() > 70);
}
use of com.seleniumtests.driver.screenshots.SnapshotTarget in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCaptureNonExistingElement.
/**
* Check that if element does not exist, a Scenario exception is raised
* @throws IOException
*/
@Test(groups = { "it" }, expectedExceptions = ScenarioException.class)
public void testCaptureNonExistingElement() throws IOException {
driver.manage().window().maximize();
WaitHelper.waitForSeconds(1);
// get cropped picture
String filePath = generateCaptureFilePath();
BufferedImage image = new ScreenshotUtil(driver).capture(new SnapshotTarget(DriverTestPage.textElementNotPresent), BufferedImage.class, false, false).get(0);
FileUtility.writeImage(filePath, image);
// should be 100 be may depend on browser / version
Assert.assertTrue(image.getHeight() < 105 && image.getHeight() > 95);
// should be 72 be may depend on browser / version
Assert.assertTrue(image.getWidth() < 75 && image.getWidth() > 70);
}
Aggregations