use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestScreenshotUtil method testScreenshotIsNotNullWhenForced.
@Test(groups = { "it" })
public void testScreenshotIsNotNullWhenForced(ITestContext testContext) throws Exception {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
SeleniumTestsContextManager.getThreadContext().setCaptureSnapshot(false);
SeleniumTestsContextManager.getThreadContext().setBrowser("chrome");
WebDriver localDriver = null;
try {
localDriver = WebUIDriver.getWebDriver(true);
ScreenShot screenshot = new ScreenshotUtil(localDriver).capture(SnapshotTarget.PAGE, ScreenShot.class, true);
Assert.assertNotNull(screenshot);
Assert.assertTrue(new File(screenshot.getFullImagePath()).exists());
} finally {
if (localDriver != null) {
localDriver.close();
WebUIDriver.cleanUp();
}
}
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testRemoveFooter.
/**
* Test if we succeed in cropping picture according to requested parameters
* @throws IOException
*/
@Test(groups = { "it" })
public void testRemoveFooter() 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(0, 5);
FileUtility.writeImage(filePath, image);
int[] headerFooter = getHeaderAndFooterPixels(new File(filePath));
// header should have been removed, not footer
Assert.assertEquals(headerFooter[0], 6);
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 testCaptureViewport.
/**
* Capture viewport
* @throws IOException
*/
@Test(groups = { "it" })
public void testCaptureViewport() throws IOException {
driver.manage().window().maximize();
WaitHelper.waitForSeconds(1);
// get viewport picture and compare it to full page capture
String filePath = generateCaptureFilePath();
BufferedImage imageVp = new ScreenshotUtil(driver).capture(SnapshotTarget.VIEWPORT, BufferedImage.class, false, false).get(0);
FileUtility.writeImage(filePath, imageVp);
BufferedImage imageP = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, BufferedImage.class, false, false).get(0);
// check no vertical scrolling has been performed
Assert.assertTrue(imageVp.getHeight() < imageP.getHeight());
Assert.assertTrue(imageVp.getWidth() <= imageP.getWidth());
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testNoScrollbarCapture.
/**
* Test when no scrollbar is present in capture
* @throws Exception
*/
@Test(groups = { "it" })
public void testNoScrollbarCapture() throws Exception {
new DriverSubTestPage(true);
// 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 where 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 testMultipleWindowsCapture.
/**
* Check we get capture for each window
* Check also we remain on the same window handle after the capture
* Check that first captured image (popup) is smaller than the second one (main page)
*/
@Test(groups = { "it" })
public void testMultipleWindowsCapture() {
String currentWindowHandle = driver.getWindowHandle();
DriverTestPage.link.click();
List<ScreenShot> screenshots = new ScreenshotUtil().capture(SnapshotTarget.PAGE, ScreenShot.class, true, false);
Assert.assertEquals(screenshots.size(), 2);
Assert.assertEquals(currentWindowHandle, driver.getWindowHandle());
Assert.assertTrue(FileUtils.sizeOf(new File(((ScreenShot) screenshots.get(0)).getFullImagePath())) < FileUtils.sizeOf(new File(((ScreenShot) screenshots.get(1)).getFullImagePath())));
}
Aggregations