private Step convert(final Path source, final ResultsVisitor visitor, final StepResult step) { final Step result = new Step() .setName(step.getName()) .setStatus(convert(step.getStatus())) .setTime(convert(step.getStart(), step.getStop())) .setParameters(convert(step.getParameters(), this::convert)) .setAttachments(convert(step.getAttachments(), attachment -> convert(source, visitor, attachment))) .setSteps(convert(step.getSteps(), s -> convert(source, visitor, s))); Optional.of(step) .map(ExecutableItem::getStatusDetails) .ifPresent(statusDetails -> { result.setStatusMessage(statusDetails.getMessage()); result.setStatusTrace(statusDetails.getTrace()); }); return result; }
protected void fireCanceledStep(final Step unimplementedStep) { final StepResult stepResult = new StepResult(); stepResult.setName(unimplementedStep.getName()) .setStart(System.currentTimeMillis()) .setStop(System.currentTimeMillis()) .setStatus(Status.SKIPPED) .setStatusDetails(new StatusDetails().setMessage("Unimplemented step")); lifecycle.startStep(scenario.getId(), getStepUuid(unimplementedStep), stepResult); lifecycle.stopStep(getStepUuid(unimplementedStep)); final StatusDetails statusDetails = new StatusDetails(); final TagParser tagParser = new TagParser(feature, scenario); statusDetails .setFlaky(tagParser.isFlaky()) .setMuted(tagParser.isMuted()) .setKnown(tagParser.isKnown()); lifecycle.updateTestCase(scenario.getId(), scenarioResult -> scenarioResult.setStatus(Status.SKIPPED) .setStatusDetails(statusDetails .setMessage("Unimplemented steps were found"))); }
@Override public void onEvent(final LogEvent event) { lifecycle.getCurrentTestCase().ifPresent(uuid -> { final String stepUUID = UUID.randomUUID().toString(); lifecycle.startStep(stepUUID, new StepResult() .setName(event.toString()) .setStatus(Status.PASSED)); lifecycle.updateStep(stepResult -> stepResult.setStart(stepResult.getStart() - event.getDuration())); if (LogEvent.EventStatus.FAIL.equals(event.getStatus())) { if (saveScreenshots) { lifecycle.addAttachment("Screenshot", "image/png", "png", getScreenshotBytes()); } if (savePageHtml) { lifecycle.addAttachment("Page source", "text/html", "html", getPageSourceBytes()); } lifecycle.updateStep(stepResult -> { final StatusDetails details = ResultsUtils.getStatusDetails(event.getError()) .orElse(new StatusDetails()); stepResult.setStatus(ResultsUtils.getStatus(event.getError()).orElse(Status.BROKEN)); stepResult.setStatusDetails(details); }); } lifecycle.stopStep(stepUUID); }); }
private void handleTestStepStarted(final TestStepStarted event) { if (event.testStep instanceof PickleStepTestStep) { final PickleStepTestStep pickleStepTestStep = (PickleStepTestStep) event.testStep; final String stepKeyword = Optional.ofNullable( cucumberSourceUtils.getKeywordFromSource(currentFeatureFile, pickleStepTestStep.getStepLine()) ).orElse("UNDEFINED"); final StepResult stepResult = new StepResult() .setName(String.format("%s %s", stepKeyword, pickleStepTestStep.getPickleStep().getText())) .setStart(System.currentTimeMillis()); lifecycle.startStep(getTestCaseUuid(currentTestCase), getStepUuid(event.testStep), stepResult); pickleStepTestStep.getStepArgument().stream() .filter(PickleTable.class::isInstance) .findFirst() .ifPresent(table -> createDataTableAttachment((PickleTable) table)); } else if (event.testStep instanceof HookTestStep) { final HookTestStep hookTestStep = (HookTestStep) event.testStep; final StepResult stepResult = new StepResult() .setName(hookTestStep.getHookType().toString()) .setStart(System.currentTimeMillis()); lifecycle.startStep(getTestCaseUuid(currentTestCase), getHookStepUuid(event.testStep), stepResult); } else { throw new IllegalStateException(); } }
/** * Run provided {@link ThrowableRunnable} as step with given name. Takes no effect * if no test run at the moment. * * @param runnable the step's body. */ public static <T> T step(final ThrowableContextRunnable<T, StepContext> runnable) { final String uuid = UUID.randomUUID().toString(); getLifecycle().startStep(uuid, new StepResult().setName("step")); try { final T result = runnable.run(new DefaultStepContext(uuid)); getLifecycle().updateStep(uuid, step -> step.setStatus(Status.PASSED)); return result; } catch (Throwable throwable) { getLifecycle().updateStep(s -> s .setStatus(getStatus(throwable).orElse(Status.BROKEN)) .setStatusDetails(getStatusDetails(throwable).orElse(null))); ExceptionUtils.sneakyThrow(throwable); return null; } finally { getLifecycle().stopStep(uuid); } }
/** * Adds step with provided name and status in current test or step (or test fixture). Takes no effect * if no test run at the moment. * * @param name the name of step. * @param status the step status. */ public static void step(final String name, final Status status) { final String uuid = UUID.randomUUID().toString(); getLifecycle().startStep(uuid, new StepResult().setName(name).setStatus(status)); getLifecycle().stopStep(uuid); }
@AfterThrowing(pointcut = "anyMethod() && withStepAnnotation()", throwing = "e") public void stepFailed(final Throwable e) { getLifecycle().updateStep(s -> s .setStatus(getStatus(e).orElse(Status.BROKEN)) .setStatusDetails(getStatusDetails(e).orElse(null))); getLifecycle().stopStep(); }
@Before("anyMethod() && withStepAnnotation()") public void stepStart(final JoinPoint joinPoint) { final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); final Step step = methodSignature.getMethod().getAnnotation(Step.class); final String uuid = UUID.randomUUID().toString(); final String name = getName(step.value(), methodSignature, joinPoint.getArgs()); final List<Parameter> parameters = getParameters(methodSignature, joinPoint.getArgs()); final StepResult result = new StepResult() .setName(name) .setParameters(parameters); getLifecycle().startStep(uuid, result); }
public static void stepStart(String stepName) { StepResult result = new StepResult().setName(stepName); String uuid = UUID.randomUUID().toString(); getLifecycle().startStep(uuid, result); STEP_UUID_STACK.get().addFirst(uuid); }
@Override public StepResult withStatus(Status value) { setStatus(value); return this; }
private static void writeToAllure(String message) { if (!writeToAllure) return; final String uuid = UUID.randomUUID().toString(); StepResult step = new StepResult().withName(message).withStatus(PASSED); getLifecycle().startStep(uuid, step); getLifecycle().stopStep(uuid); }
public static StepResult randomStepResult() throws IOException { return new StepResult() .withName(randomStepResultName()); }
@Override public StepResult withName(String value) { setName(value); return this; }
/** * Create an instance of {@link StepResult } * */ public StepResult createStepResult() { return new StepResult(); }
/** * Start a new step as child of specified parent. * * @param parentUuid the uuid of parent test case or step. * @param uuid the uuid of step. * @param result the step. */ public void startStep(final String parentUuid, final String uuid, final StepResult result) { notifier.beforeStepStart(result); result.setStage(Stage.RUNNING); result.setStart(System.currentTimeMillis()); threadContext.start(uuid); storage.put(uuid, result); storage.get(parentUuid, WithSteps.class).ifPresent(parentStep -> { synchronized (storage) { parentStep.getSteps().add(result); } }); notifier.afterStepStart(result); }
@Override public StepResult withStart(Long value) { setStart(value); return this; }
@Override public StepResult withStatusDetails(StatusDetails value) { setStatusDetails(value); return this; }
/** * Stops step by given uuid. * * @param uuid the uuid of step to stop. */ public void stopStep(final String uuid) { final Optional<StepResult> found = storage.getStep(uuid); if (!found.isPresent()) { LOGGER.error("Could not stop step: step with uuid {} not found", uuid); return; } final StepResult step = found.get(); notifier.beforeStepStop(step); step.setStage(Stage.FINISHED); step.setStop(System.currentTimeMillis()); storage.remove(uuid); threadContext.stop(); notifier.afterStepStop(step); }
@Override public StepResult withParameters(Parameter... values) { if (values!= null) { for (Parameter value: values) { getParameters().add(value); } } return this; }
@Override public StepResult withStop(Long value) { setStop(value); return this; }