Search in sources :

Example 1 with SingleScenarioRunner

use of com.trivago.rta.vo.SingleScenarioRunner in project cucable-plugin by trivago.

the class RunnerFileContentRendererTest method getRenderedFeatureFileContentTest.

@Test
public void getRenderedFeatureFileContentTest() throws Exception {
    String template = "package parallel;\n" + "\n" + "import cucumber.api.CucumberOptions;\n" + "\n" + "@CucumberOptions(\n" + "    monochrome = false,\n" + "    features = {\"classpath:parallel/features/[FEATURE_FILE_NAME].feature\"},\n" + "    plugin = {\"json:target/cucumber-report/[FEATURE_FILE_NAME].json\"}\n" + ")\n" + "public class [FEATURE_FILE_NAME] {\n" + "}\n";
    when(fileIO.readContentFromFile(anyString())).thenReturn(template);
    String expectedOutput = "package parallel;\n" + "\n" + "import cucumber.api.CucumberOptions;\n" + "\n" + "@CucumberOptions(\n" + "    monochrome = false,\n" + "    features = {\"classpath:parallel/features/featureFileName.feature\"},\n" + "    plugin = {\"json:target/cucumber-report/featureFileName.json\"}\n" + ")\n" + "public class featureFileName {\n" + "}\n" + "\n" + "\n" + "// Source Feature: \n" + "// Generated by Cucable\n";
    SingleScenarioRunner singleScenarioRunner = new SingleScenarioRunner("pathToTemplate", "featureFileName");
    SingleScenario singleScenario = new SingleScenario("", "", "", "", "", "", null, null);
    String renderedRunnerFileContent = runnerFileContentRenderer.getRenderedRunnerFileContent(singleScenarioRunner, singleScenario);
    assertThat(renderedRunnerFileContent, is(expectedOutput));
}
Also used : SingleScenarioRunner(com.trivago.rta.vo.SingleScenarioRunner) SingleScenario(com.trivago.rta.vo.SingleScenario) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with SingleScenarioRunner

use of com.trivago.rta.vo.SingleScenarioRunner in project cucable-plugin by trivago.

the class FeatureFileConverter method convertToSingleScenariosAndRunners.

/**
 * Converts all scenarios in the given feature file to single
 * scenario feature files and their respective runners.
 *
 * @param featureFilePath feature file to process.
 * @return Number of created scenarios.
 * @throws CucablePluginException see {@link CucablePluginException}
 */
private int convertToSingleScenariosAndRunners(final Path featureFilePath) throws CucablePluginException {
    String featureFilePathString = featureFilePath.toString();
    if (featureFilePathString == null || featureFilePathString.equals("")) {
        throw new MissingFileException(featureFilePathString);
    }
    List<Integer> lineNumbers = propertyManager.getScenarioLineNumbers();
    List<String> includeScenarioTags = propertyManager.getIncludeScenarioTags();
    List<String> excludeScenarioTags = propertyManager.getExcludeScenarioTags();
    String featureFileContent = fileIO.readContentFromFile(featureFilePathString);
    List<SingleScenario> singleScenarios;
    try {
        singleScenarios = gherkinDocumentParser.getSingleScenariosFromFeature(featureFileContent, featureFilePathString, lineNumbers, includeScenarioTags, excludeScenarioTags);
    } catch (CucablePluginException e) {
        throw new FeatureFileParseException(featureFilePathString);
    }
    // that means that the provided line number is wrong.
    if (propertyManager.hasValidScenarioLineNumbers() && singleScenarios.size() == 0) {
        throw new CucablePluginException("There is no parseable scenario or scenario outline at line " + lineNumbers);
    }
    for (SingleScenario singleScenario : singleScenarios) {
        String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
        String featureFileName = getFeatureFileNameFromPath(featureFilePath);
        Integer featureCounter = singleFeatureCounters.getOrDefault(featureFileName, 0);
        featureCounter++;
        String scenarioCounterFilenamePart = String.format(SCENARIO_COUNTER_FORMAT, featureCounter);
        for (int testRuns = 1; testRuns <= propertyManager.getNumberOfTestRuns(); testRuns++) {
            String testRunsCounterFilenamePart = String.format(TEST_RUNS_COUNTER_FORMAT, testRuns);
            // Append the scenario and test run counters to the filename.
            // Also add the "_IT" postfix so Maven Failsafe considers it an integration test automatically.
            String generatedFileName = featureFileName.concat(scenarioCounterFilenamePart).concat(testRunsCounterFilenamePart).concat(INTEGRATION_TEST_POSTFIX);
            String generatedFeatureFilePath = propertyManager.getGeneratedFeatureDirectory().concat(PATH_SEPARATOR).concat(generatedFileName).concat(FEATURE_FILE_EXTENSION);
            singleFeatureCounters.put(featureFileName, featureCounter);
            // Save scenario information to new feature file
            fileIO.writeContentToFile(renderedFeatureFileContent, generatedFeatureFilePath);
            // Generate runner for the newly generated single scenario feature file
            SingleScenarioRunner singleScenarioRunner = new SingleScenarioRunner(propertyManager.getSourceRunnerTemplateFile(), generatedFileName);
            String renderedRunnerFileContent = runnerFileContentRenderer.getRenderedRunnerFileContent(singleScenarioRunner, singleScenario);
            String generatedRunnerFilePath = propertyManager.getGeneratedRunnerDirectory().concat(PATH_SEPARATOR).concat(generatedFileName).concat(RUNNER_FILE_EXTENSION);
            fileIO.writeContentToFile(renderedRunnerFileContent, generatedRunnerFilePath);
        }
    }
    int createdScenarios = singleScenarios.size();
    logProcessCompleteMessage(featureFilePathString, createdScenarios);
    return createdScenarios;
}
Also used : SingleScenarioRunner(com.trivago.rta.vo.SingleScenarioRunner) SingleScenario(com.trivago.rta.vo.SingleScenario) FeatureFileParseException(com.trivago.rta.exceptions.filesystem.FeatureFileParseException) CucablePluginException(com.trivago.rta.exceptions.CucablePluginException) MissingFileException(com.trivago.rta.exceptions.filesystem.MissingFileException)

Aggregations

SingleScenario (com.trivago.rta.vo.SingleScenario)2 SingleScenarioRunner (com.trivago.rta.vo.SingleScenarioRunner)2 CucablePluginException (com.trivago.rta.exceptions.CucablePluginException)1 FeatureFileParseException (com.trivago.rta.exceptions.filesystem.FeatureFileParseException)1 MissingFileException (com.trivago.rta.exceptions.filesystem.MissingFileException)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1