use of gherkin.ast.ScenarioDefinition in project cucable-plugin by trivago.
the class GherkinDocumentParser method getSingleScenariosFromFeature.
/**
* Returns a {@link com.trivago.rta.vo.SingleScenario} list from a given feature file.
*
* @param featureContent A feature string.
* @param featureFilePath The path to the source feature file.
* @param scenarioLineNumbers An optional line number of a scenario inside a feature file.
* @param includeScenarioTags Optional scenario tags to include into scenario generation.
* @param excludeScenarioTags Optional scenario tags to exclude from scenario generation.
* @return A {@link com.trivago.rta.vo.SingleScenario} list.
* @throws CucablePluginException see {@link CucablePluginException}.
*/
public List<SingleScenario> getSingleScenariosFromFeature(final String featureContent, final String featureFilePath, final List<Integer> scenarioLineNumbers, final List<String> includeScenarioTags, final List<String> excludeScenarioTags) throws CucablePluginException {
GherkinDocument gherkinDocument = getGherkinDocumentFromFeatureFileContent(featureContent);
Feature feature = gherkinDocument.getFeature();
String featureName = feature.getKeyword() + ": " + feature.getName();
String featureLanguage = feature.getLanguage();
String featureDescription = feature.getDescription();
List<String> featureTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(feature.getTags());
ArrayList<SingleScenario> singleScenarioFeatures = new ArrayList<>();
List<Step> backgroundSteps = new ArrayList<>();
List<ScenarioDefinition> scenarioDefinitions = feature.getChildren();
for (ScenarioDefinition scenarioDefinition : scenarioDefinitions) {
String scenarioName = scenarioDefinition.getKeyword() + ": " + scenarioDefinition.getName();
String scenarioDescription = scenarioDefinition.getDescription();
if (scenarioDefinition instanceof Background) {
// Save background steps in order to add them to every scenario inside the same feature
Background background = (Background) scenarioDefinition;
backgroundSteps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(background.getSteps());
continue;
}
if (scenarioDefinition instanceof Scenario) {
Scenario scenario = (Scenario) scenarioDefinition;
if (scenarioLineNumbers == null || scenarioLineNumbers.isEmpty() || scenarioLineNumbers.contains(scenario.getLocation().getLine())) {
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, backgroundSteps);
addGherkinScenarioInformationToSingleScenario(scenario, singleScenario);
if (scenarioShouldBeIncluded(singleScenario.getScenarioTags(), singleScenario.getFeatureTags(), includeScenarioTags, excludeScenarioTags)) {
singleScenarioFeatures.add(singleScenario);
}
}
continue;
}
if (scenarioDefinition instanceof ScenarioOutline) {
ScenarioOutline scenarioOutline = (ScenarioOutline) scenarioDefinition;
if (scenarioLineNumbers == null || scenarioLineNumbers.isEmpty() || scenarioLineNumbers.contains(scenarioOutline.getLocation().getLine())) {
List<SingleScenario> outlineScenarios = getSingleScenariosFromOutline(scenarioOutline, featureName, featureFilePath, featureLanguage, featureDescription, featureTags, backgroundSteps, includeScenarioTags, excludeScenarioTags);
singleScenarioFeatures.addAll(outlineScenarios);
}
}
}
return singleScenarioFeatures;
}
use of gherkin.ast.ScenarioDefinition in project page-factory-2 by sbtqa.
the class FragmentReplacer method replace.
/**
* In the graph, terminal fragments are searched and substituted cyclically.
* The cycle will be completed when all fragments are substituted and there are no edges left in the graph.
*
* @throws IllegalAccessException if it was not possible to replace a step with a fragment
* @throws FragmentException if fragments replacing is in an infinite loop
*/
public void replace() throws IllegalAccessException, FragmentException, DataException {
while (!fragmentsGraph.edges().isEmpty()) {
int fragmentsGraphSize = fragmentsGraph.edges().size();
for (EndpointPair edge : new ArrayList<>(fragmentsGraph.edges())) {
ScenarioDefinition fragment = (ScenarioDefinition) edge.nodeV();
ScenarioDefinition scenario = (ScenarioDefinition) edge.nodeU();
String data = fragmentsGraph.edgeValue(edge.nodeU(), edge.nodeV()).get();
if (isTerminal(fragment)) {
replaceFragmentInScenario(scenario, fragment, data);
fragmentsGraph.removeEdge(scenario, fragment);
}
}
if (fragmentsGraphSize == fragmentsGraph.edges().size()) {
throw new FragmentException("Fragments replacing is no longer performed, it will lead to an infinite loop. Interrupting...");
}
}
}
use of gherkin.ast.ScenarioDefinition in project cucable-plugin by trivago.
the class GherkinDocumentParser method getSingleScenariosFromFeature.
/**
* Returns a {@link SingleScenario} list from a given feature file.
*
* @param featureContent A feature string.
* @param featureFilePath The path to the source feature file.
* @return A {@link SingleScenario} list.
* @throws CucablePluginException see {@link CucablePluginException}.
*/
public List<SingleScenario> getSingleScenariosFromFeature(final String featureContent, final String featureFilePath, final List<Integer> scenarioLineNumbers) throws CucablePluginException {
String escapedFeatureContent = featureContent.replace("\\n", "\\\\n");
GherkinDocument gherkinDocument;
try {
gherkinDocument = getGherkinDocumentFromFeatureFileContent(escapedFeatureContent);
} catch (CucablePluginException e) {
throw new FeatureFileParseException(featureFilePath, e.getMessage());
}
Feature feature = gherkinDocument.getFeature();
if (feature == null) {
return Collections.emptyList();
}
String featureName = feature.getKeyword() + ": " + feature.getName();
String featureLanguage = feature.getLanguage();
String featureDescription = feature.getDescription();
List<String> featureTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(feature.getTags());
ArrayList<SingleScenario> singleScenarioFeatures = new ArrayList<>();
List<Step> backgroundSteps = new ArrayList<>();
List<ScenarioDefinition> scenarioDefinitions = feature.getChildren();
for (ScenarioDefinition scenarioDefinition : scenarioDefinitions) {
String scenarioName = scenarioDefinition.getKeyword() + ": " + scenarioDefinition.getName();
String scenarioDescription = scenarioDefinition.getDescription();
if (scenarioDefinition instanceof Background) {
// Save background steps in order to add them to every scenario inside the same feature
Background background = (Background) scenarioDefinition;
backgroundSteps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(background.getSteps());
continue;
}
if (scenarioDefinition instanceof Scenario) {
Scenario scenario = (Scenario) scenarioDefinition;
if (scenarioLineNumbers == null || scenarioLineNumbers.isEmpty() || scenarioLineNumbers.contains(scenario.getLocation().getLine())) {
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, backgroundSteps);
addGherkinScenarioInformationToSingleScenario(scenario, singleScenario);
if (scenarioShouldBeIncluded(singleScenario)) {
singleScenarioFeatures.add(singleScenario);
}
}
continue;
}
if (scenarioDefinition instanceof ScenarioOutline) {
ScenarioOutline scenarioOutline = (ScenarioOutline) scenarioDefinition;
if (scenarioLineNumbers == null || scenarioLineNumbers.isEmpty() || scenarioLineNumbers.contains(scenarioOutline.getLocation().getLine())) {
List<SingleScenario> outlineScenarios = getSingleScenariosFromOutline(scenarioOutline, featureName, featureFilePath, featureLanguage, featureDescription, featureTags, backgroundSteps);
for (SingleScenario singleScenario : outlineScenarios) {
if (scenarioShouldBeIncluded(singleScenario)) {
singleScenarioFeatures.add(singleScenario);
}
}
}
}
}
return singleScenarioFeatures;
}
Aggregations