use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testMultipleWindowsCaptureWithError.
/**
* Check that when an error occurs when communicating with driver, a desktop capture is taken
*/
@Test(groups = { "it" })
public void testMultipleWindowsCaptureWithError() {
DriverTestPage.link.click();
WebDriver mockedDriver = spy(driver);
ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
when(mockedDriver.getWindowHandles()).thenThrow(WebDriverException.class);
List<ScreenShot> screenshots = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class, true, false);
Assert.assertEquals(screenshots.size(), 1);
verify(screenshotUtil).captureDesktop();
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testRemoveHeaderAndFooter.
/**
* Test if we succeed in cropping picture according to requested parameters
* @throws IOException
*/
@Test(groups = { "it" })
public void testRemoveHeaderAndFooter() 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, 5);
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], 0);
Assert.assertEquals(headerFooter[2], 2);
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testRemoveScrollbarCapture.
/**
* Test if we succeed in removing scrollbars from capture (horizontal and vertical)
* @throws IOException
*/
@Test(groups = { "it" })
public void testRemoveScrollbarCapture() throws IOException {
driver.manage().window().setSize(new Dimension(400, 300));
WaitHelper.waitForSeconds(1);
// get real capture
String origFilePath = generateCaptureFilePath();
captureSnapshot(origFilePath);
Dimension screenshotDim = getViewPortDimension(new File(origFilePath));
// get cropped picture
BufferedImage image = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, BufferedImage.class);
// check all scrollbars were already removed from screenshot
Assert.assertEquals(image.getWidth(), screenshotDim.width);
Assert.assertEquals(image.getHeight(), screenshotDim.height);
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil 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.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testDesktopSnapshot.
/**
* Check we can capture desktop snapshots
*/
@Test(groups = { "it" })
public void testDesktopSnapshot() {
File output = new ScreenshotUtil(driver).capture(SnapshotTarget.SCREEN, File.class);
Assert.assertTrue(FileUtils.sizeOf(output) > 0);
}
Aggregations