Search in sources :

Example 1 with MD5

use of ru.sbtqa.tag.pagefactory.utils.MD5 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);
        }
    }
}
Also used : Status(io.qameta.allure.model.Status) MD5(ru.sbtqa.tag.pagefactory.utils.MD5) Arrays(java.util.Arrays) I18N(ru.sbtqa.tag.qautils.i18n.I18N) TestResult(io.qameta.allure.model.TestResult) PageEntry(ru.sbtqa.tag.pagefactory.annotations.PageEntry) Page(ru.sbtqa.tag.pagefactory.Page) Endpoint(ru.sbtqa.tag.pagefactory.annotations.rest.Endpoint) StatusDetails(io.qameta.allure.model.StatusDetails) Allure(io.qameta.allure.Allure) Locale(java.util.Locale) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ApiEndpoint(ru.sbtqa.tag.pagefactory.ApiEndpoint) StepResult(io.qameta.allure.model.StepResult) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Configuration(ru.sbtqa.tag.pagefactory.properties.Configuration) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) StatusDetails(io.qameta.allure.model.StatusDetails) TestResult(io.qameta.allure.model.TestResult) StepResult(io.qameta.allure.model.StepResult)

Aggregations

Allure (io.qameta.allure.Allure)1 Status (io.qameta.allure.model.Status)1 StatusDetails (io.qameta.allure.model.StatusDetails)1 StepResult (io.qameta.allure.model.StepResult)1 TestResult (io.qameta.allure.model.TestResult)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Arrays (java.util.Arrays)1 Locale (java.util.Locale)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 ApiEndpoint (ru.sbtqa.tag.pagefactory.ApiEndpoint)1 Page (ru.sbtqa.tag.pagefactory.Page)1 PageEntry (ru.sbtqa.tag.pagefactory.annotations.PageEntry)1 Endpoint (ru.sbtqa.tag.pagefactory.annotations.rest.Endpoint)1 Configuration (ru.sbtqa.tag.pagefactory.properties.Configuration)1 MD5 (ru.sbtqa.tag.pagefactory.utils.MD5)1 I18N (ru.sbtqa.tag.qautils.i18n.I18N)1