Search in sources :

Example 1 with TestResult

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);
        }
    }
}
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)

Example 2 with TestResult

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();
    }
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) TestCaseFinished(cucumber.api.event.TestCaseFinished) Result(cucumber.api.Result) TestResult(io.qameta.allure.model.TestResult) Around(org.aspectj.lang.annotation.Around)

Example 3 with TestResult

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;
}
Also used : Status(io.qameta.allure.model.Status) Arrays(java.util.Arrays) Result(cucumber.api.Result) Environment(ru.sbtqa.tag.pagefactory.environment.Environment) AllureNonCriticalError(ru.sbtqa.tag.pagefactory.exceptions.AllureNonCriticalError) TestStepFinished(cucumber.api.event.TestStepFinished) AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) Aspect(org.aspectj.lang.annotation.Aspect) Map(java.util.Map) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) Category(ru.sbtqa.tag.pagefactory.allure.Category) TestCase(cucumber.api.TestCase) TestResult(io.qameta.allure.model.TestResult) Collection(java.util.Collection) ResultsUtils.md5(io.qameta.allure.util.ResultsUtils.md5) Pointcut(org.aspectj.lang.annotation.Pointcut) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) Around(org.aspectj.lang.annotation.Around) HookTestStep(cucumber.api.HookTestStep) PickleStep(gherkin.pickles.PickleStep) TestCaseFinished(cucumber.api.event.TestCaseFinished) Objects(java.util.Objects) CategoriesInjector(ru.sbtqa.tag.pagefactory.allure.CategoriesInjector) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) Allure(io.qameta.allure.Allure) ReadFieldError(ru.sbtqa.tag.pagefactory.exceptions.ReadFieldError) Optional(java.util.Optional) FieldUtils.readDeclaredField(org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField) TestStep(cucumber.api.TestStep) ErrorHandler(ru.sbtqa.tag.pagefactory.allure.ErrorHandler) Collections(java.util.Collections) AllureStorage(io.qameta.allure.internal.AllureStorage) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Objects(java.util.Objects) TestResult(io.qameta.allure.model.TestResult) Map(java.util.Map) AllureStorage(io.qameta.allure.internal.AllureStorage)

Aggregations

TestResult (io.qameta.allure.model.TestResult)3 Result (cucumber.api.Result)2 TestCaseFinished (cucumber.api.event.TestCaseFinished)2 Allure (io.qameta.allure.Allure)2 Status (io.qameta.allure.model.Status)2 Arrays (java.util.Arrays)2 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)2 Around (org.aspectj.lang.annotation.Around)2 AutotestError (ru.sbtqa.tag.qautils.errors.AutotestError)2 HookTestStep (cucumber.api.HookTestStep)1 TestCase (cucumber.api.TestCase)1 TestStep (cucumber.api.TestStep)1 TestStepFinished (cucumber.api.event.TestStepFinished)1 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)1 PickleStep (gherkin.pickles.PickleStep)1 AllureStorage (io.qameta.allure.internal.AllureStorage)1 StatusDetails (io.qameta.allure.model.StatusDetails)1 StepResult (io.qameta.allure.model.StepResult)1 ResultsUtils.md5 (io.qameta.allure.util.ResultsUtils.md5)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1