Search in sources :

Example 6 with ScreenshotUtil

use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.

the class TestBrowserSnapshot method testRemoveHeader.

/**
 * Test if we succeed in cropping picture according to requested parameters
 * @throws IOException
 */
@Test(groups = { "it" })
public void testRemoveHeader() 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(6, 0);
    FileUtility.writeImage(filePath, image);
    int[] headerFooter = getHeaderAndFooterPixels(new File(filePath));
    // header should have been removed, not footer
    Assert.assertEquals(headerFooter[0], 0);
    Assert.assertEquals(headerFooter[1], 5);
    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 7 with ScreenshotUtil

use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.

the class TestBrowserSnapshot method testFixedHeaderFooterManualCropping.

/**
 * Check we are able to get all the content whereas we crop the header and footer manually (top and bottom pixels set automatically)
 * @throws IOException
 */
@Test(groups = { "it" })
public void testFixedHeaderFooterManualCropping() throws IOException {
    driver.manage().window().setSize(new Dimension(400, 300));
    WaitHelper.waitForSeconds(1);
    // get full picture without cropping
    File imageFull = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
    SeleniumTestsContextManager.getThreadContext().setSnapshotBottomCropping(5);
    SeleniumTestsContextManager.getThreadContext().setSnapshotTopCropping(6);
    // get picture with header and footer cropped
    File image = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
    int[] headerFooter = getHeaderAndFooterPixels(image);
    int[] headerFooterFull = getHeaderAndFooterPixels(imageFull);
    // header and footer should have been removed
    Assert.assertEquals(headerFooter[0], 6);
    Assert.assertEquals(headerFooter[1], 5);
    // depending on browser window size (depends on OS) image is split in more or less sections
    Assert.assertTrue(headerFooter[2] >= headerFooterFull[2]);
    Assert.assertEquals(ImageIO.read(image).getHeight(), ImageIO.read(imageFull).getHeight());
}
Also used : ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) Dimension(org.openqa.selenium.Dimension) File(java.io.File) Test(org.testng.annotations.Test) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest)

Example 8 with ScreenshotUtil

use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.

the class TestBrowserSnapshot method testFixedHeaderFooterAutomaticCropping.

/**
 * Check we are able to get all the content whereas we crop the header and footer automatically
 * @throws IOException
 */
@Test(groups = { "it" })
public void testFixedHeaderFooterAutomaticCropping() throws IOException {
    driver.manage().window().setSize(new Dimension(400, 300));
    WaitHelper.waitForSeconds(1);
    // get full picture without cropping
    File imageFull = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
    SeleniumTestsContextManager.getThreadContext().setSnapshotBottomCropping(null);
    SeleniumTestsContextManager.getThreadContext().setSnapshotTopCropping(null);
    // get picture with header and footer cropped
    File image = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, File.class);
    int[] headerFooter = getHeaderAndFooterPixels(image);
    // header and footer should have been removed
    Assert.assertEquals(headerFooter[0], 6);
    Assert.assertEquals(headerFooter[1], 5);
    // with automatic cropping, all fixed lines are removed, even green and red ones. Only remains the first top and last bottom one
    Assert.assertEquals(headerFooter[2], 2);
    Assert.assertEquals(ImageIO.read(image).getHeight(), ImageIO.read(imageFull).getHeight());
}
Also used : ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) Dimension(org.openqa.selenium.Dimension) File(java.io.File) Test(org.testng.annotations.Test) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest)

Example 9 with ScreenshotUtil

use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.

the class TestBrowserSnapshot method captureSnapshot.

private void captureSnapshot(String filePath) {
    String b64Img = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, String.class);
    byte[] byteArray = b64Img.getBytes();
    FileUtility.writeImage(filePath, byteArray);
}
Also used : ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil)

Example 10 with ScreenshotUtil

use of com.seleniumtests.driver.screenshots.ScreenshotUtil in project seleniumRobot by bhecquet.

the class TestBrowserSnapshot method testCurrentWindowsCapture2.

/**
 * Check that only main window is captured when no argument is given
 */
@Test(groups = { "it" })
public void testCurrentWindowsCapture2() {
    DriverTestPage.link.click();
    ScreenShot screenshot = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class);
    Assert.assertNotNull(screenshot.getImagePath());
}
Also used : 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