Search in sources :

Example 1 with DataTableArgument

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

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

Aggregations

DataTableArgument (io.cucumber.plugin.event.DataTableArgument)2 DocStringArgument (io.cucumber.plugin.event.DocStringArgument)2 StepArgument (io.cucumber.plugin.event.StepArgument)2 LinkedHashMap (java.util.LinkedHashMap)2 ParameterType (io.cucumber.cucumberexpressions.ParameterType)1 Step (io.cucumber.messages.types.Step)1 HookTestStep (io.cucumber.plugin.event.HookTestStep)1 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)1 TestStep (io.cucumber.plugin.event.TestStep)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1