Search in sources :

Example 36 with ScreenShot

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

the class WebUIDriver method logFinalDriverState.

/**
 * Logs current state of the browser
 */
private void logFinalDriverState(ITestResult testResult) {
    if (driver != null) {
        try {
            // issue #414: capture the whole screen
            driver.switchTo().defaultContent();
            // force screenshotUtil to use the driver of this WebUiDriver, not the currently selected one
            for (ScreenShot screenshot : new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class, true, true)) {
                scenarioLogger.logScreenshot(screenshot, null, name, SnapshotCheckType.FALSE);
                // add the last screenshots to TestInfo so that there is a quicklink on reports
                Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
                if (lastStateInfo != null) {
                    ((MultipleInfo) lastStateInfo).addInfo(new ImageLinkInfo(TestNGResultUtils.getUniqueTestName(testResult) + "/" + screenshot.getImagePath()));
                }
            }
        } catch (Exception e) {
            scenarioLogger.log("Error while logging: " + e.getMessage());
        }
    }
    try {
        // stop HAR capture
        if (config.getBrowserMobProxy() != null) {
            Har har = config.getBrowserMobProxy().endHar();
            scenarioLogger.logNetworkCapture(har, name);
        }
    } catch (Exception e) {
        scenarioLogger.log("Error while logging: " + e.getMessage());
    } finally {
        config.setBrowserMobProxy(null);
    }
}
Also used : ImageLinkInfo(com.seleniumtests.reporter.info.ImageLinkInfo) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) Har(net.lightbody.bmp.core.har.Har) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) Info(com.seleniumtests.reporter.info.Info) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) ImageLinkInfo(com.seleniumtests.reporter.info.ImageLinkInfo) ScenarioException(com.seleniumtests.customexception.ScenarioException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) IOException(java.io.IOException)

Example 37 with ScreenShot

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

the class TestJiraConnector method init.

@BeforeMethod(groups = { "no-ti" })
public void init() throws IOException {
    File tmpImg = File.createTempFile("img", ".png");
    File tmpHtml = File.createTempFile("html", ".html");
    screenshot = new ScreenShot();
    screenshot.setImagePath("screenshot/" + tmpImg.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(tmpImg, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1 = new TestStep("step 1", null, new ArrayList<>(), false);
    step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step2 = new TestStep("step 2", null, new ArrayList<>(), false);
    step2.setFailed(true);
    step2.addAction(new TestAction("action1", false, new ArrayList<>()));
    step2.addAction(new TestAction("action2", false, new ArrayList<>()));
    step2.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    stepEnd = new TestStep("Test end", null, new ArrayList<>(), false);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end", SnapshotCheckType.FULL), 1, null);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end2", SnapshotCheckType.FULL), 1, null);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File) TestAction(com.seleniumtests.reporter.logger.TestAction) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 38 with ScreenShot

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

the class TestSeleniumRobotSnapshotServerConnector method testCreateSnapshot.

/**
 * create a snapshot
 * @throws IOException
 */
@Test(groups = { "it" })
public void testCreateSnapshot() throws IOException {
    Integer sessionId = connector.createSession("Session1");
    Integer testCaseId = connector.createTestCase("Test 2");
    Integer testCaseInSessionId = connector.createTestCaseInSession(sessionId, testCaseId, "Test 2");
    Integer testStepId = connector.createTestStep("Step 1", testCaseInSessionId);
    Integer stepResultId = connector.recordStepResult(true, "logs", 1, sessionId, testCaseInSessionId, testStepId);
    File image = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "img.png").toFile();
    image.deleteOnExit();
    FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("tu/images/ffLogoConcat.png"), image);
    ScreenShot screenshot = new ScreenShot();
    screenshot.setImagePath(image.getName());
    Snapshot snapshot = new Snapshot(screenshot, "img", SnapshotCheckType.TRUE);
    Integer snapshotId = connector.createSnapshot(snapshot, sessionId, testCaseInSessionId, stepResultId);
    Assert.assertNotNull(snapshotId);
}
Also used : Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 39 with ScreenShot

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

the class TestBrowserSnapshot method testSnapshotWithJavascriptErrors.

/**
 * issue #272: Test taking snapshot inside an iframe when some javascript error occurs. This happens with some website where access to iframe seems denied
 * We want to get source and title, even if picture is not get
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotWithJavascriptErrors() throws Exception {
    driver.switchTo().frame(DriverTestPage.iframe.getElement());
    // get real capture
    generateCaptureFilePath();
    CustomEventFiringWebDriver mockedDriver = (CustomEventFiringWebDriver) spy(driver);
    ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
    doThrow(JavascriptException.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 40 with ScreenShot

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

Aggregations

ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)63 Test (org.testng.annotations.Test)45 File (java.io.File)37 GenericTest (com.seleniumtests.GenericTest)35 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 TestStep (com.seleniumtests.reporter.logger.TestStep)24 ArrayList (java.util.ArrayList)14 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)10 GenericFile (com.seleniumtests.reporter.logger.GenericFile)8 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)5 TestAction (com.seleniumtests.reporter.logger.TestAction)5 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 User (com.atlassian.jira.rest.client.api.domain.User)2 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 SnapshotTarget (com.seleniumtests.driver.screenshots.SnapshotTarget)2