Search in sources :

Example 1 with MultipleInfo

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

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

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

the class SeleniumRobotTestListener method logLastStep.

/**
 * On test end, will take a snap shot and store it
 */
private void logLastStep(ITestResult testResult) {
    // finalize manual steps if we use this mode
    try {
        TestTasks.addStep(null);
    } catch (ConfigurationException e) {
    // no problem as it's to close the previous manual step
    }
    TestStep tearDownStep = new TestStep(TestStepManager.LAST_STEP_NAME, testResult, new ArrayList<>(), true);
    scenarioLogger.logTestInfo(TestStepManager.LAST_STATE_NAME, new MultipleInfo(TestStepManager.LAST_STATE_NAME));
    // add step to video
    VideoRecorder videoRecorder = WebUIDriver.getThreadVideoRecorder();
    if (videoRecorder != null) {
        CustomEventFiringWebDriver.displayStepOnScreen(tearDownStep.getName(), SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), videoRecorder);
    }
    TestStepManager.setCurrentRootTestStep(tearDownStep);
    if (testResult.isSuccess()) {
        scenarioLogger.log("Test is OK");
    } else if (testResult.getStatus() == ITestResult.FAILURE) {
        // issue #289: allow retry in case SO_TIMEOUT is raised
        if (SeleniumTestsContextManager.getThreadContext().getRunMode() != DriverMode.LOCAL && testResult.getThrowable() != null && testResult.getThrowable() instanceof WebDriverException && testResult.getThrowable().getMessage().contains("SO_TIMEOUT")) {
            logger.info("Test is retried due to SO_TIMEOUT");
            increaseMaxRetry();
        }
        String error = testResult.getThrowable() != null ? ExceptionUtility.getExceptionMessage(testResult.getThrowable()) : "no error found";
        scenarioLogger.log("Test is KO with error: " + error);
    } else {
        scenarioLogger.log("Test has not started or has been skipped");
    }
    logThrowableToTestEndStep(testResult);
    WebUIDriver.logFinalDriversState(testResult);
    tearDownStep.updateDuration();
    TestStepManager.logTestStep(tearDownStep);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) WebDriverException(org.openqa.selenium.WebDriverException)

Example 4 with MultipleInfo

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

MultipleInfo (com.seleniumtests.reporter.info.MultipleInfo)4 Info (com.seleniumtests.reporter.info.Info)3 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 TestStep (com.seleniumtests.reporter.logger.TestStep)2 IOException (java.io.IOException)2 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)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 ScenarioLogger (com.seleniumtests.util.logging.ScenarioLogger)1 VideoRecorder (com.seleniumtests.util.video.VideoRecorder)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Har (net.lightbody.bmp.core.har.Har)1 WebDriverException (org.openqa.selenium.WebDriverException)1 AfterMethod (org.testng.annotations.AfterMethod)1