use of io.qameta.allure.model.StepResult in project page-factory-2 by sbtqa.
the class JunitReporter method attachParameters.
private static void attachParameters(String methodName, Object[] args, String uid, String stepName) {
if (stepName.equals(methodName)) {
Arrays.stream(args).forEach(arg -> {
Allure.getLifecycle().startStep(uid + System.currentTimeMillis(), new StepResult().setName(arg.toString()).setStatus(Status.PASSED));
Allure.getLifecycle().stopStep();
});
}
}
use of io.qameta.allure.model.StepResult 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);
}
}
}
use of io.qameta.allure.model.StepResult in project page-factory-2 by sbtqa.
the class ParamsHelper method addParam.
/**
* Add parameter to allure report
*
* @param format a format string as described in Format string syntax.
* @param parameters parameters referenced by the format specifiers in the format string
*/
public static void addParam(String format, String[] parameters) {
String name = String.format(format, (Object[]) parameters);
LOG.debug(name);
Allure.getLifecycle().startStep(randomUUID().toString(), new StepResult().setName(name).setStatus(Status.PASSED));
Allure.getLifecycle().stopStep();
}
Aggregations