Search in sources :

Example 21 with ScreenshotUtil

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

the class TestBrowserSnapshot method testSnapshotWithErrors.

/**
 * Test that if an unexpected error occurs when snapshot is taken, take desktop
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotWithErrors() throws Exception {
    driver.switchTo().frame(DriverTestPage.iframe.getElement());
    // get real capture
    generateCaptureFilePath();
    CustomEventFiringWebDriver mockedDriver = (CustomEventFiringWebDriver) spy(driver);
    ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
    doThrow(WebDriverException.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)

Example 22 with ScreenshotUtil

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

the class TestBrowserSnapshot method testCurrentWindowsCapture.

/**
 * Check that only main window is captured
 */
@Test(groups = { "it" })
public void testCurrentWindowsCapture() {
    String currentWindowHandle = driver.getWindowHandle();
    DriverTestPage.link.click();
    List<ScreenShot> screenshots = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class, false, false);
    Assert.assertEquals(screenshots.size(), 1);
    Assert.assertEquals(currentWindowHandle, driver.getWindowHandle());
}
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)

Example 23 with ScreenshotUtil

use of com.seleniumtests.driver.screenshots.ScreenshotUtil 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)

Example 24 with ScreenshotUtil

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

the class TestScreenshotUtil method testDesktopScreenshots.

/**
 * issue #300: check that desktop capture is done
 * @param testContext
 * @throws Exception
 */
@Test(groups = { "it" })
public void testDesktopScreenshots(ITestContext testContext) throws Exception {
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
    ScreenShot screenshot = new ScreenshotUtil(null).capture(SnapshotTarget.SCREEN, ScreenShot.class);
    Assert.assertTrue(new File(screenshot.getFullImagePath()).exists());
}
Also used : 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)

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