private String getScenarioDefinitionText(ScenarioDefinition definition) { return definition.getKeyword() + ": " + definition.getName(); }
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 ""; }
public ExampleTableInMarkdown(Feature feature, String scenarioReport, ScenarioDefinition scenarioDefinition) { this.feature = feature; this.scenarioReport = scenarioReport; this.scenarioId = Digest.ofTextValue(scenarioDefinition.getName()); this.scenarioDefinition = scenarioDefinition; }
private String resultToken() { return "{result:" + feature.getName() + "!" + scenarioDefinition.getName() + "}"; }
public NamedScenario withName(String scenarioName) { return feature.getChildren().stream() .filter(scenarioDefinition -> scenarioDefinition.getName().equalsIgnoreCase(scenarioName.trim())) .map(scenario -> NamedScenario.forScenarioDefinition(feature, scenario)) .findFirst() .orElse(NamedScenario.withNoMatchingScenario()); } }
public String renderedFormOf(Examples exampleTable, int exampleRow, ScenarioDisplayOption displayOption) { ExampleRowResultIcon exampleRowCounter = new ExampleRowResultIcon(feature.getName(),scenarioDefinition.getName(), exampleRow); StringBuilder renderedExampleTable = new StringBuilder(); String tableName = RenderedExampleTable.nameFor(exampleTable); if (tableName.isEmpty()) { tableName = scenarioDefinition.getName(); } if (displayOption == WithTitle) { String exampleTitle = "### " + tableName; renderedExampleTable.append(exampleTitle); } renderedExampleTable.append(System.lineSeparator()); renderedExampleTable.append(RenderedExampleTable.descriptionFor(exampleTable)); renderedExampleTable.append(RenderedExampleTable.renderedTable(exampleTable, exampleRowCounter)); renderedExampleTable.append(System.lineSeparator()).append("[<i class=\"fa fa-info-circle\"></i> More details](#" + scenarioId + ")").append(System.lineSeparator()); return renderedExampleTable.toString(); } }
@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 + ""); }
protected IdentifiedScenario(Feature feature, ScenarioDefinition scenarioDefinition) { this.feature = feature; this.scenarioReport = ScenarioReport.forScenario(scenarioDefinition.getName()).inFeature(feature); this.scenarioId = Digest.ofTextValue(scenarioDefinition.getName()); this.scenarioDefinition = scenarioDefinition; this.exampleTableInMarkdown = new ExampleTableInMarkdown(feature, scenarioReport, scenarioDefinition); }
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); }
protected IdentifiedExampleTable(Feature feature, ScenarioDefinition scenarioDefinition, String exampleTableName) { this.feature = feature; this.scenarioReport = ScenarioReport.forScenario(scenarioDefinition.getName()).inFeature(feature); this.scenarioDefinition = scenarioDefinition; this.exampleTableName = exampleTableName; this.exampleTableInMarkdown = new ExampleTableInMarkdown(feature, scenarioReport, scenarioDefinition); }
private Function<CucumberFeature, List<WeightedCucumberScenario>> getScenarios() { return cucumberFeature -> { try { return (cucumberFeature.getGherkinFeature().getFeature() == null) ? Collections.emptyList() : cucumberFeature.getGherkinFeature().getFeature().getChildren() .stream() .filter(child -> asList(ScenarioOutline.class, Scenario.class).contains(child.getClass())) .map(scenarioDefinition -> new WeightedCucumberScenario( new File(cucumberFeature.getUri()).getName(), cucumberFeature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName(), scenarioWeightFor(cucumberFeature, scenarioDefinition), tagsFor(cucumberFeature, scenarioDefinition), scenarioCountFor(scenarioDefinition))) .collect(toList()); } catch (Exception e) { throw new IllegalStateException(String.format("Could not extract scenarios from %s", cucumberFeature.getUri()), e); } }; }
private Function<CucumberFeature, List<WeightedCucumberScenario>> getScenarios() { return cucumberFeature -> { try { return (cucumberFeature.getGherkinFeature().getFeature() == null) ? Collections.emptyList() : cucumberFeature.getGherkinFeature().getFeature().getChildren() .stream() .filter(child -> asList(ScenarioOutline.class, Scenario.class).contains(child.getClass())) .map(scenarioDefinition -> new WeightedCucumberScenario( new File(cucumberFeature.getUri()).getName(), cucumberFeature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName(), scenarioWeightFor(cucumberFeature, scenarioDefinition), tagsFor(cucumberFeature, scenarioDefinition), scenarioCountFor(scenarioDefinition))) .collect(toList()); } catch (Exception e) { throw new IllegalStateException(String.format("Could not extract scenarios from %s", cucumberFeature.getUri()), e); } }; }
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 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); } }; }
static Map<String, ScenarioDefinition> cacheFragmentsAsMap(List<CucumberFeature> features) { Map<String, ScenarioDefinition> fragments = new HashMap<>(); for (CucumberFeature cucumberFeature : features) { GherkinDocument gherkinDocument = cucumberFeature.getGherkinFeature(); Feature feature = gherkinDocument.getFeature(); List<ScenarioDefinition> scenarioDefinitions = feature.getChildren(); for (ScenarioDefinition scenario : scenarioDefinitions) { List<Tag> tags = new DefaultReflection().getScenarioTags(scenario); if (isFragmentTagContains(tags)) { fragments.put(scenario.getName(), scenario); } } } return fragments; }
private BigDecimal scenarioWeightFor(CucumberFeature feature, ScenarioDefinition scenarioDefinition) { return statistics.scenarioWeightFor(feature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName()); }
private BigDecimal scenarioWeightFor(CucumberFeature feature, ScenarioDefinition scenarioDefinition) { return statistics.scenarioWeightFor(feature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName()); }
String scenarioId = scenarioIdFrom(currentFeature.get().getName(), TestSourcesModel.convertToId(currentScenarioDefinition.getName())); boolean newScenario = !scenarioId.equals(currentScenario); if (newScenario) { examplesRunning = true; addingScenarioOutlineSteps = true; examples(currentFeature.get(), ((ScenarioOutline) currentScenarioDefinition).getTags(), currentScenarioDefinition.getName(), ((ScenarioOutline) currentScenarioDefinition).getExamples()); currentScenario = scenarioIdFrom(currentFeature.get().getName(), TestSourcesModel.convertToId(currentScenarioDefinition.getName())); } else { if (currentScenarioDefinition instanceof ScenarioOutline) {
private void startOfScenarioLifeCycle(Feature feature, String scenarioName, ScenarioDefinition scenario, Integer currentLine) { boolean newScenario = !scenarioIdFrom(TestSourcesModel.convertToId(feature.getName()), TestSourcesModel.convertToId(scenario.getName())).equals(currentScenario); currentScenario = scenarioIdFrom(TestSourcesModel.convertToId(feature.getName()), TestSourcesModel.convertToId(scenario.getName())); if (examplesRunning) { if (newScenario) { startScenario(feature, scenario, scenarioName); getStepEventBus(currentFeaturePath()).useExamplesFrom(table); getStepEventBus(currentFeaturePath()).useScenarioOutline(ScenarioOutlineDescription.from(scenario).getDescription()); } else { getStepEventBus(currentFeaturePath()).addNewExamplesFrom(table); } startExample(currentLine); } else { startScenario(feature, scenario, scenarioName); } }
private void startOfScenarioLifeCycle(Feature feature, String scenarioName, ScenarioDefinition scenario, Integer currentLine) { boolean newScenario = !scenarioIdFrom(TestSourcesModel.convertToId(feature.getName()), TestSourcesModel.convertToId(scenario.getName())).equals(currentScenario); currentScenario = scenarioIdFrom(TestSourcesModel.convertToId(feature.getName()), TestSourcesModel.convertToId(scenario.getName())); if (examplesRunning) { if (newScenario) { startScenario(feature, scenario, scenarioName); getStepEventBus(currentFeaturePath()).useExamplesFrom(table); getStepEventBus(currentFeaturePath()).useScenarioOutline(ScenarioOutlineDescription.from(scenario).getDescription()); } else { getStepEventBus(currentFeaturePath()).addNewExamplesFrom(table); } startExample(currentLine); } else { startScenario(feature, scenario, scenarioName); } }