use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testSnapshotWithErrors.
/**
* Test that if an unexpected error occurs when snapshot is taken, take desktop
* @throws Exception
*/
@Test(groups = { "it" })
public void testSnapshotWithErrors() throws Exception {
driver.switchTo().frame(DriverTestPage.iframe.getElement());
// get real capture
generateCaptureFilePath();
CustomEventFiringWebDriver mockedDriver = (CustomEventFiringWebDriver) spy(driver);
ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
doThrow(WebDriverException.class).when(mockedDriver).scrollTop();
doThrow(JavascriptException.class).when(mockedDriver).scrollTo(anyInt(), anyInt());
ScreenShot screenshot = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class);
Assert.assertNotNull(screenshot.getHtmlSourcePath());
Assert.assertNotNull(screenshot.getFullImagePath());
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCurrentWindowsCapture.
/**
* Check that only main window is captured
*/
@Test(groups = { "it" })
public void testCurrentWindowsCapture() {
String currentWindowHandle = driver.getWindowHandle();
DriverTestPage.link.click();
List<ScreenShot> screenshots = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class, false, false);
Assert.assertEquals(screenshots.size(), 1);
Assert.assertEquals(currentWindowHandle, driver.getWindowHandle());
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil 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);
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestScreenshotUtil method testDesktopScreenshots.
/**
* issue #300: check that desktop capture is done
* @param testContext
* @throws Exception
*/
@Test(groups = { "it" })
public void testDesktopScreenshots(ITestContext testContext) throws Exception {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
ScreenShot screenshot = new ScreenshotUtil(null).capture(SnapshotTarget.SCREEN, ScreenShot.class);
Assert.assertTrue(new File(screenshot.getFullImagePath()).exists());
}
Aggregations