use of com.trivago.rta.vo.Step in project cucable-plugin by trivago.
the class FeatureFileContentRenderer method addSteps.
/**
* Adds the rendered steps to the generated feature file content.
*
* @param stringBuilder The current feature {@link StringBuilder} instance.
* @param steps The {@link Step} list.
*/
private void addSteps(final StringBuilder stringBuilder, final List<Step> steps) {
if (steps == null) {
return;
}
for (Step step : steps) {
stringBuilder.append(step.getName()).append(LINE_SEPARATOR);
stringBuilder.append(formatDocString(step.getDocString()));
stringBuilder.append(formatDataTableString(step.getDataTable()));
}
}
use of com.trivago.rta.vo.Step in project cucable-plugin by trivago.
the class FeatureFileContentRendererTest method formatDocStringTest.
@Test
public void formatDocStringTest() {
String expectedOutput = "Feature: featureName\n" + "\n" + "Scenario: scenarioName\n" + "\n" + "Step 1\n" + "\"\"\"\n" + "DOCSTRING LINE 1\n" + "DOCSTRING LINE 2\n" + "\"\"\"\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
String featureName = "Feature: featureName";
String scenarioName = "Scenario: scenarioName";
List<Step> steps = Collections.singletonList(new Step("Step 1", null, "DOCSTRING LINE 1\nDOCSTRING LINE 2"));
String featureFilePath = "TESTPATH";
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, null, null, scenarioName, null, new ArrayList<>(), new ArrayList<>());
singleScenario.setSteps(steps);
String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
assertThat(renderedFeatureFileContent, is(expectedOutput));
}
use of com.trivago.rta.vo.Step in project cucable-plugin by trivago.
the class GherkinDocumentParser method getSingleScenariosFromOutline.
/**
* Returns a list of Cucable single scenarios from a Gherkin scenario outline.
*
* @param scenarioOutline A Gherkin {@link ScenarioOutline}.
* @param featureName The name of the feature this scenario outline belongs to.
* @param featureFilePath The source path of the feature file.
* @param featureLanguage The feature language this scenario outline belongs to.
* @param featureTags The feature tags of the parent feature.
* @param backgroundSteps Return a Cucable {@link SingleScenario} list.
* @param includeScenarioTags Optional scenario tags to include in scenario generation.
* @throws CucablePluginException Thrown when the scenario outline does not contain an example table.
*/
private List<SingleScenario> getSingleScenariosFromOutline(final ScenarioOutline scenarioOutline, final String featureName, final String featureFilePath, final String featureLanguage, final String featureDescription, final List<String> featureTags, final List<Step> backgroundSteps, final List<String> includeScenarioTags, final List<String> excludeScenarioTags) throws CucablePluginException {
// Retrieve the translation of "Scenario" in the target language and add it to the scenario
String translatedScenarioKeyword = gherkinTranslations.getScenarioKeyword(featureLanguage);
String scenarioName = translatedScenarioKeyword + ": " + scenarioOutline.getName();
String scenarioDescription = scenarioOutline.getDescription();
List<String> scenarioTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(scenarioOutline.getTags());
if (!scenarioShouldBeIncluded(featureTags, scenarioTags, includeScenarioTags, excludeScenarioTags)) {
return Collections.emptyList();
}
List<SingleScenario> outlineScenarios = new ArrayList<>();
List<Step> steps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(scenarioOutline.getSteps());
if (scenarioOutline.getExamples().isEmpty()) {
throw new CucablePluginException("Scenario outline without examples table!");
}
Examples exampleTable = scenarioOutline.getExamples().get(0);
Map<String, List<String>> exampleMap = gherkinToCucableConverter.convertGherkinExampleTableToCucableExampleMap(exampleTable);
String firstColumnHeader = (String) exampleMap.keySet().toArray()[0];
int rowCount = exampleMap.get(firstColumnHeader).size();
// For each example row, create a new single scenario
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, substituteScenarioNameExamplePlaceholders(scenarioName, exampleMap, rowIndex), scenarioDescription, featureTags, backgroundSteps);
List<Step> substitutedSteps = substituteStepExamplePlaceholders(steps, exampleMap, rowIndex);
singleScenario.setSteps(substitutedSteps);
singleScenario.setScenarioTags(scenarioTags);
outlineScenarios.add(singleScenario);
}
return outlineScenarios;
}
use of com.trivago.rta.vo.Step in project cucable-plugin by trivago.
the class GherkinDocumentParser method substituteStepExamplePlaceholders.
/**
* Replaces the example value placeholders in steps by the actual example table values.
*
* @param steps The Cucable {@link Step} list.
* @param exampleMap The generated example map from an example table.
* @param rowIndex The row index of the example table to consider.
* @return A {@link Step} list with substituted names.
*/
private List<Step> substituteStepExamplePlaceholders(final List<Step> steps, final Map<String, List<String>> exampleMap, final int rowIndex) {
List<Step> substitutedSteps = new ArrayList<>();
for (Step step : steps) {
String stepName = step.getName();
// substitute values in the step
DataTable dataTable = step.getDataTable();
for (String columnName : exampleMap.keySet()) {
String columnValue = exampleMap.get(columnName).get(rowIndex);
stepName = stepName.replace(columnName, columnValue);
dataTable = replaceDataTableExamplePlaceholder(dataTable, columnName, columnValue);
}
substitutedSteps.add(new Step(stepName, dataTable, step.getDocString()));
}
return substitutedSteps;
}
use of com.trivago.rta.vo.Step 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;
}
Aggregations