gherkin.pickles.PickleTable Java Examples

The following examples show how to use gherkin.pickles.PickleTable. 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 createTestStep(PickleStepTestStep testStep) {
    String stepName = testStep.getStepText();
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile.get(), testStep.getStepLine());
    if (astNode != null) {
        Step step = (Step) astNode.node;
        try {
            String name = stepName == null || stepName.isEmpty() 
                    ? step.getText().replace("<", "&lt;").replace(">", "&gt;")
                    : stepName;
            ExtentTest t = scenarioThreadLocal.get()
                    .createNode(new GherkinKeyword(step.getKeyword().trim()), step.getKeyword() + name, testStep.getCodeLocation());
            stepTestThreadLocal.set(t);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    if (!testStep.getStepArgument().isEmpty()) {
        Argument argument = testStep.getStepArgument().get(0);
        if (argument instanceof PickleString) {
            createDocStringMap((PickleString)argument);
        } else if (argument instanceof PickleTable) {
            List<PickleRow> rows = ((PickleTable) argument).getRows();
            stepTestThreadLocal.get().pass(MarkupHelper.createTable(getPickleTable(rows)).getMarkup());
        }
    }
}
 
Example #2
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void handleTestStepStarted(final TestStepStarted event) {
    if (!event.testStep.isHook()) {
        final String stepKeyword = Optional.ofNullable(
                cucumberSourceUtils.getKeywordFromSource(currentFeatureFile, event.testStep.getStepLine())
        ).orElse("UNDEFINED");

        final StepResult stepResult = new StepResult()
                .setName(String.format("%s %s", stepKeyword, event.testStep.getPickleStep().getText()))
                .setStart(System.currentTimeMillis());

        lifecycle.startStep(getTestCaseUuid(currentTestCase), getStepUuid(event.testStep), stepResult);

        event.testStep.getStepArgument().stream()
                .filter(PickleTable.class::isInstance)
                .findFirst()
                .ifPresent(table -> createDataTableAttachment((PickleTable) table));
    } else if (event.testStep instanceof UnskipableStep) {
        initHook((UnskipableStep) event.testStep);
    }
}
 
Example #3
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void createDataTableAttachment(final PickleTable pickleTable) {
    final List<PickleRow> rows = pickleTable.getRows();

    final StringBuilder dataTableCsv = new StringBuilder();
    if (!rows.isEmpty()) {
        rows.forEach(dataTableRow -> {
            dataTableCsv.append(
                    dataTableRow.getCells().stream()
                            .map(PickleCell::getValue)
                            .collect(Collectors.joining("\t"))
            );
            dataTableCsv.append('\n');
        });

        final String attachmentSource = lifecycle
                .prepareAttachment("Data table", "text/tab-separated-values", "csv");
        lifecycle.writeAttachment(attachmentSource,
                new ByteArrayInputStream(dataTableCsv.toString().getBytes(StandardCharsets.UTF_8)));
    }
}
 
Example #4
Source File: AllureCucumber4Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void handleTestStepStarted(final TestStepStarted event) {
    if (event.testStep instanceof PickleStepTestStep) {
        final PickleStepTestStep pickleStep = (PickleStepTestStep) event.testStep;
        final String stepKeyword = Optional.ofNullable(
                testSources.getKeywordFromSource(currentFeatureFile.get(), pickleStep.getStepLine())
        ).orElse("UNDEFINED");

        final StepResult stepResult = new StepResult()
                .setName(String.format("%s %s", stepKeyword, pickleStep.getPickleStep().getText()))
                .setStart(System.currentTimeMillis());

        lifecycle.startStep(getTestCaseUuid(currentTestCase.get()), getStepUuid(pickleStep), stepResult);

        pickleStep.getStepArgument().stream()
                .filter(PickleTable.class::isInstance)
                .findFirst()
                .ifPresent(table -> createDataTableAttachment((PickleTable) table));
    } else if (event.testStep instanceof HookTestStep) {
        initHook((HookTestStep) event.testStep);
    }
}
 
Example #5
Source File: AllureCucumber4Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void createDataTableAttachment(final PickleTable pickleTable) {
    final List<PickleRow> rows = pickleTable.getRows();

    final StringBuilder dataTableCsv = new StringBuilder();
    if (!rows.isEmpty()) {
        rows.forEach(dataTableRow -> {
            dataTableCsv.append(
                    dataTableRow.getCells().stream()
                            .map(PickleCell::getValue)
                            .collect(Collectors.joining("\t"))
            );
            dataTableCsv.append('\n');
        });

        final String attachmentSource = lifecycle
                .prepareAttachment("Data table", "text/tab-separated-values", "csv");
        lifecycle.writeAttachment(attachmentSource,
                new ByteArrayInputStream(dataTableCsv.toString().getBytes(StandardCharsets.UTF_8)));
    }
}
 
Example #6
Source File: AllureCucumber3Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void handleTestStepStarted(final TestStepStarted event) {
    if (event.testStep instanceof PickleStepTestStep) {
        final PickleStepTestStep pickleStep = (PickleStepTestStep) event.testStep;
        final String stepKeyword = Optional.ofNullable(
                cucumberSourceUtils.getKeywordFromSource(currentFeatureFile, pickleStep.getStepLine())
        ).orElse("UNDEFINED");

        final StepResult stepResult = new StepResult()
                .setName(String.format("%s %s", stepKeyword, pickleStep.getPickleStep().getText()))
                .setStart(System.currentTimeMillis());

        lifecycle.startStep(getTestCaseUuid(currentTestCase), getStepUuid(pickleStep), stepResult);

        pickleStep.getStepArgument().stream()
                .filter(PickleTable.class::isInstance)
                .findFirst()
                .ifPresent(table -> createDataTableAttachment((PickleTable) table));
    } else if (event.testStep instanceof HookTestStep) {
        initHook((HookTestStep) event.testStep);
    }
}
 
Example #7
Source File: AllureCucumber3Jvm.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void createDataTableAttachment(final PickleTable pickleTable) {
    final List<PickleRow> rows = pickleTable.getRows();

    final StringBuilder dataTableCsv = new StringBuilder();
    if (!rows.isEmpty()) {
        rows.forEach(dataTableRow -> {
            dataTableCsv.append(
                    dataTableRow.getCells().stream()
                            .map(PickleCell::getValue)
                            .collect(Collectors.joining("\t"))
            );
            dataTableCsv.append('\n');
        });

        final String attachmentSource = lifecycle
                .prepareAttachment("Data table", "text/tab-separated-values", "csv");
        lifecycle.writeAttachment(attachmentSource,
                new ByteArrayInputStream(dataTableCsv.toString().getBytes(StandardCharsets.UTF_8)));
    }
}
 
Example #8
Source File: DataTableUtils.java    From akita with Apache License 2.0 5 votes vote down vote up
public static DataTable dataTableFromLists(List<List<String>> lists) {
    List<PickleRow> rows = new ArrayList<>();
    lists.forEach(list -> {
        List<PickleCell> cells = new ArrayList<>();
        list.forEach(string -> {
            cells.add(new PickleCell(null,string));
        });
        rows.add(new PickleRow(cells));
    });
    return new DataTable(new PickleTable(rows), null);
}