use of io.qameta.allure.model.StatusDetails in project page-factory-2 by sbtqa.
the class JunitReporter method handleStep.
public static Object handleStep(ProceedingJoinPoint joinPoint) throws Throwable {
// FIXME: need to get another way to filter junit only steps cuz getStackTrace is very hard
boolean isFromCucumber = Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(stackTraceElement -> stackTraceElement.getClassName().matches("ru\\.sbtqa\\.tag\\.stepdefs\\.[en|ru]\\..*"));
if (isFromCucumber) {
return joinPoint.proceed();
} else {
boolean isTestCaseStarted = Allure.getLifecycle().getCurrentTestCase().isPresent();
if (!isTestCaseStarted) {
String testCaseId = MD5.hash(joinPoint.getSignature().toShortString());
String testResultUid = MD5.hash(joinPoint.toLongString());
Allure.getLifecycle().scheduleTestCase(new TestResult().setTestCaseId(testCaseId).setUuid(testResultUid));
Allure.getLifecycle().startTestCase(testResultUid);
}
Object[] args = normalizeArgs(joinPoint.getArgs());
String methodName = joinPoint.getSignature().getName();
// I18n contains template for steps as <methodName><dot><argsCount>. For example: fill.2
String methodNameWithArgsCount = methodName + "." + args.length;
String stepUid = createUid(joinPoint);
String stepNameI18n = getStepNameI18n(joinPoint, methodNameWithArgsCount);
// if step has i18n template - substitute args to it
String stepName = String.format((stepNameI18n.equals(methodNameWithArgsCount) ? methodName : stepNameI18n), args);
Allure.getLifecycle().startStep(stepUid, new StepResult().setName(stepName));
System.out.println("\t * " + stepName);
try {
Object r = joinPoint.proceed();
Allure.getLifecycle().updateStep(stepUid, stepResult -> stepResult.setStatus(Status.PASSED));
return r;
} catch (Throwable t) {
Allure.getLifecycle().updateStep(stepUid, stepResult -> stepResult.setStatus(Status.FAILED).setStatusDetails(new StatusDetails().setTrace(ExceptionUtils.getStackTrace(t)).setMessage(t.getMessage())));
throw t;
} finally {
attachParameters(methodName, args, createUid(joinPoint), stepName);
Allure.getLifecycle().stopStep(stepUid);
}
}
}
Aggregations