Search in sources :

Example 1 with SnapshotTarget

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

the class PageObject method captureElementSnapshot.

/**
 * Capture a portion of the page by giving the element to capture
 * @param snapshotName		the snapshot name
 * @param element			the element to capture
 * @param checkSnapshot		if true, will send snapshot to server (when seleniumRobot is configured for this) for comparison
 */
public void captureElementSnapshot(String snapshotName, WebElement element, SnapshotCheckType checkSnapshot) {
    SnapshotTarget snapshotTarget = new SnapshotTarget(element);
    ScreenShot screenShot = screenshotUtil.capture(snapshotTarget, ScreenShot.class, computeScrollDelay(checkSnapshot));
    // check SnapshotCheckType configuration is compatible with the snapshot
    checkSnapshot.check(snapshotTarget);
    storeSnapshot(snapshotName, screenShot, checkSnapshot);
}
Also used : SnapshotTarget(com.seleniumtests.driver.screenshots.SnapshotTarget) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot)

Example 2 with SnapshotTarget

use of com.seleniumtests.driver.screenshots.SnapshotTarget 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 3 with SnapshotTarget

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

the class TestBrowserSnapshot method testCaptureNonExistingElement.

/**
 * Check that if element does not exist, a Scenario exception is raised
 * @throws IOException
 */
@Test(groups = { "it" }, expectedExceptions = ScenarioException.class)
public void testCaptureNonExistingElement() throws IOException {
    driver.manage().window().maximize();
    WaitHelper.waitForSeconds(1);
    // get cropped picture
    String filePath = generateCaptureFilePath();
    BufferedImage image = new ScreenshotUtil(driver).capture(new SnapshotTarget(DriverTestPage.textElementNotPresent), 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)

Aggregations

SnapshotTarget (com.seleniumtests.driver.screenshots.SnapshotTarget)3 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)2 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)2 BufferedImage (java.awt.image.BufferedImage)2 Test (org.testng.annotations.Test)2 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)1