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);
}
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()));
}
}
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);
}
}
Aggregations