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; }
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 List<PickleStep> pickleSteps(ScenarioDefinition scenarioDefinition) { List<PickleStep> result = new ArrayList<>(); for (Step step : scenarioDefinition.getSteps()) { result.add(pickleStep(step)); } return unmodifiableList(result); }
public String getDescription() { return scenario.getSteps().stream().map( step -> stepToString(step) ).collect(Collectors.joining(System.lineSeparator())); }
public String getDescription() { return scenario.getSteps().stream().map( step -> stepToString(step) ).collect(Collectors.joining(System.lineSeparator())); }
private BigDecimal scenarioStepCountFor(int backgroundStepCount, ScenarioDefinition scenarioDefinition) { final int stepCount; if (scenarioDefinition instanceof ScenarioOutline) { ScenarioOutline outline = (ScenarioOutline) scenarioDefinition; Integer exampleCount = outline.getExamples().stream().map(examples -> examples.getTableBody().size()).mapToInt(Integer::intValue).sum(); stepCount = exampleCount * (backgroundStepCount + outline.getSteps().size()); } else { stepCount = backgroundStepCount + scenarioDefinition.getSteps().size(); } return BigDecimal.valueOf(stepCount); }
private BigDecimal scenarioStepCountFor(int backgroundStepCount, ScenarioDefinition scenarioDefinition) { final int stepCount; if (scenarioDefinition instanceof ScenarioOutline) { ScenarioOutline outline = (ScenarioOutline) scenarioDefinition; Integer exampleCount = outline.getExamples().stream().map(examples -> examples.getTableBody().size()).mapToInt(Integer::intValue).sum(); stepCount = exampleCount * (backgroundStepCount + outline.getSteps().size()); } else { stepCount = backgroundStepCount + scenarioDefinition.getSteps().size(); } return BigDecimal.valueOf(stepCount); }
private void setTableScenarioOutline() { List<Step> steps = currentScenarioDefinition.getSteps(); StringBuffer scenarioOutlineBuffer = new StringBuffer(); for (Step step : steps) { scenarioOutlineBuffer.append(step.getKeyword()).append(step.getText()).append("\n\r"); } String scenarioOutline = scenarioOutlineBuffer.toString(); if (table != null) { table.setScenarioOutline(scenarioOutline); } }
private void setTableScenarioOutline() { List<Step> steps = currentScenarioDefinition.getSteps(); StringBuffer scenarioOutlineBuffer = new StringBuffer(); for (Step step : steps) { scenarioOutlineBuffer.append(step.getKeyword()).append(step.getText()).append("\n\r"); } String scenarioOutline = scenarioOutlineBuffer.toString(); if (table != null) { table.setScenarioOutline(scenarioOutline); } }
@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 + ""); }
private List<Step> replaceStepWithFragment(Step stepToReplace, ScenarioDefinition fragment) { List<Step> replacementSteps = fragment.getSteps(); StepReplacer stepReplacer = new StepReplacer(stepToReplace); return stepReplacer.replaceWith(replacementSteps); } }
private int backgroundStepCountFor(CucumberFeature feature) { ScenarioDefinition scenarioDefinition = feature.getGherkinFeature().getFeature().getChildren().get(0); if (scenarioDefinition instanceof Background) { return scenarioDefinition.getSteps().size(); } else { return 0; } }
private int backgroundStepCountFor(CucumberFeature feature) { ScenarioDefinition scenarioDefinition = feature.getGherkinFeature().getFeature().getChildren().get(0); if (scenarioDefinition instanceof Background) { return scenarioDefinition.getSteps().size(); } else { return 0; } }
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 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 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 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); }
static MutableGraph<Object> cacheFragmentsAsGraph(List<CucumberFeature> features, Map<String, ScenarioDefinition> fragmentsMap, Map<ScenarioDefinition, String> scenarioLanguageMap) throws FragmentException { MutableGraph<Object> graph = GraphBuilder.directed().allowsSelfLoops(false).build(); for (CucumberFeature cucumberFeature : features) { GherkinDocument gherkinDocument = cucumberFeature.getGherkinFeature(); Feature feature = gherkinDocument.getFeature(); List<ScenarioDefinition> scenarioDefinitions = feature.getChildren(); for (ScenarioDefinition scenario : scenarioDefinitions) { graph.addNode(scenario); List<Step> steps = scenario.getSteps(); for (Step step : steps) { String language = scenarioLanguageMap.get(scenario); if (FragmentUtils.isStepFragmentRequire(step, language)) { String scenarioName = FragmentUtils.getFragmentName(step, language); ScenarioDefinition scenarioAsFragment = fragmentsMap.get(scenarioName); if (scenarioAsFragment == null) { throw new FragmentException(String.format("There is no scenario (fragment) with name \"%s\"", scenarioName)); } graph.putEdge(scenario, scenarioAsFragment); } } } } if (Graphs.hasCycle(graph)) { LOG.error("Fragments graph contains cycles"); } return graph; }
public void replaceDataPlaceholders(List<CucumberFeature> cucumberFeatures) throws DataException, IllegalAccessException { for (CucumberFeature cucumberFeature : cucumberFeatures) { featureDataTagValue = "$" + Props.get("data.initial.collection"); GherkinDocument gherkinDocument = cucumberFeature.getGherkinFeature(); Feature feature = gherkinDocument.getFeature(); setFeatureDataTag(parseTags(feature.getTags())); List<ScenarioDefinition> featureChildren = feature.getChildren(); for (ScenarioDefinition scenarioDefinition : featureChildren) { List<Tag> currentScenarioTags = getScenarioTags(scenarioDefinition); setCurrentScenarioTag(parseTags(currentScenarioTags)); List<Step> steps = scenarioDefinition.getSteps(); if (scenarioDefinition instanceof ScenarioOutline) { List<Examples> examples = ((ScenarioOutline) scenarioDefinition).getExamples(); FieldUtils.writeField(scenarioDefinition, "examples", replaceExamplesPlaceholders(examples), true); } for (Step step : steps) { FieldUtils.writeField(step, "argument", replaceArgumentPlaceholders(step.getArgument()), true); FieldUtils.writeField(step, "text", replaceDataPlaceholders(step.getText()), true); } } } }
public void replaceDataPlaceholders(List<CucumberFeature> cucumberFeatures) throws DataException, IllegalAccessException { for (CucumberFeature cucumberFeature : cucumberFeatures) { featureDataTagValue = "$" + Props.get("data.initial.collection"); GherkinDocument gherkinDocument = cucumberFeature.getGherkinFeature(); Feature feature = gherkinDocument.getFeature(); if (feature == null) { continue; } setFeatureDataTag(parseTags(feature.getTags())); List<ScenarioDefinition> featureChildren = feature.getChildren(); for (ScenarioDefinition scenarioDefinition : featureChildren) { List<Tag> currentScenarioTags = getScenarioTags(scenarioDefinition); setCurrentScenarioTag(parseTags(currentScenarioTags)); List<Step> steps = scenarioDefinition.getSteps(); if (scenarioDefinition instanceof ScenarioOutline) { List<Examples> examples = ((ScenarioOutline) scenarioDefinition).getExamples(); FieldUtils.writeField(scenarioDefinition, "examples", replaceExamplesPlaceholders(examples), true); } for (Step step : steps) { FieldUtils.writeField(step, "argument", replaceArgumentPlaceholders(step.getArgument()), true); FieldUtils.writeField(step, "text", replaceDataPlaceholders(step.getText()), true); } } } }