gherkin.ast.Examples Java Examples

The following examples show how to use gherkin.ast.Examples. 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: TestSourcesModel.java    From extentreports-cucumber4-adapter with Apache License 2.0 6 votes vote down vote up
static String calculateId(AstNode astNode) {
    Node node = astNode.node;
    if (node instanceof ScenarioDefinition) {
        return calculateId(astNode.parent) + ";" + convertToId(((ScenarioDefinition) node).getName());
    }
    if (node instanceof ExamplesRowWrapperNode) {
        return calculateId(astNode.parent) + ";" + Integer.toString(((ExamplesRowWrapperNode) node).bodyRowIndex + 2);
    }
    if (node instanceof TableRow) {
        return calculateId(astNode.parent) + ";" + Integer.toString(1);
    }
    if (node instanceof Examples) {
        return calculateId(astNode.parent) + ";" + convertToId(((Examples) node).getName());
    }
    if (node instanceof Feature) {
        return convertToId(((Feature) node).getName());
    }
    return "";
}
 
Example #2
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 #3
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 #4
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 #5
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private void createTestData(TestCase testCase, List<Examples> examples) {
    for (Examples example : examples) {
        TestDataModel tdModel = createTestData(testCase.getName());
        List<String> columns = new ArrayList<>();
        for (TableCell tCell : example.getTableHeader().getCells()) {
            columns.add(tCell.getValue());
            tdModel.addColumn(tCell.getValue());
        }
        for (int i = 0; i < example.getTableBody().size(); i++) {
            TableRow tRow = example.getTableBody().get(i);
            tdModel.addRecord();
            Record record = tdModel.getRecords().get(i);
            record.setScenario(testCase.getScenario().getName());
            record.setTestcase(testCase.getName());
            record.setIteration("1");
            record.setSubIteration("" + (i + 1));
            for (int j = 0; j < tRow.getCells().size(); j++) {
                tdModel.setValueAt(tRow.getCells().get(j).getValue(),
                        i,
                        tdModel.getColumnIndex(columns.get(j)));
            }
        }
    }
}
 
Example #6
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 #7
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private void createExamples(Examples examples) {
    List<TableRow> rows = new ArrayList<>();
    rows.add(examples.getTableHeader());
    rows.addAll(examples.getTableBody());
    String[][] data = getTable(rows);
    String markup = MarkupHelper.createTable(data).getMarkup();
    if (examples.getName() != null && !examples.getName().isEmpty()) {
        markup = examples.getName() + markup;
    }
    markup = scenarioOutlineThreadLocal.get().getModel().getDescription() + markup;
    scenarioOutlineThreadLocal.get().getModel().setDescription(markup);
}