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;
}
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;
}
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);
}
}
}
}
Aggregations