Search in sources :

Example 1 with CucumberTagStatement

use of cucumber.runtime.model.CucumberTagStatement in project cucumber-jvm by cucumber.

the class ScenarioCounterTest method createCucumberFeaturesWithScenarioOutlines.

private List<CucumberFeature> createCucumberFeaturesWithScenarioOutlines(final int numberOfCucumberFeatures, final int numberOfScenarioOutlines, final int numberOfCucumberExamples, final int numberOfExampleRows) {
    final int numberOfExampleRowsIncludingHeaderRow = numberOfExampleRows + 1;
    final List<CucumberFeature> cucumberFeatures = new ArrayList<CucumberFeature>();
    for (int f = 0; f < numberOfCucumberFeatures; f++) {
        final CucumberFeature cucumberFeature = mock(CucumberFeature.class);
        cucumberFeatures.add(cucumberFeature);
        // set up 2 scenarios outlines
        final List<CucumberTagStatement> cucumberTagStatements = new ArrayList<CucumberTagStatement>();
        for (int o = 0; o < numberOfScenarioOutlines; o++) {
            cucumberTagStatements.add(mock(CucumberScenarioOutline.class));
        }
        when(cucumberFeature.getFeatureElements()).thenReturn(cucumberTagStatements);
        // with 2 examples for each scenario outline
        for (final CucumberTagStatement cucumberTagStatement : cucumberTagStatements) {
            final CucumberScenarioOutline cucumberScenarioOutline = (CucumberScenarioOutline) cucumberTagStatement;
            final List<CucumberExamples> cucumberExamplesList = createMockList(CucumberExamples.class, numberOfCucumberExamples);
            when(cucumberScenarioOutline.getCucumberExamplesList()).thenReturn(cucumberExamplesList);
            // each example should have two rows (excluding the header row)
            for (final CucumberExamples cucumberExamples : cucumberExamplesList) {
                final Examples examples = mock(Examples.class);
                when(examples.getRows()).thenReturn(createMockList(ExamplesTableRow.class, numberOfExampleRowsIncludingHeaderRow));
                when(cucumberExamples.getExamples()).thenReturn(examples);
            }
        }
    }
    return cucumberFeatures;
}
Also used : CucumberScenarioOutline(cucumber.runtime.model.CucumberScenarioOutline) ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) CucumberFeature(cucumber.runtime.model.CucumberFeature) ArrayList(java.util.ArrayList) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement) CucumberExamples(cucumber.runtime.model.CucumberExamples) CucumberExamples(cucumber.runtime.model.CucumberExamples) Examples(gherkin.formatter.model.Examples)

Example 2 with CucumberTagStatement

use of cucumber.runtime.model.CucumberTagStatement in project cucumber-jvm by cucumber.

the class StepdefGenerator method generate.

public List<MetaStepdef> generate(Collection<StepDefinition> stepDefinitions, List<CucumberFeature> features) {
    List<MetaStepdef> result = new ArrayList<MetaStepdef>();
    List<StepDefinition> sortedStepdefs = new ArrayList<StepDefinition>();
    sortedStepdefs.addAll(stepDefinitions);
    Collections.sort(sortedStepdefs, STEP_DEFINITION_COMPARATOR);
    for (StepDefinition stepDefinition : sortedStepdefs) {
        MetaStepdef metaStepdef = new MetaStepdef();
        metaStepdef.source = stepDefinition.getPattern();
        // TODO = get the flags too
        metaStepdef.flags = "";
        for (CucumberFeature feature : features) {
            List<CucumberTagStatement> cucumberTagStatements = feature.getFeatureElements();
            for (CucumberTagStatement tagStatement : cucumberTagStatements) {
                List<Step> steps = tagStatement.getSteps();
                for (Step step : steps) {
                    List<Argument> arguments = stepDefinition.matchedArguments(step);
                    if (arguments != null) {
                        MetaStepdef.MetaStep ms = new MetaStepdef.MetaStep();
                        ms.name = step.getName();
                        for (Argument argument : arguments) {
                            MetaStepdef.MetaArgument ma = new MetaStepdef.MetaArgument();
                            ma.offset = argument.getOffset();
                            ma.val = argument.getVal();
                            ms.args.add(ma);
                        }
                        metaStepdef.steps.add(ms);
                    }
                }
            }
            Collections.sort(cucumberTagStatements, CUCUMBER_TAG_STATEMENT_COMPARATOR);
        }
        result.add(metaStepdef);
    }
    return result;
}
Also used : Argument(gherkin.formatter.Argument) ArrayList(java.util.ArrayList) Step(gherkin.formatter.model.Step) CucumberFeature(cucumber.runtime.model.CucumberFeature) StepDefinition(cucumber.runtime.StepDefinition) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement)

Example 3 with CucumberTagStatement

use of cucumber.runtime.model.CucumberTagStatement in project cucumber-jvm by cucumber.

the class FeatureRunner method buildFeatureElementRunners.

private void buildFeatureElementRunners() {
    for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) {
        try {
            ParentRunner featureElementRunner;
            if (cucumberTagStatement instanceof CucumberScenario) {
                featureElementRunner = new ExecutionUnitRunner(runtime, (CucumberScenario) cucumberTagStatement, jUnitReporter);
            } else {
                featureElementRunner = new ScenarioOutlineRunner(runtime, (CucumberScenarioOutline) cucumberTagStatement, jUnitReporter);
            }
            children.add(featureElementRunner);
        } catch (InitializationError e) {
            throw new CucumberException("Failed to create scenario runner", e);
        }
    }
}
Also used : CucumberScenarioOutline(cucumber.runtime.model.CucumberScenarioOutline) InitializationError(org.junit.runners.model.InitializationError) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement) CucumberException(cucumber.runtime.CucumberException) ParentRunner(org.junit.runners.ParentRunner)

Example 4 with CucumberTagStatement

use of cucumber.runtime.model.CucumberTagStatement in project cucumber-jvm by cucumber.

the class ScenarioCounterTest method createCucumberFeaturesWithScenarios.

private List<CucumberFeature> createCucumberFeaturesWithScenarios(final int numberOfCucumberFeatures, final int numberOfCucumberScenarios) {
    final List<CucumberFeature> cucumberFeatures = new ArrayList<CucumberFeature>();
    for (int f = 0; f < numberOfCucumberFeatures; f++) {
        final CucumberFeature cucumberFeature = mock(CucumberFeature.class);
        cucumberFeatures.add(cucumberFeature);
        final List<CucumberTagStatement> cucumberTagStatements = new ArrayList<CucumberTagStatement>();
        for (int s = 0; s < numberOfCucumberScenarios; s++) {
            cucumberTagStatements.add(mock(CucumberScenario.class));
        }
        when(cucumberFeature.getFeatureElements()).thenReturn(cucumberTagStatements);
    }
    return cucumberFeatures;
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ArrayList(java.util.ArrayList) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement)

Example 5 with CucumberTagStatement

use of cucumber.runtime.model.CucumberTagStatement in project activityinfo by bedatadriven.

the class TestMain method queueFeatures.

private void queueFeatures(String environment, ResourceLoader loader, RuntimeOptions options, Module... driverModules) {
    List<Module> modules = new ArrayList<>();
    modules.add(new SystemUnderTest(url));
    modules.add(new EmailModule());
    modules.addAll(Arrays.asList(driverModules));
    TestConditions conditions = new TestConditions(environment, modules);
    Predicate<String> filter = filterPredicate();
    List<CucumberFeature> features = options.cucumberFeatures(loader);
    for (CucumberFeature feature : features) {
        for (CucumberTagStatement element : feature.getFeatureElements()) {
            if (filter.apply(feature.getPath()) || filter.apply(element.getVisualName())) {
                ScenarioTestCase testCase = new ScenarioTestCase(options, feature, element, conditions);
                queueTestCase(testCase);
            }
        }
    }
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) SystemUnderTest(org.activityinfo.test.sut.SystemUnderTest) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement) OdkModule(org.activityinfo.test.webdriver.OdkModule) Module(com.google.inject.Module) ApiModule(org.activityinfo.test.driver.ApiModule) WebDriverModule(org.activityinfo.test.webdriver.WebDriverModule) EmailModule(org.activityinfo.test.driver.mail.EmailModule) EmailModule(org.activityinfo.test.driver.mail.EmailModule) ScenarioTestCase(org.activityinfo.test.cucumber.ScenarioTestCase)

Aggregations

CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)5 CucumberFeature (cucumber.runtime.model.CucumberFeature)4 ArrayList (java.util.ArrayList)3 CucumberScenario (cucumber.runtime.model.CucumberScenario)2 CucumberScenarioOutline (cucumber.runtime.model.CucumberScenarioOutline)2 Module (com.google.inject.Module)1 CucumberException (cucumber.runtime.CucumberException)1 StepDefinition (cucumber.runtime.StepDefinition)1 CucumberExamples (cucumber.runtime.model.CucumberExamples)1 Argument (gherkin.formatter.Argument)1 Examples (gherkin.formatter.model.Examples)1 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)1 Step (gherkin.formatter.model.Step)1 ScenarioTestCase (org.activityinfo.test.cucumber.ScenarioTestCase)1 ApiModule (org.activityinfo.test.driver.ApiModule)1 EmailModule (org.activityinfo.test.driver.mail.EmailModule)1 SystemUnderTest (org.activityinfo.test.sut.SystemUnderTest)1 OdkModule (org.activityinfo.test.webdriver.OdkModule)1 WebDriverModule (org.activityinfo.test.webdriver.WebDriverModule)1 ParentRunner (org.junit.runners.ParentRunner)1