use of io.qameta.allure.model.TestResult 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.TestResult in project page-factory-2 by sbtqa.
the class CriticalStepCheckAspect method sendCaseFinished.
@Around("sendCaseFinished(event)")
public void sendCaseFinished(ProceedingJoinPoint joinPoint, TestCaseFinished event) throws Throwable {
boolean hasFailedNonCriticalStep = hasFailedNonCriticalStep(event.testCase);
if (hasFailedNonCriticalStep) {
final Result result = new Result(Result.Type.PASSED, event.result.getDuration(), new AutotestError(NON_CRITICAL_CATEGORY_MESSAGE));
event = new TestCaseFinished(event.getTimeStamp(), event.getTimeStampMillis(), event.testCase, result);
Allure.getLifecycle().updateTestCase(getCurrentTestCaseUid(event.testCase), testResult -> testResult.setStatus(Status.PASSED));
joinPoint.proceed(new Object[] { event });
} else {
joinPoint.proceed();
}
}
use of io.qameta.allure.model.TestResult in project page-factory-2 by sbtqa.
the class CriticalStepCheckAspect method getCurrentTestCaseUid.
private String getCurrentTestCaseUid(TestCase testCase) throws IllegalAccessException {
final String testCaseLocation = testCase.getUri() + ":" + testCase.getLine();
String uid = md5(testCaseLocation);
AllureStorage allureStorage = (AllureStorage) readDeclaredField(Allure.getLifecycle(), "storage", true);
Map<String, Object> storage = (Map<String, Object>) readDeclaredField(allureStorage, "storage", true);
Collection<Object> testResults = storage.values();
Optional<Object> testResultOptional = testResults.stream().filter(Objects::nonNull).filter(o -> o instanceof TestResult && ((TestResult) o).getHistoryId().equals(uid)).findFirst();
return testResultOptional.isPresent() ? ((TestResult) testResultOptional.get()).getUuid() : uid;
}
Aggregations