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 void parseGherkinSource(String path) { if (!pathToReadEventMap.containsKey(path)) { return; } Parser<GherkinDocument> parser = new Parser<GherkinDocument>(new AstBuilder()); TokenMatcher matcher = new TokenMatcher(); try { GherkinDocument gherkinDocument = parser.parse(pathToReadEventMap.get(path).source, matcher); pathToAstMap.put(path, gherkinDocument); Map<Integer, AstNode> nodeMap = new HashMap<Integer, AstNode>(); AstNode currentParent = new AstNode(gherkinDocument.getFeature(), null); for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) { processScenarioDefinition(nodeMap, child, currentParent); } pathToNodeMap.put(path, nodeMap); } catch (ParserException e) { // Ignore exceptions } }
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 } }
private List<ScenarioDefinition> backgrounds(Feature feature) { List<ScenarioDefinition> result = new ArrayList<>(); for (ScenarioDefinition scenario : feature.getChildren()) { if (gherkin.ast.Background.class.isInstance(scenario)) { result.add(scenario); } } return result; }
private boolean featureContainsExampleTableWithName(String exampleTableName) { return feature.getChildren().stream() .anyMatch( scenarioDefinition -> scenarioContainsExampleTableWithName(scenarioDefinition, exampleTableName) ); }
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 NamedExampleTable withName(String exampleTableName) { return feature.getChildren().stream() .filter(scenarioDefinition -> featureContainsExampleTableWithName(exampleTableName)) .map(scenarioDefinition -> NamedExampleTable.forScenarioDefinition(feature, scenarioDefinition, exampleTableName)) .findFirst() .orElse(NamedExampleTable.withNoMatchingScenario()); }
private Function<CucumberFeature, List<TestScenarioResult>> featureToScenarios() { 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(scenarioToResult(cucumberFeature)) .collect(toList()); } catch (Exception e) { throw new IllegalStateException(String.format("Could not extract scenarios from %s", cucumberFeature.getUri()), e); } }; }
private Function<CucumberFeature, List<TestScenarioResult>> featureToScenarios() { 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(scenarioToResult(cucumberFeature)) .collect(toList()); } catch (Exception e) { throw new IllegalStateException(String.format("Could not extract scenarios from %s", cucumberFeature.getUri()), e); } }; }
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; } }
static Map<ScenarioDefinition, String> cacheScenarioLanguage(List<CucumberFeature> features) { Map<ScenarioDefinition, String> scenarioLanguageMap = new HashMap<>(); for (CucumberFeature cucumberFeature : features) { GherkinDocument gherkinDocument = cucumberFeature.getGherkinFeature(); Feature feature = gherkinDocument.getFeature(); List<ScenarioDefinition> scenarios = feature.getChildren(); for (ScenarioDefinition scenario : scenarios) { scenarioLanguageMap.put(scenario, feature.getLanguage()); } } return scenarioLanguageMap; } }
public List<ScenarioOutcome> forOutcomesIn(RequirementsOutcomes requirementsOutcomes) { CucumberParser parser = new CucumberParser(); Optional<Feature> feature = parser.loadFeature(pathFromResourceOnClasspath(requirement.getPath())); if (!feature.isPresent()) { return Collections.emptyList(); } else { List<ScenarioOutcome> scenarioOutcomes = new ArrayList<>(); feature.get().getChildren().forEach( scenarioDefinition -> scenarioOutcomes.add( scenarioOutcomeFrom(feature.get(), scenarioDefinition, requirementsOutcomes.getTestOutcomes())) ); return scenarioOutcomes; } }
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 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 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); } }; }
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 Feature featureWithDefaultName(Feature feature, String defaultName) { return new Feature(feature.getTags(), feature.getLocation(), feature.getLanguage(), feature.getKeyword(), defaultName, feature.getDescription(), feature.getChildren()); }
private Feature featureWithDefaultName(Feature feature, String defaultName) { return new Feature(feature.getTags(), feature.getLocation(), feature.getLanguage(), feature.getKeyword(), defaultName, feature.getDescription(), feature.getChildren()); }