Search in sources :

Example 1 with DataTableArgument

use of io.cucumber.core.gherkin.DataTableArgument in project cucumber-jvm by cucumber.

the class PrettyFormatter method printStep.

private void printStep(TestStepFinished event) {
    if (event.getTestStep() instanceof PickleStepTestStep) {
        PickleStepTestStep testStep = (PickleStepTestStep) event.getTestStep();
        String keyword = testStep.getStep().getKeyword();
        String stepText = testStep.getStep().getText();
        String status = event.getResult().getStatus().name().toLowerCase(ROOT);
        String formattedStepText = formatStepText(keyword, stepText, formats.get(status), formats.get(status + "_arg"), testStep.getDefinitionArgument());
        String locationComment = formatLocationComment(event, testStep, keyword, stepText);
        out.println(STEP_INDENT + formattedStepText + locationComment);
        StepArgument stepArgument = testStep.getStep().getArgument();
        if (DataTableArgument.class.isInstance(stepArgument)) {
            DataTableFormatter tableFormatter = DataTableFormatter.builder().prefixRow(STEP_SCENARIO_INDENT).escapeDelimiters(false).build();
            DataTableArgument dataTableArgument = (DataTableArgument) stepArgument;
            try {
                tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out);
            } catch (IOException e) {
                throw new CucumberException(e);
            }
        }
    }
}
Also used : DataTableFormatter(io.cucumber.datatable.DataTableFormatter) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) StepArgument(io.cucumber.plugin.event.StepArgument) DataTableArgument(io.cucumber.core.gherkin.DataTableArgument) IOException(java.io.IOException) CucumberException(io.cucumber.core.exception.CucumberException)

Example 2 with DataTableArgument

use of io.cucumber.core.gherkin.DataTableArgument in project cucumber-jvm by cucumber.

the class ArgumentMatcher method argumentsFrom.

public List<Argument> argumentsFrom(Step step, Type... types) {
    io.cucumber.core.gherkin.Argument arg = step.getArgument();
    if (arg == null) {
        return expression.match(step.getText(), types);
    }
    if (arg instanceof io.cucumber.core.gherkin.DocStringArgument) {
        DocStringArgument docString = (DocStringArgument) arg;
        String content = docString.getContent();
        String contentType = docString.getMediaType();
        return expression.match(step.getText(), content, contentType, types);
    }
    if (arg instanceof io.cucumber.core.gherkin.DataTableArgument) {
        DataTableArgument table = (DataTableArgument) arg;
        List<List<String>> cells = emptyCellsToNull(table.cells());
        return expression.match(step.getText(), cells, types);
    }
    throw new IllegalStateException("Argument was neither PickleString nor PickleTable");
}
Also used : DataTableArgument(io.cucumber.core.gherkin.DataTableArgument) List(java.util.List) DocStringArgument(io.cucumber.core.gherkin.DocStringArgument)

Example 3 with DataTableArgument

use of io.cucumber.core.gherkin.DataTableArgument in project cucumber-jvm by cucumber.

the class FeatureParserTest method empty_table_is_parsed.

@Test
void empty_table_is_parsed() throws IOException {
    URI uri = URI.create("classpath:com/example.feature");
    String source = new String(readAllBytes(Paths.get("src/test/resources/io/cucumber/core/gherkin/messages/empty-table.feature")));
    Feature feature = parser.parse(uri, source, UUID::randomUUID).get();
    Pickle pickle = feature.getPickles().get(0);
    Step step = pickle.getSteps().get(0);
    DataTableArgument argument = (DataTableArgument) step.getArgument();
    assertEquals(5, argument.getLine());
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) DataTableArgument(io.cucumber.core.gherkin.DataTableArgument) Step(io.cucumber.core.gherkin.Step) URI(java.net.URI) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

DataTableArgument (io.cucumber.core.gherkin.DataTableArgument)3 CucumberException (io.cucumber.core.exception.CucumberException)1 DocStringArgument (io.cucumber.core.gherkin.DocStringArgument)1 Feature (io.cucumber.core.gherkin.Feature)1 Pickle (io.cucumber.core.gherkin.Pickle)1 Step (io.cucumber.core.gherkin.Step)1 DataTableFormatter (io.cucumber.datatable.DataTableFormatter)1 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)1 StepArgument (io.cucumber.plugin.event.StepArgument)1 IOException (java.io.IOException)1 URI (java.net.URI)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1