Search in sources :

Example 1 with StepArgument

use of io.cucumber.plugin.event.StepArgument in project cucumber-jvm by cucumber.

the class SnippetGenerator method arguments.

private Map<String, Type> arguments(Step step, List<String> parameterNames, List<ParameterType<?>> parameterTypes) {
    Map<String, Type> arguments = new LinkedHashMap<>(parameterTypes.size() + 1);
    for (int i = 0; i < parameterTypes.size(); i++) {
        ParameterType<?> parameterType = parameterTypes.get(i);
        String parameterName = parameterNames.get(i);
        arguments.put(parameterName, parameterType.getType());
    }
    StepArgument arg = step.getArgument();
    if (arg == null) {
        return arguments;
    } else if (arg instanceof DocStringArgument) {
        arguments.put(parameterName("docString", parameterNames), String.class);
    } else if (arg instanceof DataTableArgument) {
        arguments.put(parameterName("dataTable", parameterNames), DataTable.class);
    }
    return arguments;
}
Also used : Type(java.lang.reflect.Type) ParameterType(io.cucumber.cucumberexpressions.ParameterType) StepArgument(io.cucumber.plugin.event.StepArgument) DataTableArgument(io.cucumber.plugin.event.DataTableArgument) LinkedHashMap(java.util.LinkedHashMap) DocStringArgument(io.cucumber.plugin.event.DocStringArgument)

Example 2 with StepArgument

use of io.cucumber.plugin.event.StepArgument in project cucumber-jvm by cucumber.

the class JsonFormatter method createTestStep.

private Map<String, Object> createTestStep(PickleStepTestStep testStep) {
    Map<String, Object> stepMap = new HashMap<>();
    stepMap.put("name", testStep.getStepText());
    stepMap.put("line", testStep.getStepLine());
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testStep.getStepLine());
    StepArgument argument = testStep.getStepArgument();
    if (argument != null) {
        if (argument instanceof DocStringArgument) {
            DocStringArgument docStringArgument = (DocStringArgument) argument;
            stepMap.put("doc_string", createDocStringMap(docStringArgument));
        } else if (argument instanceof DataTableArgument) {
            DataTableArgument dataTableArgument = (DataTableArgument) argument;
            stepMap.put("rows", createDataTableList(dataTableArgument));
        }
    }
    if (astNode != null) {
        Step step = (Step) astNode.node;
        stepMap.put("keyword", step.getKeyword());
    }
    return stepMap;
}
Also used : StepArgument(io.cucumber.plugin.event.StepArgument) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DataTableArgument(io.cucumber.plugin.event.DataTableArgument) TestStep(io.cucumber.plugin.event.TestStep) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) HookTestStep(io.cucumber.plugin.event.HookTestStep) Step(io.cucumber.messages.types.Step) DocStringArgument(io.cucumber.plugin.event.DocStringArgument)

Example 3 with StepArgument

use of io.cucumber.plugin.event.StepArgument 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)

Aggregations

StepArgument (io.cucumber.plugin.event.StepArgument)3 DataTableArgument (io.cucumber.plugin.event.DataTableArgument)2 DocStringArgument (io.cucumber.plugin.event.DocStringArgument)2 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)2 LinkedHashMap (java.util.LinkedHashMap)2 CucumberException (io.cucumber.core.exception.CucumberException)1 DataTableArgument (io.cucumber.core.gherkin.DataTableArgument)1 ParameterType (io.cucumber.cucumberexpressions.ParameterType)1 DataTableFormatter (io.cucumber.datatable.DataTableFormatter)1 Step (io.cucumber.messages.types.Step)1 HookTestStep (io.cucumber.plugin.event.HookTestStep)1 TestStep (io.cucumber.plugin.event.TestStep)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1