static Background getBackgroundForTestCase(AstNode astNode) { Feature feature = getFeatureForTestCase(astNode); ScenarioDefinition backgound = feature.getChildren().get(0); if (backgound instanceof Background) { return (Background) backgound; } else { return null; } }
private Map<String, Object> createFeature(TestCase testCase) { Map<String, Object> featureMap = new HashMap<String, Object>(); Feature feature = testSources.getFeature(testCase.getUri()); if (feature != null) { featureMap.put("keyword", feature.getKeyword()); featureMap.put("name", feature.getName()); featureMap.put("description", feature.getDescription() != null ? feature.getDescription() : ""); if (!feature.getTags().isEmpty()) { featureMap.put("tags", createTagList(feature.getTags())); } } return featureMap; }
private void createFeatureStepMap(String path) { if (!pathToSourceMap.containsKey(path)) { return; } Parser<GherkinDocument> parser = new Parser<GherkinDocument>(new AstBuilder()); TokenMatcher matcher = new TokenMatcher(); try { GherkinDocument gherkinDocument = parser.parse(pathToSourceMap.get(path), matcher); Map<Integer, StepNode> stepMap = new HashMap<Integer, StepNode>(); StepNode initialPreviousNode = null; for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) { StepNode lastStepNode = processScenarioDefinition(stepMap, initialPreviousNode, child); if (child instanceof Background) { initialPreviousNode = lastStepNode; } } pathToStepMap.put(path, new FeatureStepMap(new GherkinDialectProvider(gherkinDocument.getFeature().getLanguage()).getDefaultDialect(), stepMap)); } catch (ParserException e) { // Ignore exceptions } }
@Override public String getName() { Feature feature = cucumberFeature.getGherkinFeature().getFeature(); return feature.getKeyword() + ": " + feature.getName(); }
private Feature featureWithDefaultName(Feature feature, String defaultName) { return new Feature(feature.getTags(), feature.getLocation(), feature.getLanguage(), feature.getKeyword(), defaultName, feature.getDescription(), feature.getChildren()); }
String getFeatureName(String uri) { Feature feature = getFeature(uri); if (feature != null) { return feature.getName(); } return ""; }
String featureName = feature.getKeyword() + ": " + feature.getName(); String featureLanguage = feature.getLanguage(); String featureDescription = feature.getDescription(); List<String> featureTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(feature.getTags()); List<ScenarioDefinition> scenarioDefinitions = feature.getChildren(); for (ScenarioDefinition scenarioDefinition : scenarioDefinitions) { String scenarioName = scenarioDefinition.getKeyword() + ": " + scenarioDefinition.getName();
public Optional<Narrative> loadFeatureNarrative(File narrativeFile) { Optional<Feature> loadedFeature = loadFeature(narrativeFile); if (!loadedFeature.isPresent()) { return Optional.empty(); } Feature feature = loadedFeature.get(); String cardNumber = findCardNumberInTags(tagsDefinedIn(feature)); List<String> versionNumbers = findVersionNumberInTags(tagsDefinedIn(feature)); String title = feature.getName(); String text = descriptionWithScenarioReferencesFrom(feature); String id = getIdFromName(title); List<TestTag> tags = feature.getTags().stream().map(tag -> TestTag.withValue(tag.getName())).collect(Collectors.toList()); tags.add(TestTag.withName(title).andType("feature")); return Optional.of(new Narrative(Optional.ofNullable(title), Optional.ofNullable(id), Optional.ofNullable(cardNumber), versionNumbers, "feature", text != null ? text : "", tags)); }
public List<Pickle> compile(GherkinDocument gherkinDocument) { List<Pickle> pickles = new ArrayList<>(); Feature feature = gherkinDocument.getFeature(); if (feature == null) { return pickles; } List<Tag> featureTags = feature.getTags(); List<PickleStep> backgroundSteps = new ArrayList<>(); for (ScenarioDefinition scenarioDefinition : feature.getChildren()) { if (scenarioDefinition instanceof Background) { backgroundSteps = pickleSteps(scenarioDefinition); } else if (scenarioDefinition instanceof Scenario) { compileScenario(pickles, backgroundSteps, (Scenario) scenarioDefinition, featureTags); } else { compileScenarioOutline(pickles, backgroundSteps, (ScenarioOutline) scenarioDefinition, featureTags); } } return pickles; }
private Story userStoryFrom(Feature feature, String featureFileUri) { Story userStory = Story.withIdAndPath(TestSourcesModel.convertToId(feature.getName()), feature.getName(), featureFileUri).asFeature(); if (!isEmpty(feature.getDescription())) { userStory = userStory.withNarrative(feature.getDescription()); } return userStory; }
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 List<Tag> tagsDefinedIn(Feature feature) { return feature.getTags(); }
String getKeywordFromSource(String uri, int stepLine) { Feature feature = getFeature(uri); if (feature != null) { TestSourceRead event = getTestSourceReadEvent(uri); String trimmedSourceLine = event.source.split("\n")[stepLine - 1].trim(); GherkinDialect dialect = new GherkinDialectProvider(feature.getLanguage()).getDefaultDialect(); for (String keyword : dialect.getStepKeywords()) { if (trimmedSourceLine.startsWith(keyword)) { return keyword; } } } return ""; }
private String descriptionWithScenarioReferencesFrom(Feature feature) { if (feature.getDescription() == null) { return ""; } return stream(feature.getDescription().split("\\r?\\n")) .map(line -> DescriptionWithScenarioReferences.from(feature).forText(line)) .collect(Collectors.joining(lineSeparator())); }
String language = featureLine.matchedGherkinDialect.getLanguage(); return new Feature(tags, getLocation(featureLine, 0), language, featureLine.matchedKeyword, featureLine.matchedText, description, scenarioDefinitions);
private Feature featureWithDefaultName(Feature feature, String defaultName) { return new Feature(feature.getTags(), feature.getLocation(), feature.getLanguage(), feature.getKeyword(), defaultName, feature.getDescription(), feature.getChildren()); }
public String getName() { return gherkinDocument.getFeature().getName(); }
private void examples(Feature currentFeature, List<Tag> scenarioOutlineTags, String id, List<Examples> examplesList) { String featureName = currentFeature.getName(); List<Tag> currentFeatureTags = currentFeature.getTags(); addingScenarioOutlineSteps = false; initializeExamples(); for (Examples examples : examplesList) { if (examplesAreNotExcludedByTags(examples, scenarioOutlineTags, currentFeatureTags) && examplesAreNotExcludedByLinesFilter(examples)) { List<TableRow> examplesTableRows = examples.getTableBody().stream().filter( tableRow -> tableRowIsNotExcludedByLinesFilter(tableRow)).collect(Collectors.toList()); List<String> headers = getHeadersFrom(examples.getTableHeader()); List<Map<String, String>> rows = getValuesFrom(examplesTableRows, headers); for (int i = 0; i < examplesTableRows.size(); i++) { addRow(exampleRows(), headers, examplesTableRows.get(i)); if (examples.getTags() != null) { exampleTags().put(examplesTableRows.get(i).getLocation().getLine(), examples.getTags()); } } String scenarioId = scenarioIdFrom(featureName, id); boolean newScenario = !scenarioId.equals(currentScenarioId); table = (newScenario) ? thucydidesTableFrom(SCENARIO_OUTLINE_NOT_KNOWN_YET, headers, rows, trim(examples.getName()), trim(examples.getDescription())) : addTableRowsTo(table, headers, rows, trim(examples.getName()), trim(examples.getDescription())); table.addTagsToLatestDataSet(examples.getTags().stream().map(tag -> TestTag.withValue(tag.getName().substring(1))).collect(Collectors.toList())); exampleCount = table.getSize(); currentScenarioId = scenarioId; } } }
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); } } } }
private Story userStoryFrom(Feature feature, String featureFileUri) { Story userStory = Story.withIdAndPath(TestSourcesModel.convertToId(feature.getName()), feature.getName(), featureFileUri).asFeature(); if (!isEmpty(feature.getDescription())) { userStory = userStory.withNarrative(feature.getDescription()); } return userStory; }