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