Search in sources :

Example 11 with ScreenshotUtil

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();
}
Also used : ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) ImageDetector(com.seleniumtests.util.imaging.ImageDetector) Dimension(org.openqa.selenium.Dimension) File(java.io.File) Test(org.testng.annotations.Test) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest)

Example 12 with ScreenshotUtil

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());
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) MockitoTest(com.seleniumtests.MockitoTest) Test(org.testng.annotations.Test)

Example 13 with ScreenshotUtil

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));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) ScenarioLogger(com.seleniumtests.util.logging.ScenarioLogger)

Example 14 with ScreenshotUtil

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);
    }
}
Also used : ImageLinkInfo(com.seleniumtests.reporter.info.ImageLinkInfo) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) Har(net.lightbody.bmp.core.har.Har) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) Info(com.seleniumtests.reporter.info.Info) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) ImageLinkInfo(com.seleniumtests.reporter.info.ImageLinkInfo) ScenarioException(com.seleniumtests.customexception.ScenarioException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) IOException(java.io.IOException)

Example 15 with ScreenshotUtil

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());
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) Test(org.testng.annotations.Test) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest)

Aggregations

ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)24 Test (org.testng.annotations.Test)21 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)18 File (java.io.File)12 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)11 BufferedImage (java.awt.image.BufferedImage)8 Dimension (org.openqa.selenium.Dimension)8 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)3 WebDriver (org.openqa.selenium.WebDriver)3 SnapshotTarget (com.seleniumtests.driver.screenshots.SnapshotTarget)2 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)2 MockitoTest (com.seleniumtests.MockitoTest)1 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 DriverSubTestPage (com.seleniumtests.it.driver.support.pages.DriverSubTestPage)1 ImageLinkInfo (com.seleniumtests.reporter.info.ImageLinkInfo)1 Info (com.seleniumtests.reporter.info.Info)1 MultipleInfo (com.seleniumtests.reporter.info.MultipleInfo)1 ImageDetector (com.seleniumtests.util.imaging.ImageDetector)1