gherkin.ast.ScenarioOutline Java Examples

The following examples show how to use gherkin.ast.ScenarioOutline. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 6 votes vote down vote up
private synchronized void handleScenarioOutline(TestCase testCase) {
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile.get(), testCase.getLine());
    if (TestSourcesModel.isScenarioOutlineScenario(astNode)) {
        ScenarioOutline scenarioOutline = (ScenarioOutline)TestSourcesModel.getScenarioDefinition(astNode);
        if (currentScenarioOutline.get() == null || !currentScenarioOutline.get().getName().equals(scenarioOutline.getName())) {
            scenarioOutlineThreadLocal.set(null);
            createScenarioOutline(scenarioOutline);
            currentScenarioOutline.set(scenarioOutline);
            addOutlineStepsToReport(scenarioOutline);
        }
        Examples examples = (Examples)astNode.parent.node;
        if (currentExamples.get() == null || !currentExamples.get().equals(examples)) {
            currentExamples.set(examples);
            createExamples(examples);
        }
    } else {
        scenarioOutlineThreadLocal.set(null);
        currentScenarioOutline.set(null);
        currentExamples.set(null);
    }
}
 
Example #2
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 6 votes vote down vote up
private synchronized void createScenarioOutline(ScenarioOutline scenarioOutline) {
    if (scenarioOutlineMap.containsKey(scenarioOutline.getName())) {
        scenarioOutlineThreadLocal.set(scenarioOutlineMap.get(scenarioOutline.getName()));
        return;
    }
    if (scenarioOutlineThreadLocal.get() == null) {
        ExtentTest t = featureTestThreadLocal.get()
                .createNode(com.aventstack.extentreports.gherkin.model.ScenarioOutline.class, scenarioOutline.getName(), scenarioOutline.getDescription());
        scenarioOutlineThreadLocal.set(t);
        scenarioOutlineMap.put(scenarioOutline.getName(), t);
        List<String> featureTags = scenarioOutlineThreadLocal.get().getModel()
        		.getParent().getCategoryContext().getAll()
        		.stream()
        		.map(x -> x.getName())
        		.collect(Collectors.toList());
        scenarioOutline.getTags()
        	.stream()
        	.map(x -> x.getName())
        	.filter(x -> !featureTags.contains(x))
        	.forEach(scenarioOutlineThreadLocal.get()::assignCategory);
    }
}
 
Example #3
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private void createTestCases(Scenario scenario, Feature feature) {
    for (ScenarioDefinition scenarioDef : feature.getChildren()) {
        String scenDefName = scenarioDef.getName();
        TestCase testCase = updateInfo(createTestCase(scenario, scenDefName), scenarioDef);
        testCase.clearSteps();
        for (Step step : scenarioDef.getSteps()) {
            String reusableName = convert(step.getText());
            TestCase reusable = updateInfo(createReusable(create("StepDefinitions"), reusableName), step);
            if (reusable != null) {
                reusable.addNewStep()
                        .setInput(getInputField(testCase.getName(), step.getText()))
                        .setDescription(getDescription(step));
            }
            testCase.addNewStep()
                    .asReusableStep("StepDefinitions", reusableName)
                    .setDescription(getDescription(step));
        }
        if (scenarioDef instanceof ScenarioOutline) {
            ScenarioOutline scOutline = (ScenarioOutline) scenarioDef;
            createTestData(testCase, scOutline.getExamples());
        }
    }
}
 
Example #4
Source File: CucumberSourceUtils.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void processScenarioOutlineExamples(
        final Map<Integer, AstNode> nodeMap, final ScenarioOutline scenarioOutline, final AstNode childNode
) {
    scenarioOutline.getExamples().forEach(examples -> {
        final AstNode examplesNode = new AstNode(examples, childNode);
        final TableRow headerRow = examples.getTableHeader();
        final AstNode headerNode = new AstNode(headerRow, examplesNode);
        nodeMap.put(headerRow.getLocation().getLine(), headerNode);
        IntStream.range(0, examples.getTableBody().size()).forEach(i -> {
            final TableRow examplesRow = examples.getTableBody().get(i);
            final Node rowNode = new CucumberSourceUtils.ExamplesRowWrapperNode(examplesRow, i);
            final AstNode expandedScenarioNode = new AstNode(rowNode, examplesNode);
            nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode);
        });
    });
}
 
Example #5
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private List<Parameter> getExamplesAsParameters(final ScenarioOutline scenarioOutline) {
    final int gap = 2;
    final Optional<Examples> examplesBlock = scenarioOutline.getExamples().stream()
            .filter(e -> currentTestCase.getLine() >= e.getLocation().getLine() + gap)
            .filter(e -> currentTestCase.getLine() < e.getLocation().getLine() + e.getTableBody().size() + gap)
            .findFirst();

    if (examplesBlock.isPresent()) {
        final Examples examples = examplesBlock.get();
        final int rowIndex = currentTestCase.getLine() - examples.getLocation().getLine() - gap;
        final List<TableCell> names = examples.getTableHeader().getCells();
        final List<TableCell> values = examples.getTableBody().get(rowIndex).getCells();
        return IntStream.range(0, examplesBlock.get().getTableHeader().getCells().size()).mapToObj(index -> {
            final String name = names.get(index).getValue();
            final String value = values.get(index).getValue();
            return new Parameter().setName(name).setValue(value);
        }).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
 
Example #6
Source File: CucumberSourceUtils.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void processScenarioOutlineExamples(
        final Map<Integer, AstNode> nodeMap, final ScenarioOutline scenarioOutline, final AstNode childNode
) {
    scenarioOutline.getExamples().forEach(examples -> {
        final AstNode examplesNode = new AstNode(examples, childNode);
        final TableRow headerRow = examples.getTableHeader();
        final AstNode headerNode = new AstNode(headerRow, examplesNode);
        nodeMap.put(headerRow.getLocation().getLine(), headerNode);
        IntStream.range(0, examples.getTableBody().size()).forEach(i -> {
            final TableRow examplesRow = examples.getTableBody().get(i);
            final Node rowNode = new CucumberSourceUtils.ExamplesRowWrapperNode(examplesRow, i);
            final AstNode expandedScenarioNode = new AstNode(rowNode, examplesNode);
            nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode);
        });
    });
}
 
Example #7
Source File: TestSourcesModel.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void processScenarioOutlineExamples(final Map<Integer, AstNode> nodeMap,
                                            final ScenarioOutline scenarioOutline,
                                            final AstNode childNode) {
    for (Examples examples : scenarioOutline.getExamples()) {
        final AstNode examplesNode = createAstNode(examples, childNode);
        final TableRow headerRow = examples.getTableHeader();
        final AstNode headerNode = createAstNode(headerRow, examplesNode);
        nodeMap.put(headerRow.getLocation().getLine(), headerNode);
        for (int i = 0; i < examples.getTableBody().size(); ++i) {
            final TableRow examplesRow = examples.getTableBody().get(i);
            final Node rowNode = createExamplesRowWrapperNode(examplesRow, i);
            final AstNode expandedScenarioNode = createAstNode(rowNode, examplesNode);
            nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode);
        }
    }
}
 
Example #8
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private List getTags(ScenarioDefinition sdef) {
    if (sdef instanceof ScenarioOutline) {
        return ((ScenarioOutline) sdef).getTags();
    } else if (sdef instanceof gherkin.ast.Scenario) {
        return ((gherkin.ast.Scenario) sdef).getTags();
    } else {
        return null;
    }
}
 
Example #9
Source File: TestSourcesModel.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private void processScenarioDefinition(Map<Integer, AstNode> nodeMap, ScenarioDefinition child, AstNode currentParent) {
    AstNode childNode = new AstNode(child, currentParent);
    nodeMap.put(child.getLocation().getLine(), childNode);
    for (Step step : child.getSteps()) {
        nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode));
    }
    if (child instanceof ScenarioOutline) {
        processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
    }
}
 
Example #10
Source File: CucumberSourceUtils.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void processScenarioDefinition(
        final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child, final AstNode currentParent
) {
    final AstNode childNode = new AstNode(child, currentParent);
    nodeMap.put(child.getLocation().getLine(), childNode);

    child.getSteps().forEach(
        step -> nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode))
    );

    if (child instanceof ScenarioOutline) {
        processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
    }
}
 
Example #11
Source File: TestSourcesModel.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void processScenarioDefinition(final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child,
                                       final AstNode currentParent) {
    final AstNode childNode = new AstNode(child, currentParent);
    nodeMap.put(child.getLocation().getLine(), childNode);
    for (Step step : child.getSteps()) {
        nodeMap.put(step.getLocation().getLine(), createAstNode(step, childNode));
    }
    if (child instanceof ScenarioOutline) {
        processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
    }
}
 
Example #12
Source File: CucumberSourceUtils.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void processScenarioDefinition(
        final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child, final AstNode currentParent
) {
    final AstNode childNode = new AstNode(child, currentParent);
    nodeMap.put(child.getLocation().getLine(), childNode);

    child.getSteps().forEach(
        step -> nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode))
    );

    if (child instanceof ScenarioOutline) {
        processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
    }
}
 
Example #13
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private synchronized void addOutlineStepsToReport(ScenarioOutline scenarioOutline) {
    for (Step step : scenarioOutline.getSteps()) {
        if (step.getArgument() != null) {
            Node argument = step.getArgument();
            if (argument instanceof DocString) {
                createDocStringMap((DocString)argument);
            } else if (argument instanceof DataTable) {
                
            }
        }
    }
}
 
Example #14
Source File: TestSourcesModel.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private void processScenarioOutlineExamples(Map<Integer, AstNode> nodeMap, ScenarioOutline scenarioOutline, AstNode childNode) {
    for (Examples examples : scenarioOutline.getExamples()) {
        AstNode examplesNode = new AstNode(examples, childNode);
        TableRow headerRow = examples.getTableHeader();
        AstNode headerNode = new AstNode(headerRow, examplesNode);
        nodeMap.put(headerRow.getLocation().getLine(), headerNode);
        for (int i = 0; i < examples.getTableBody().size(); ++i) {
            TableRow examplesRow = examples.getTableBody().get(i);
            Node rowNode = new ExamplesRowWrapperNode(examplesRow, i);
            AstNode expandedScenarioNode = new AstNode(rowNode, examplesNode);
            nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode);
        }
    }
}
 
Example #15
Source File: AllureCucumber4Jvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private void handleTestCaseStarted(final TestCaseStarted event) {
    currentFeatureFile.set(event.testCase.getUri());
    currentFeature.set(testSources.getFeature(currentFeatureFile.get()));
    currentTestCase.set(event.testCase);
    currentContainer.set(UUID.randomUUID().toString());
    forbidTestCaseStatusChange.set(false);

    final Deque<PickleTag> tags = new LinkedList<>(currentTestCase.get().getTags());

    final Feature feature = currentFeature.get();
    final LabelBuilder labelBuilder = new LabelBuilder(feature, currentTestCase.get(), tags);

    final String name = currentTestCase.get().getName();
    final String featureName = feature.getName();

    final TestResult result = new TestResult()
            .setUuid(getTestCaseUuid(currentTestCase.get()))
            .setHistoryId(getHistoryId(currentTestCase.get()))
            .setFullName(featureName + ": " + name)
            .setName(name)
            .setLabels(labelBuilder.getScenarioLabels())
            .setLinks(labelBuilder.getScenarioLinks());

    final ScenarioDefinition scenarioDefinition =
            testSources.getScenarioDefinition(currentFeatureFile.get(), currentTestCase.get().getLine());
    if (scenarioDefinition instanceof ScenarioOutline) {
        result.setParameters(
                getExamplesAsParameters((ScenarioOutline) scenarioDefinition, currentTestCase.get())
        );
    }

    final String description = Stream.of(feature.getDescription(), scenarioDefinition.getDescription())
            .filter(Objects::nonNull)
            .filter(s -> !s.isEmpty())
            .collect(Collectors.joining("\n"));

    if (!description.isEmpty()) {
        result.setDescription(description);
    }

    final TestResultContainer resultContainer = new TestResultContainer()
            .setName(String.format("%s: %s", scenarioDefinition.getKeyword(), scenarioDefinition.getName()))
            .setUuid(getTestContainerUuid())
            .setChildren(Collections.singletonList(getTestCaseUuid(currentTestCase.get())));

    lifecycle.scheduleTestCase(result);
    lifecycle.startTestContainer(getTestContainerUuid(), resultContainer);
    lifecycle.startTestCase(getTestCaseUuid(currentTestCase.get()));
}
 
Example #16
Source File: AllureCucumber3Jvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private void handleTestCaseStarted(final TestCaseStarted event) {
    currentTestCase = event.testCase;
    currentFeatureFile = currentTestCase.getUri();
    currentFeature = cucumberSourceUtils.getFeature(currentFeatureFile);
    currentContainer = UUID.randomUUID().toString();
    forbidTestCaseStatusChange = false;


    final Deque<PickleTag> tags = new LinkedList<>(currentTestCase.getTags());

    final LabelBuilder labelBuilder = new LabelBuilder(currentFeature, currentTestCase, tags);

    final String name = currentTestCase.getName();
    final String featureName = currentFeature.getName();

    final TestResult result = new TestResult()
            .setUuid(getTestCaseUuid(currentTestCase))
            .setHistoryId(getHistoryId(currentTestCase))
            .setFullName(featureName + ": " + name)
            .setName(name)
            .setLabels(labelBuilder.getScenarioLabels())
            .setLinks(labelBuilder.getScenarioLinks());

    final ScenarioDefinition scenarioDefinition =
            cucumberSourceUtils.getScenarioDefinition(currentFeatureFile, currentTestCase.getLine());
    if (scenarioDefinition instanceof ScenarioOutline) {
        result.setParameters(
                getExamplesAsParameters((ScenarioOutline) scenarioDefinition)
        );
    }

    if (currentFeature.getDescription() != null && !currentFeature.getDescription().isEmpty()) {
        result.setDescription(currentFeature.getDescription());
    }

    final TestResultContainer resultContainer = new TestResultContainer()
            .setName(String.format("%s: %s", scenarioDefinition.getKeyword(), scenarioDefinition.getName()))
            .setUuid(getTestContainerUuid())
            .setChildren(Collections.singletonList(getTestCaseUuid(currentTestCase)));

    lifecycle.scheduleTestCase(result);
    lifecycle.startTestContainer(getTestContainerUuid(), resultContainer);
    lifecycle.startTestCase(getTestCaseUuid(currentTestCase));
}
 
Example #17
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private void handleTestCaseStarted(final TestCaseStarted event) {
    currentTestCase = event.testCase;
    currentFeatureFile = currentTestCase.getUri();
    currentFeature = cucumberSourceUtils.getFeature(currentFeatureFile);
    currentContainer = UUID.randomUUID().toString();
    forbidTestCaseStatusChange = false;


    final Deque<PickleTag> tags = new LinkedList<>(currentTestCase.getTags());

    final LabelBuilder labelBuilder = new LabelBuilder(currentFeature, currentTestCase, tags);

    final String name = currentTestCase.getName();
    final String featureName = currentFeature.getName();

    final TestResult result = new TestResult()
            .setUuid(getTestCaseUuid(currentTestCase))
            .setHistoryId(getHistoryId(currentTestCase))
            .setFullName(featureName + ": " + name)
            .setName(name)
            .setLabels(labelBuilder.getScenarioLabels())
            .setLinks(labelBuilder.getScenarioLinks());

    final ScenarioDefinition scenarioDefinition =
            cucumberSourceUtils.getScenarioDefinition(currentFeatureFile, currentTestCase.getLine());
    if (scenarioDefinition instanceof ScenarioOutline) {
        result.setParameters(
                getExamplesAsParameters((ScenarioOutline) scenarioDefinition)
        );
    }

    if (currentFeature.getDescription() != null && !currentFeature.getDescription().isEmpty()) {
        result.setDescription(currentFeature.getDescription());
    }

    final TestResultContainer resultContainer = new TestResultContainer()
            .setName(String.format("%s: %s", scenarioDefinition.getKeyword(), scenarioDefinition.getName()))
            .setUuid(getTestContainerUuid())
            .setChildren(Collections.singletonList(getTestCaseUuid(currentTestCase)));

    lifecycle.scheduleTestCase(result);
    lifecycle.startTestContainer(getTestContainerUuid(), resultContainer);
    lifecycle.startTestCase(getTestCaseUuid(currentTestCase));
}