Search in sources :

Example 1 with Info

use of com.seleniumtests.reporter.info.Info in project seleniumRobot by bhecquet.

the class SeleniumRobotTestPlan method finishTestMethod.

/**
 * According to TestNG doc, this method will be executed after the \@AfterMethod inside test classes
 * #issue 136: This will close any remaining browser for this thread and forbid user to create a new driver in other \@AfterXXX
 */
@AfterMethod(alwaysRun = true)
public void finishTestMethod(Method method, ITestResult testResult) {
    // stop video capture and log file
    File videoFile = WebUIDriver.stopVideoCapture();
    if (videoFile != null) {
        VideoUtils.extractReferenceForSteps(videoFile, TestStepManager.getInstance().getTestSteps(), Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
        if (SeleniumTestsContextManager.getThreadContext().getVideoCapture() == VideoCaptureMode.TRUE || (SeleniumTestsContextManager.getThreadContext().getVideoCapture() == VideoCaptureMode.ON_SUCCESS && testResult.isSuccess()) || (SeleniumTestsContextManager.getThreadContext().getVideoCapture() == VideoCaptureMode.ON_ERROR && !testResult.isSuccess())) {
            ((ScenarioLogger) logger).logFileToTestEnd(videoFile.getAbsoluteFile(), "Video capture");
            Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
            if (lastStateInfo != null) {
                ((MultipleInfo) lastStateInfo).addInfo(new VideoLinkInfo(TestNGResultUtils.getUniqueTestName(testResult) + "/videoCapture.avi"));
            }
            logger.info("Video file copied to " + videoFile.getAbsolutePath());
        } else {
            try {
                Files.delete(Paths.get(videoFile.getAbsolutePath()));
            } catch (IOException e) {
                logger.warn(String.format("Video file %s not deleted: %s", videoFile.getAbsoluteFile(), e.getMessage()));
            }
        }
    }
    WebUIDriver.cleanUp();
    SeleniumTestsContextManager.getThreadContext().setDriverCreationBlocked(true);
    SeleniumRobotTestListener.getCurrentListener().onTestFullyFinished(testResult);
}
Also used : ScenarioLogger(com.seleniumtests.util.logging.ScenarioLogger) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) IOException(java.io.IOException) Info(com.seleniumtests.reporter.info.Info) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) VideoLinkInfo(com.seleniumtests.reporter.info.VideoLinkInfo) VideoLinkInfo(com.seleniumtests.reporter.info.VideoLinkInfo) File(java.io.File) AfterMethod(org.testng.annotations.AfterMethod)

Example 2 with Info

use of com.seleniumtests.reporter.info.Info in project seleniumRobot by bhecquet.

the class SeleniumRobotTestListener method logThrowableToTestEndStep.

private void logThrowableToTestEndStep(ITestResult testResult) {
    if (testResult.getThrowable() != null) {
        logger.error(testResult.getThrowable().getMessage());
        // when error occurs, exception raised is not added to the step if this error is outside of a PageObject
        // we add it there as an exception always terminates the test (except for soft assert, but this case is handled in SoftAssertion.aj)
        TestStep lastStep = TestStepManager.getCurrentRootTestStep();
        if (lastStep == null) {
            // when steps are automatic, they are closed (lastStep is null) once method is finished
            try {
                lastStep = Iterables.getLast(SeleniumTestsContextManager.getThreadContext().getTestStepManager().getTestSteps());
            } catch (NoSuchElementException e) {
            // if last step does not exist, do not crash
            }
        }
        if (lastStep != null) {
            lastStep.setFailed(true);
            lastStep.setActionException(testResult.getThrowable());
        }
        Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
        ((MultipleInfo) lastStateInfo).addInfo(new LogInfo(testResult.getThrowable().getMessage()));
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) LogInfo(com.seleniumtests.reporter.info.LogInfo) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) Info(com.seleniumtests.reporter.info.Info) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) LogInfo(com.seleniumtests.reporter.info.LogInfo)

Example 3 with Info

use of com.seleniumtests.reporter.info.Info 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)

Aggregations

Info (com.seleniumtests.reporter.info.Info)3 MultipleInfo (com.seleniumtests.reporter.info.MultipleInfo)3 IOException (java.io.IOException)2 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)1 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)1 ImageLinkInfo (com.seleniumtests.reporter.info.ImageLinkInfo)1 LogInfo (com.seleniumtests.reporter.info.LogInfo)1 VideoLinkInfo (com.seleniumtests.reporter.info.VideoLinkInfo)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 ScenarioLogger (com.seleniumtests.util.logging.ScenarioLogger)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Har (net.lightbody.bmp.core.har.Har)1 AfterMethod (org.testng.annotations.AfterMethod)1