use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testRemoveHeader.
/**
* Test if we succeed in cropping picture according to requested parameters
* @throws IOException
*/
@Test(groups = { "it" })
public void testRemoveHeader() throws IOException {
driver.manage().window().setSize(new Dimension(400, 300));
WaitHelper.waitForSeconds(1);
// get cropped picture
String filePath = generateCaptureFilePath();
BufferedImage image = new ScreenshotUtil(driver).capturePage(6, 0);
FileUtility.writeImage(filePath, image);
int[] headerFooter = getHeaderAndFooterPixels(new File(filePath));
// header should have been removed, not footer
Assert.assertEquals(headerFooter[0], 0);
Assert.assertEquals(headerFooter[1], 5);
Assert.assertEquals(headerFooter[2], 2);
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testFixedHeaderFooterManualCropping.
/**
* Check we are able to get all the content whereas we crop the header and footer manually (top and bottom pixels set automatically)
* @throws IOException
*/
@Test(groups = { "it" })
public void testFixedHeaderFooterManualCropping() throws IOException {
driver.manage().window().setSize(new Dimension(400, 300));
WaitHelper.waitForSeconds(1);
// get full picture without cropping
File imageFull = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
SeleniumTestsContextManager.getThreadContext().setSnapshotBottomCropping(5);
SeleniumTestsContextManager.getThreadContext().setSnapshotTopCropping(6);
// get picture with header and footer cropped
File image = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
int[] headerFooter = getHeaderAndFooterPixels(image);
int[] headerFooterFull = getHeaderAndFooterPixels(imageFull);
// header and footer should have been removed
Assert.assertEquals(headerFooter[0], 6);
Assert.assertEquals(headerFooter[1], 5);
// depending on browser window size (depends on OS) image is split in more or less sections
Assert.assertTrue(headerFooter[2] >= headerFooterFull[2]);
Assert.assertEquals(ImageIO.read(image).getHeight(), ImageIO.read(imageFull).getHeight());
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testFixedHeaderFooterAutomaticCropping.
/**
* Check we are able to get all the content whereas we crop the header and footer automatically
* @throws IOException
*/
@Test(groups = { "it" })
public void testFixedHeaderFooterAutomaticCropping() throws IOException {
driver.manage().window().setSize(new Dimension(400, 300));
WaitHelper.waitForSeconds(1);
// get full picture without cropping
File imageFull = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
SeleniumTestsContextManager.getThreadContext().setSnapshotBottomCropping(null);
SeleniumTestsContextManager.getThreadContext().setSnapshotTopCropping(null);
// get picture with header and footer cropped
File image = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
int[] headerFooter = getHeaderAndFooterPixels(image);
// header and footer should have been removed
Assert.assertEquals(headerFooter[0], 6);
Assert.assertEquals(headerFooter[1], 5);
// with automatic cropping, all fixed lines are removed, even green and red ones. Only remains the first top and last bottom one
Assert.assertEquals(headerFooter[2], 2);
Assert.assertEquals(ImageIO.read(image).getHeight(), ImageIO.read(imageFull).getHeight());
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method captureSnapshot.
private void captureSnapshot(String filePath) {
String b64Img = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, String.class);
byte[] byteArray = b64Img.getBytes();
FileUtility.writeImage(filePath, byteArray);
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCurrentWindowsCapture2.
/**
* Check that only main window is captured when no argument is given
*/
@Test(groups = { "it" })
public void testCurrentWindowsCapture2() {
DriverTestPage.link.click();
ScreenShot screenshot = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class);
Assert.assertNotNull(screenshot.getImagePath());
}
Aggregations