Search in sources :

Example 1 with ScreenshotUtil

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();
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) File(java.io.File) Test(org.testng.annotations.Test) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 2 with ScreenshotUtil

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

Example 3 with ScreenshotUtil

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

Example 4 with ScreenshotUtil

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

Example 5 with ScreenshotUtil

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())));
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) File(java.io.File) 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