Search in sources :

Example 16 with ScreenshotUtil

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

the class TestBrowserSnapshot method testMultipleWindowsCaptureWithError.

/**
 * Check that when an error occurs when communicating with driver, a desktop capture is taken
 */
@Test(groups = { "it" })
public void testMultipleWindowsCaptureWithError() {
    DriverTestPage.link.click();
    WebDriver mockedDriver = spy(driver);
    ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
    when(mockedDriver.getWindowHandles()).thenThrow(WebDriverException.class);
    List<ScreenShot> screenshots = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class, true, false);
    Assert.assertEquals(screenshots.size(), 1);
    verify(screenshotUtil).captureDesktop();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) 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)

Example 17 with ScreenshotUtil

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

the class TestBrowserSnapshot method testRemoveHeaderAndFooter.

/**
 * Test if we succeed in cropping picture according to requested parameters
 * @throws IOException
 */
@Test(groups = { "it" })
public void testRemoveHeaderAndFooter() 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, 5);
    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], 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 18 with ScreenshotUtil

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

the class TestBrowserSnapshot method testRemoveScrollbarCapture.

/**
 * Test if we succeed in removing scrollbars from capture (horizontal and vertical)
 * @throws IOException
 */
@Test(groups = { "it" })
public void testRemoveScrollbarCapture() throws IOException {
    driver.manage().window().setSize(new Dimension(400, 300));
    WaitHelper.waitForSeconds(1);
    // 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 were already removed from screenshot
    Assert.assertEquals(image.getWidth(), screenshotDim.width);
    Assert.assertEquals(image.getHeight(), screenshotDim.height);
}
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 19 with ScreenshotUtil

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

the class TestBrowserSnapshot method testCaptureElement.

/**
 * Test if we succeed in capturing a single element
 * @throws IOException
 */
@Test(groups = { "it" })
public void testCaptureElement() throws IOException {
    driver.manage().window().maximize();
    WaitHelper.waitForSeconds(1);
    // get cropped picture
    String filePath = generateCaptureFilePath();
    BufferedImage image = new ScreenshotUtil(driver).capture(new SnapshotTarget(DriverTestPage.table), 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);
}
Also used : SnapshotTarget(com.seleniumtests.driver.screenshots.SnapshotTarget) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) BufferedImage(java.awt.image.BufferedImage) Test(org.testng.annotations.Test) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest)

Example 20 with ScreenshotUtil

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

the class TestBrowserSnapshot method testDesktopSnapshot.

/**
 * Check we can capture desktop snapshots
 */
@Test(groups = { "it" })
public void testDesktopSnapshot() {
    File output = new ScreenshotUtil(driver).capture(SnapshotTarget.SCREEN, File.class);
    Assert.assertTrue(FileUtils.sizeOf(output) > 0);
}
Also used : 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