use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class JiraConnector method formatDescription.
/**
* Format description of the issue
*/
@Override
protected void formatDescription(String testName, List<TestStep> failedSteps, TestStep lastTestStep, String description, StringBuilder fullDescription) {
fullDescription.append(String.format("*Test:* %s\n", testName));
if (description != null) {
fullDescription.append(String.format("*Description:* %s\n", description.replace("Test goal:", "*Test goal:*")));
}
if (SeleniumTestsContextManager.getThreadContext().getStartedBy() != null) {
fullDescription.append(String.format("*Started by:* %s\n", SeleniumTestsContextManager.getThreadContext().getStartedBy()));
}
for (TestStep failedStep : failedSteps) {
fullDescription.append(String.format("*Error step #%d (%s):* *{color:#de350b}%s{color}*\n", failedStep.getPosition(), failedStep.getName(), failedStep.getActionException()));
}
formatFailedStep(failedSteps, fullDescription);
fullDescription.append("h2. Last logs\n");
if (lastTestStep != null) {
fullDescription.append(String.format("{code:java}%s{code}", lastTestStep.toString()));
fullDescription.append("\n\nh2. Associated screenshots\n");
List<ScreenShot> screenshots = lastTestStep.getSnapshots().stream().map(Snapshot::getScreenshot).collect(Collectors.toList());
for (ScreenShot screenshot : screenshots) {
if (screenshot.getFullImagePath() != null && new File(screenshot.getFullImagePath()).exists()) {
fullDescription.append(String.format("!%s|thumbnail!\n", new File(screenshot.getFullImagePath()).getName()));
}
}
}
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class Uft method readAction.
/**
* Read an action element
* <p>
* // * @param parentStep
*
* @param actionElement
* @throws DataConversionException
*/
private TestStep readAction(Element actionElement) throws DataConversionException {
TestStep actionStep = new TestStep("UFT: " + actionElement.getChildText("AName").trim(), Reporter.getCurrentTestResult(), new ArrayList<>(), false);
Element summary = actionElement.getChild("Summary");
if (summary != null && summary.getAttribute("failed").getIntValue() != 0) {
actionStep.setFailed(true);
}
for (Element element : actionElement.getChildren()) {
if ("Action".equals(element.getName())) {
TestStep readStep = readAction(element);
actionStep.addStep(readStep);
} else if ("Step".equals(element.getName())) {
TestAction readAction = readStep(element);
actionStep.addAction(readAction);
}
}
return actionStep;
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class Uft method readXmlResult.
public List<TestStep> readXmlResult(String xmlString) {
Document document;
SAXBuilder builder = new SAXBuilder();
List<TestStep> listStep = new ArrayList<>();
try {
String xml = xmlString.substring(xmlString.indexOf("<"));
String xml10pattern = "[^" + "\u0009\r\n" + "\u0020-\uD7FF" + "\uE000-\uFFFD" + "\ud800\udc00-\udbff\udfff" + "]";
xml = xml.replaceAll(xml10pattern, "");
// we skip BOM by searching the first "<" character
document = builder.build(new InputSource(new StringReader(xml)));
Element docElement = document.getRootElement().getChild("Doc");
Element summary = docElement.getChild("Summary");
Element elementToIterate = docElement.getChild("DIter");
Element iterationChild = elementToIterate.getChild("Action");
if (!iterationChild.getChildren("Action").isEmpty()) {
elementToIterate = iterationChild;
}
for (Element element : elementToIterate.getChildren()) {
if ("Action".equals(element.getName())) {
TestStep readStep = readAction(element);
listStep.add(readStep);
} else if ("Step".equals(element.getName())) {
readStep(element);
}
}
} catch (IndexOutOfBoundsException e) {
addStepWithoutXml(listStep, "Invalid XML data: ", e);
} catch (JDOMException | IOException e) {
addStepWithoutXml(listStep, "Could not read UFT report: ", e);
}
return listStep;
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class LogAction method commonLogTestStep.
/**
* Log a TestStep, inside a parent TestStep or not
* Common method used for all test step logging
* @return
* @throws Throwable
*/
private Object commonLogTestStep(ProceedingJoinPoint joinPoint, String stepNamePrefix, boolean configStep) throws Throwable {
Object reply = null;
boolean rootStep = false;
TestStep previousParent = null;
// step name will contain method arguments only if it's not a configuration method (as they are generic)
TestStep currentStep = buildRootStep(joinPoint, stepNamePrefix, !configStep);
if ("openPage".equals(joinPoint.getSignature().getName()) && joinPoint.getTarget() instanceof PageObject) {
PageObject page = (PageObject) joinPoint.getTarget();
currentStep.addAction(new TestAction(String.format("Opening page %s", page.getClass().getSimpleName()), false, new ArrayList<>()));
}
BrowserMobProxy mobProxy = WebUIDriver.getBrowserMobProxy();
NLWebDriver neoloadDriver = WebUIDriver.getNeoloadDriver();
VideoRecorder videoRecorder = WebUIDriver.getThreadVideoRecorder();
// if rootStep is null, parent step is also null
if (TestStepManager.getCurrentRootTestStep() == null) {
// will also set parent step
TestStepManager.setCurrentRootTestStep(currentStep);
rootStep = true;
if (mobProxy != null) {
mobProxy.newPage(currentStep.getName());
}
if (videoRecorder != null) {
CustomEventFiringWebDriver.displayStepOnScreen(currentStep.getName(), SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), videoRecorder);
}
if (neoloadDriver != null) {
neoloadDriver.startTransaction(currentStep.getName());
}
} else {
TestStepManager.getParentTestStep().addStep(currentStep);
previousParent = TestStepManager.getParentTestStep();
TestStepManager.setParentTestStep(currentStep);
}
// set the start date once step is initialized so that when we get the video frame associated to step, step name displayed on screen is the same as the running step name
currentStep.setStartDate();
try {
reply = joinPoint.proceed(joinPoint.getArgs());
} catch (Throwable e) {
currentStep.setFailed(true);
currentStep.setActionException(e);
// issue #287 (https://github.com/cbeust/testng/issues/2148): is method an @AfterMethod. Then do not rethrow exception
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
if (methodSignature.getMethod().getAnnotation(AfterMethod.class) != null) {
scenarioLogger.error(String.format("Error in @AfterMethod %s: %s", methodSignature, e.getMessage()));
} else {
throw e;
}
} finally {
if (rootStep) {
TestStepManager.getCurrentRootTestStep().updateDuration();
TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
if (neoloadDriver != null) {
neoloadDriver.stopTransaction();
}
} else {
TestStepManager.setParentTestStep(previousParent);
}
}
return reply;
}
use of com.seleniumtests.reporter.logger.TestStep 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()));
}
}
Aggregations