private StepNode processScenarioDefinition(Map<Integer, StepNode> stepMap, StepNode initialPreviousNode, ScenarioDefinition child) { StepNode previousNode = initialPreviousNode; for (Step step : child.getSteps()) { StepNode stepNode = new StepNode(step, previousNode); stepMap.put(step.getLocation().getLine(), stepNode); previousNode = stepNode; } return previousNode; }
static String calculateId(AstNode astNode) { Node node = astNode.node; if (node instanceof ScenarioDefinition) { return calculateId(astNode.parent) + ";" + convertToId(((ScenarioDefinition) node).getName()); } if (node instanceof ExamplesRowWrapperNode) { return calculateId(astNode.parent) + ";" + Integer.toString(((ExamplesRowWrapperNode) node).bodyRowIndex + 2); } if (node instanceof TableRow) { return calculateId(astNode.parent) + ";" + Integer.toString(1); } if (node instanceof Examples) { return calculateId(astNode.parent) + ";" + convertToId(((Examples) node).getName()); } if (node instanceof Feature) { return convertToId(((Feature) node).getName()); } return ""; }
private Map<String, Object> createTestCase(TestCase testCase) { Map<String, Object> testCaseMap = new HashMap<String, Object>(); testCaseMap.put("name", testCase.getName()); TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testCase.getLine()); if (astNode != null) { ScenarioDefinition scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode); testCaseMap.put("keyword", scenarioDefinition.getKeyword()); testCaseMap.put("description", scenarioDefinition.getDescription() != null ? scenarioDefinition.getDescription() : ""); } if (!testCase.getTags().isEmpty()) { List<Map<String, Object>> tagList = new ArrayList<Map<String, Object>>(); for (PickleTag tag : testCase.getTags()) { Map<String, Object> tagMap = new HashMap<String, Object>(); tagMap.put("name", tag.getName()); tagList.add(tagMap); } testCaseMap.put("tags", tagList); } return testCaseMap; }
private String getScenarioDefinitionText(ScenarioDefinition definition) { return definition.getKeyword() + ": " + definition.getName(); }
private void processScenarioDefinition(Map<Integer, AstNode> nodeMap, ScenarioDefinition child, AstNode currentParent) { AstNode childNode = new AstNode(child, currentParent); nodeMap.put(child.getLocation().getLine(), childNode); for (Step step : child.getSteps()) { nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode)); } if (child instanceof ScenarioOutline) { processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode); } }
private ScenarioOutcome scenarioOutcomeFrom(Feature feature, ScenarioDefinition scenarioDefinition, TestOutcomes testOutcomes) { List<TestOutcome> outcomes = testOutcomes.testOutcomesWithName(scenarioDefinition.getName()); String scenarioTitle = scenarioDefinition.getName(); TestResult result = (outcomes.isEmpty()) ? TestResult.UNDEFINED : TestResultList.overallResultFrom(outcomes.stream().map(TestOutcome::getResult).collect(Collectors.toList())); List<String> reportBadges = ReportBadges.from(outcomes, scenarioDefinition.getName()); String featureReport = new ReportNameProvider().forRequirement(feature.getName(),"feature"); List<String> renderedSteps = scenarioDefinition.getSteps().stream() .map(RenderCucumber::step) .collect(Collectors.toList()); List<String> renderedExamples = (scenarioDefinition instanceof ScenarioOutline) ? RenderCucumber.examples(((ScenarioOutline) scenarioDefinition).getExamples(), feature.getName(), scenarioDefinition.getName()) : Collections.EMPTY_LIST; int exampleCount = (scenarioDefinition instanceof ScenarioOutline) ? ((ScenarioOutline) scenarioDefinition).getExamples().stream().mapToInt(examples -> examples.getTableBody().size()).sum() : 0; return new ScenarioSummaryOutcome(scenarioTitle, scenarioDefinition.getKeyword(), result, reportBadges, scenarioDefinition.getDescription(), renderedSteps, renderedExamples, exampleCount, feature.getName(), featureReport); }
@Override public Optional<String> asGivenWhenThen(ScenarioDisplayOption displayOption) { String renderedDescription = ""; String suffix = ""; if (displayOption == WithTitle) { renderedDescription = "**" + scenarioDefinition.getName() + "** " + resultToken() + lineSeparator(); } else { suffix = resultToken(); } renderedDescription += scenarioDefinition.getSteps().stream() .map(step -> RenderCucumber.step(step) + " ") .collect(Collectors.joining(lineSeparator())) + suffix; renderedDescription += System.lineSeparator() + "[<i class=\"fa fa-info-circle\"></i> More details](#" + scenarioId + ")" + System.lineSeparator(); return Optional.of("" + renderedDescription + ""); }
String name = scenarioDefinition.getName(); String description = scenarioDefinition.getDescription(); List<Step> steps = new ArrayList<>(); List<String> tags = new ArrayList<>(); steps.addAll(background.getSteps()); steps.addAll(scenarioDefinition.getSteps());
private Function<ScenarioDefinition, TestScenarioResult> scenarioToResult(CucumberFeature feature) { return scenarioDefinition -> { try { return new TestScenarioResult( feature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName(), scenarioStepCountFor(backgroundStepCountFor(feature), scenarioDefinition)); } catch (Exception e) { throw new IllegalStateException(String.format("Could not determine step count for scenario '%s'", scenarioDefinition.getDescription()), e); } }; }
String scenarioName = scenarioDefinition.getKeyword() + ": " + scenarioDefinition.getName(); String scenarioDescription = scenarioDefinition.getDescription();
private void updateManualResultsFrom(List<Tag> scenarioTags) { getStepEventBus(currentFeaturePath()).testIsManual(); manualResultDefinedIn(scenarioTags).ifPresent( result -> { if (result == TestResult.FAILURE) { String failureMessage = failureMessageFrom(currentScenarioDefinition.getDescription()).orElse("Failed manual test"); getStepEventBus(currentFeaturePath()).getBaseStepListener() .latestTestOutcome().ifPresent( outcome -> outcome.setTestFailureMessage(failureMessage)); } getStepEventBus(currentFeaturePath()).getBaseStepListener().overrideResultTo(result); } ); }
private ScenarioDefinition findScenarioDefinitionViaLocation(Location location, GherkinDocument gherkinDocument) { List<ScenarioDefinition> scenarioDefinitions = gherkinDocument.getFeature().getChildren(); for (ScenarioDefinition definition : scenarioDefinitions) { if (isLocationSame(definition.getLocation(), location)) { return definition; } } return null; }
private void processScenarioDefinition( final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child, final AstNode currentParent ) { final AstNode childNode = new AstNode(child, currentParent); nodeMap.put(child.getLocation().getLine(), childNode); child.getSteps().forEach( step -> nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode)) ); if (child instanceof ScenarioOutline) { processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode); } }
private void replaceFragmentInScenario(ScenarioDefinition scenario, ScenarioDefinition fragment) throws IllegalAccessException { String language = scenarioLanguageMap.get(scenario); List<Step> replacementSteps = new ArrayList<>(); for (Step step : scenario.getSteps()) { if (FragmentUtils.isStepFragmentRequire(step, language) && FragmentUtils.getFragmentName(step, language).equals(fragment.getName())) { replacementSteps.addAll(replaceStepWithFragment(step, fragment)); } else { replacementSteps.add(step); } } FieldUtils.writeField(scenario, "steps", replacementSteps, true); }
private Function<ScenarioDefinition, TestScenarioResult> scenarioToResult(CucumberFeature feature) { return scenarioDefinition -> { try { return new TestScenarioResult( feature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName(), scenarioStepCountFor(backgroundStepCountFor(feature), scenarioDefinition)); } catch (Exception e) { throw new IllegalStateException(String.format("Could not determine step count for scenario '%s'", scenarioDefinition.getDescription()), e); } }; }
private void updateManualResultsFrom(List<Tag> scenarioTags) { getStepEventBus(currentFeaturePath()).testIsManual(); manualResultDefinedIn(scenarioTags).ifPresent( result -> { if (result == TestResult.FAILURE) { String failureMessage = failureMessageFrom(currentScenarioDefinition.getDescription()).orElse("Failed manual test"); getStepEventBus(currentFeaturePath()).getBaseStepListener() .latestTestOutcome().ifPresent( outcome -> outcome.setTestFailureMessage(failureMessage)); } getStepEventBus(currentFeaturePath()).getBaseStepListener().overrideResultTo(result); } ); }
private ScenarioDefinition findScenarioDefinitionViaLocation(Location location, GherkinDocument gherkinDocument) { List<ScenarioDefinition> scenarioDefinitions = gherkinDocument.getFeature().getChildren(); for (ScenarioDefinition definition : scenarioDefinitions) { if (isLocationSame(definition.getLocation(), location)) { return definition; } } return null; }
public String getDescription() { return scenario.getSteps().stream().map( step -> stepToString(step) ).collect(Collectors.joining(System.lineSeparator())); }
public ExampleTableInMarkdown(Feature feature, String scenarioReport, ScenarioDefinition scenarioDefinition) { this.feature = feature; this.scenarioReport = scenarioReport; this.scenarioId = Digest.ofTextValue(scenarioDefinition.getName()); this.scenarioDefinition = scenarioDefinition; }
private void processScenarioDefinition( final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child, final AstNode currentParent ) { final AstNode childNode = new AstNode(child, currentParent); nodeMap.put(child.getLocation().getLine(), childNode); child.getSteps().forEach( step -> nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode)) ); if (child instanceof ScenarioOutline) { processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode); } }