use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCaptureAllPage.
/**
* Check we can rebuild the whole page from partial captures
* This is useful for chrome as snapshot is only taken from visible display
* For firefox, nothing to do
* @throws IOException
*/
@Test(groups = { "it" })
public void testCaptureAllPage() throws IOException {
driver.manage().window().setSize(new Dimension(400, 300));
WaitHelper.waitForSeconds(1);
String topFilePath = generateCaptureFilePath();
FileUtility.writeImage(topFilePath, new ScreenshotUtil(driver).capturePage(0, 0));
// get full picture
File image = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
String bottomFilePath = generateCaptureFilePath();
FileUtility.writeImage(bottomFilePath, new ScreenshotUtil(driver).capturePage(0, 0));
// exception thrown if nothing found
ImageDetector detectorTop = new ImageDetector(image, new File(topFilePath), 0.001);
detectorTop.detectExactZoneWithScale();
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestHtmlUnitBrowserSnapshot method testHtmlUnitCapture.
/**
* Check no error is raised
*/
@Test(groups = { "it" })
public void testHtmlUnitCapture() {
ScreenshotUtil screenshotUtil = new ScreenshotUtil();
ScreenShot screenshot = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class);
Assert.assertNull(screenshot.getImagePath());
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class StubTestClassForListener5 method startDriver.
private void startDriver() {
WebDriver driver = WebUIDriver.getWebDriver(true);
driver.get("file:///" + Thread.currentThread().getContextClassLoader().getResource("tu/test.html").getFile());
((ScenarioLogger) logger).logScreenshot(new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class));
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class WebUIDriver method logFinalDriverState.
/**
* Logs current state of the browser
*/
private void logFinalDriverState(ITestResult testResult) {
if (driver != null) {
try {
// issue #414: capture the whole screen
driver.switchTo().defaultContent();
// force screenshotUtil to use the driver of this WebUiDriver, not the currently selected one
for (ScreenShot screenshot : new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class, true, true)) {
scenarioLogger.logScreenshot(screenshot, null, name, SnapshotCheckType.FALSE);
// add the last screenshots to TestInfo so that there is a quicklink on reports
Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
if (lastStateInfo != null) {
((MultipleInfo) lastStateInfo).addInfo(new ImageLinkInfo(TestNGResultUtils.getUniqueTestName(testResult) + "/" + screenshot.getImagePath()));
}
}
} catch (Exception e) {
scenarioLogger.log("Error while logging: " + e.getMessage());
}
}
try {
// stop HAR capture
if (config.getBrowserMobProxy() != null) {
Har har = config.getBrowserMobProxy().endHar();
scenarioLogger.logNetworkCapture(har, name);
}
} catch (Exception e) {
scenarioLogger.log("Error while logging: " + e.getMessage());
} finally {
config.setBrowserMobProxy(null);
}
}
use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testSnapshotWithJavascriptErrors.
/**
* issue #272: Test taking snapshot inside an iframe when some javascript error occurs. This happens with some website where access to iframe seems denied
* We want to get source and title, even if picture is not get
* @throws Exception
*/
@Test(groups = { "it" })
public void testSnapshotWithJavascriptErrors() throws Exception {
driver.switchTo().frame(DriverTestPage.iframe.getElement());
// get real capture
generateCaptureFilePath();
CustomEventFiringWebDriver mockedDriver = (CustomEventFiringWebDriver) spy(driver);
ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
doThrow(JavascriptException.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());
}
Aggregations