cucumber.api.Result Java Examples

The following examples show how to use cucumber.api.Result. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private Status translateTestCaseStatus(final Result testCaseResult) {
    switch (testCaseResult.getStatus()) {
        case FAILED:
            return getStatus(testCaseResult.getError())
                    .orElse(Status.FAILED);
        case PASSED:
            return Status.PASSED;
        case SKIPPED:
        case PENDING:
            return Status.SKIPPED;
        case AMBIGUOUS:
        case UNDEFINED:
        default:
            return null;
    }
}
 
Example #2
Source File: AllureCucumber4Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private Status translateTestCaseStatus(final Result testCaseResult) {
    switch (testCaseResult.getStatus()) {
        case FAILED:
            return getStatus(testCaseResult.getError())
                    .orElse(Status.FAILED);
        case PASSED:
            return Status.PASSED;
        case SKIPPED:
        case PENDING:
            return Status.SKIPPED;
        case AMBIGUOUS:
        case UNDEFINED:
        default:
            return null;
    }
}
 
Example #3
Source File: AllureCucumber3Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private Status translateTestCaseStatus(final Result testCaseResult) {
    switch (testCaseResult.getStatus()) {
        case FAILED:
            return getStatus(testCaseResult.getError())
                    .orElse(Status.FAILED);
        case PASSED:
            return Status.PASSED;
        case SKIPPED:
        case PENDING:
            return Status.SKIPPED;
        case AMBIGUOUS:
        case UNDEFINED:
        default:
            return null;
    }
}
 
Example #4
Source File: CukesGHooks.java    From bdt with Apache License 2.0 6 votes vote down vote up
private void handleTestStepFinished(TestStepFinished event) {
    if (event.result.getStatus() == Result.Type.FAILED) {
        StringBuilder stepFailedText = new StringBuilder();
        stepFailedText.append("STEP FAILED!!!");
        if (StepException.INSTANCE.getException() != null) {
            stepFailedText.append(" - ").append(StepException.INSTANCE.getException().getClass().getCanonicalName());
            if (StepException.INSTANCE.getException().getMessage() != null) {
                stepFailedText.append(": ").append(StepException.INSTANCE.getException().getMessage());
            }
            try {
                StackTraceElement[] elements = StepException.INSTANCE.getException().getStackTrace();
                stepFailedText.append(" | ").append(elements[0]);
            } catch (Exception ignore) {
            }
        } else {
            StepException.INSTANCE.setException(new Exception("FAILED SCENARIO"));
        }
        logger.error(stepFailedText.toString());
    }
}
 
Example #5
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void handlePickleStep(final TestStepFinished event) {

        final Status stepStatus = translateTestCaseStatus(event.result);
        final StatusDetails statusDetails;
        if (event.result.getStatus() == Result.Type.UNDEFINED) {
            updateTestCaseStatus(Status.PASSED);

            statusDetails =
                    getStatusDetails(new PendingException("TODO: implement me"))
                            .orElse(new StatusDetails());
            lifecycle.updateTestCase(getTestCaseUuid(currentTestCase), scenarioResult ->
                    scenarioResult
                            .setStatusDetails(statusDetails));
        } else {
            statusDetails =
                    getStatusDetails(event.result.getError())
                            .orElse(new StatusDetails());
            updateTestCaseStatus(stepStatus);
        }


        if (!Status.PASSED.equals(stepStatus) && stepStatus != null) {
            forbidTestCaseStatusChange = true;
        }

        final TagParser tagParser = new TagParser(currentFeature, currentTestCase);
        statusDetails
                .setFlaky(tagParser.isFlaky())
                .setMuted(tagParser.isMuted())
                .setKnown(tagParser.isKnown());

        lifecycle.updateStep(getStepUuid(event.testStep),
                stepResult -> stepResult.setStatus(stepStatus).setStatusDetails(statusDetails));
        lifecycle.stopStep(getStepUuid(event.testStep));
    }
 
Example #6
Source File: AllureCucumber4Jvm.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void handlePickleStep(final TestStepFinished event) {

        final Status stepStatus = translateTestCaseStatus(event.result);
        final StatusDetails statusDetails;
        if (event.result.getStatus() == Result.Type.UNDEFINED) {
            updateTestCaseStatus(Status.PASSED);

            statusDetails =
                    getStatusDetails(new PendingException("TODO: implement me"))
                            .orElse(new StatusDetails());
            lifecycle.updateTestCase(getTestCaseUuid(currentTestCase.get()), scenarioResult ->
                    scenarioResult
                            .setStatusDetails(statusDetails));
        } else {
            statusDetails =
                    getStatusDetails(event.result.getError())
                            .orElse(new StatusDetails());
            updateTestCaseStatus(stepStatus);
        }

        if (!Status.PASSED.equals(stepStatus) && stepStatus != null) {
            forbidTestCaseStatusChange.set(true);
        }

        final TagParser tagParser = new TagParser(currentFeature.get(), currentTestCase.get());
        statusDetails
                .setFlaky(tagParser.isFlaky())
                .setMuted(tagParser.isMuted())
                .setKnown(tagParser.isKnown());

        lifecycle.updateStep(getStepUuid((PickleStepTestStep) event.testStep),
                stepResult -> stepResult.setStatus(stepStatus).setStatusDetails(statusDetails));
        lifecycle.stopStep(getStepUuid((PickleStepTestStep) event.testStep));
    }
 
Example #7
Source File: HookGSpec.java    From bdt with Apache License 2.0 5 votes vote down vote up
@After
public void afterScenario(Scenario scenario) throws Throwable {
    if (scenario.getStatus() == Result.Type.UNDEFINED) {
        if (!commonspec.getExceptions().isEmpty()) {
            scenario.write(commonspec.getExceptions().get(commonspec.getExceptions().size() - 1).toString());
        }
    }
}
 
Example #8
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 4 votes vote down vote up
private synchronized void updateResult(Result result) {
    switch (result.getStatus().lowerCaseName()) {
        case "failed":
            stepTestThreadLocal.get().fail(result.getError());
            break;
        case "undefined":
        	if (strict) {
        		stepTestThreadLocal.get().fail("Step undefined");
        		break;
        	}
        	stepTestThreadLocal.get().skip("Step undefined");
        	break;
        case "pending":
        case "skipped":
        	if (isHookThreadLocal.get()) {
        		ExtentService.getInstance().removeTest(stepTestThreadLocal.get());
        		break;
        	}
            Boolean currentEndingEventSkipped = stepTestThreadLocal.get().getModel().getLogContext() != null 
                && !stepTestThreadLocal.get().getModel().getLogContext().isEmpty()
                    ? stepTestThreadLocal.get().getModel().getLogContext().getLast().getStatus() == Status.SKIP
                    : false;
            if (result.getError() != null) {
                stepTestThreadLocal.get().skip(result.getError());
            } else if (!currentEndingEventSkipped) {
                String details = result.getErrorMessage() == null ? "Step skipped" : result.getErrorMessage();
                stepTestThreadLocal.get().skip(details);
            }
            break;
        case "passed":
            if (stepTestThreadLocal.get()!= null && stepTestThreadLocal.get().getModel().getLogContext().isEmpty() && !isHookThreadLocal.get()) {
        		stepTestThreadLocal.get().pass("");
            }
            if (stepTestThreadLocal.get() != null) {
             Boolean hasLog = TestService.testHasLog(stepTestThreadLocal.get().getModel());
             Boolean hasScreenCapture = hasLog && LogService.logHasScreenCapture(stepTestThreadLocal.get().getModel().getLogContext().getFirst());
             if (isHookThreadLocal.get() && !hasLog && !hasScreenCapture) {
                 ExtentService.getInstance().removeTest(stepTestThreadLocal.get());
             }
            }
            break;
        default:
            break;
    }
}
 
Example #9
Source File: AllureCucumber3Jvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private void handlePickleStep(final TestStepFinished event) {

        final Status stepStatus = translateTestCaseStatus(event.result);
        final StatusDetails statusDetails;
        if (event.result.getStatus() == Result.Type.UNDEFINED) {
            updateTestCaseStatus(Status.PASSED);

            statusDetails =
                    getStatusDetails(new PendingException("TODO: implement me"))
                            .orElse(new StatusDetails());
            lifecycle.updateTestCase(getTestCaseUuid(currentTestCase), scenarioResult ->
                    scenarioResult
                            .setStatusDetails(statusDetails));
        } else {
            statusDetails =
                    getStatusDetails(event.result.getError())
                            .orElse(new StatusDetails());
            updateTestCaseStatus(stepStatus);
        }

        if (!Status.PASSED.equals(stepStatus) && stepStatus != null) {
            forbidTestCaseStatusChange = true;
        }

        final TagParser tagParser = new TagParser(currentFeature, currentTestCase);
        statusDetails
                .setFlaky(tagParser.isFlaky())
                .setMuted(tagParser.isMuted())
                .setKnown(tagParser.isKnown());

        lifecycle.updateStep(getStepUuid((PickleStepTestStep) event.testStep),
                stepResult -> stepResult.setStatus(stepStatus).setStatusDetails(statusDetails));
        lifecycle.stopStep(getStepUuid((PickleStepTestStep) event.testStep));
    }
 
Example #10
Source File: StubScenario.java    From akita with Apache License 2.0 4 votes vote down vote up
@Override
public Result.Type getStatus() {
    return null;
}
 
Example #11
Source File: CucumberReportAdapter.java    From openCypher with Apache License 2.0 4 votes vote down vote up
private Result.Type getStatus(Either<Throwable, Either<ExecutionFailed, CypherValueRecords>> result) {
    return result.isRight() ? Result.Type.PASSED : Result.Type.FAILED;
}
 
Example #12
Source File: CucumberReporter.java    From bdt with Apache License 2.0 4 votes vote down vote up
private String calculateTotalDurationString(Result result) {
    return NUMBER_FORMAT.format(((double) result.getDuration()) / 1000000000);
}
 
Example #13
Source File: TestCaseResultListener.java    From bdt with Apache License 2.0 4 votes vote down vote up
void receiveResult(Result result) {
    this.result = result;
}
 
Example #14
Source File: TestCaseResultListener.java    From bdt with Apache License 2.0 4 votes vote down vote up
boolean isPassed() {
    return result == null || result.is(Result.Type.PASSED);
}