private String getStepKeyword(PickleStepTestStep testStep) { TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testStep.getStepLine()); if (astNode != null) { Step step = (Step) astNode.node; return step.getKeyword(); } else { return ""; } }
private Map<String, Object> createTestStep(PickleStepTestStep testStep) { Map<String, Object> stepMap = new HashMap<String, Object>(); stepMap.put("name", testStep.getStepText()); if (!testStep.getStepArgument().isEmpty()) { Argument argument = testStep.getStepArgument().get(0); if (argument instanceof PickleString) { stepMap.put("doc_string", createDocStringMap((PickleString)argument)); } else if (argument instanceof PickleTable) { stepMap.put("rows", createDataTableList((PickleTable)argument)); } } TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testStep.getStepLine()); if (astNode != null) { Step step = (Step) astNode.node; stepMap.put("keyword", step.getKeyword()); } return stepMap; }
private Map<String, Object> createTestStep(PickleStepTestStep testStep) { Map<String, Object> stepMap = new HashMap<String, Object>(); stepMap.put("name", testStep.getStepText()); stepMap.put("line", testStep.getStepLine()); TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testStep.getStepLine()); if (!testStep.getStepArgument().isEmpty()) { Argument argument = testStep.getStepArgument().get(0); if (argument instanceof PickleString) { stepMap.put("doc_string", createDocStringMap(argument)); } else if (argument instanceof PickleTable) { stepMap.put("rows", createDataTableList(argument)); } } if (astNode != null) { Step step = (Step) astNode.node; stepMap.put("keyword", step.getKeyword()); } return stepMap; }
private String getKeywordFromSource(String path, List<PickleLocation> stepLocations) { if (!pathToStepMap.containsKey(path)) { createFeatureStepMap(path); } if (!pathToStepMap.containsKey(path)) { return null; } GherkinDialect featureDialect = pathToStepMap.get(path).dialect; List<String> givenThenWhenKeywords = getGivenWhenThenKeywords(featureDialect); Map<Integer, StepNode> stepMap = pathToStepMap.get(path).stepMap; for (PickleLocation stepLocation : stepLocations) { if (!stepMap.containsKey(stepLocation.getLine())) { continue; } for (StepNode stepNode = stepMap.get(stepLocation.getLine()); stepNode != null; stepNode = stepNode.previous) { for (String keyword : givenThenWhenKeywords) { if (!keyword.equals("* ") && keyword == stepNode.step.getKeyword()) { return convertToCodeKeyword(keyword); } } } } return getFirstGivenKeyword(featureDialect); }
private void addOutlineStepsToReport(ScenarioOutline scenarioOutline) { for (Step step : scenarioOutline.getSteps()) { Map<String, Object> stepMap = new HashMap<String, Object>(); stepMap.put("name", step.getText()); stepMap.put("keyword", step.getKeyword()); if (step.getArgument() != null) { Node argument = step.getArgument(); if (argument instanceof DocString) { stepMap.put("doc_string", createDocStringMap((DocString)argument)); } else if (argument instanceof DataTable) { stepMap.put("rows", createDataTableList((DataTable)argument)); } } jsFunctionCall("step", stepMap); } }
private void printScenarioOutline(ScenarioOutline scenarioOutline) { out.println(); printTags(scenarioOutline.getTags(), SCENARIO_INDENT); out.println(SCENARIO_INDENT + getScenarioDefinitionText(scenarioOutline) + " " + getLocationText(currentFeatureFile, scenarioOutline.getLocation().getLine())); printDescription(scenarioOutline.getDescription()); for (Step step : scenarioOutline.getSteps()) { out.println(STEP_INDENT + formats.get("skipped").text(step.getKeyword() + step.getText())); } }
private void setTableScenarioOutline() { List<Step> steps = currentScenarioDefinition.getSteps(); StringBuffer scenarioOutlineBuffer = new StringBuffer(); for (Step step : steps) { scenarioOutlineBuffer.append(step.getKeyword()).append(step.getText()).append("\n\r"); } String scenarioOutline = scenarioOutlineBuffer.toString(); if (table != null) { table.setScenarioOutline(scenarioOutline); } }
private void setTableScenarioOutline() { List<Step> steps = currentScenarioDefinition.getSteps(); StringBuffer scenarioOutlineBuffer = new StringBuffer(); for (Step step : steps) { scenarioOutlineBuffer.append(step.getKeyword()).append(step.getText()).append("\n\r"); } String scenarioOutline = scenarioOutlineBuffer.toString(); if (table != null) { table.setScenarioOutline(scenarioOutline); } }
private Step concreteStep(Step abstractStep, Map<String, String> parameters) { String text = abstractStep.getText(); for (Entry<String, String> entry : parameters.entrySet()) { String target = String.format("<%s>", entry.getKey()); String replacement = entry.getValue(); text = text.replace(target, replacement); } return new Step( abstractStep.getLocation(), abstractStep.getKeyword(), text, abstractStep.getArgument()); } }
private String stepToString(Step step) { String phrase = step.getKeyword() + step.getText(); if ((step.getArgument() != null) && (step.getArgument().getClass().isAssignableFrom(gherkin.ast.DataTable.class))) { gherkin.ast.DataTable table = (gherkin.ast.DataTable) step.getArgument(); String tableAsString = ""; for (TableRow row : table.getRows()) { tableAsString += "|"; tableAsString += row.getCells().stream() .map(TableCell::getValue) .collect(Collectors.joining(" | ")); tableAsString += "|" + System.lineSeparator(); } phrase = phrase + System.lineSeparator() + tableAsString.trim(); } return phrase; } }
private String stepToString(Step step) { String phrase = step.getKeyword() + step.getText(); if ((step.getArgument() != null) && (step.getArgument().getClass().isAssignableFrom(gherkin.ast.DataTable.class))) { gherkin.ast.DataTable table = (gherkin.ast.DataTable) step.getArgument(); String tableAsString = ""; for (TableRow row : table.getRows()) { tableAsString += "|"; tableAsString += row.getCells().stream() .map(TableCell::getValue) .collect(Collectors.joining(" | ")); tableAsString += "|" + System.lineSeparator(); } phrase = phrase + System.lineSeparator() + tableAsString.trim(); } return phrase; } }
private PickleLocation pickleStepLocation(Step step) { return new PickleLocation( step.getLocation().getLine(), step.getLocation().getColumn() + (step.getKeyword() != null ? SymbolCounter.countSymbols(step.getKeyword()) : 0) ); }
private String stepTitleFrom(Step currentStep, TestStep testStep) { if (currentStep != null) return currentStep.getKeyword() //TODO get Name + testStep.getPickleStep().getText() + embeddedTableDataIn(testStep); return ""; }
private String stepTitleFrom(Step currentStep, TestStep testStep) { if (currentStep != null) return currentStep.getKeyword() //TODO get Name + testStep.getPickleStep().getText() + embeddedTableDataIn(testStep); return ""; }
/** * Converts a list of Gherkin steps to Cucable steps including data tables. * * @param gherkinSteps a {@link Step} list. * @return a {@link com.trivago.vo.Step} list. */ List<com.trivago.vo.Step> convertGherkinStepsToCucableSteps(final List<Step> gherkinSteps) { List<com.trivago.vo.Step> steps = new ArrayList<>(); for (Step gherkinStep : gherkinSteps) { com.trivago.vo.Step step; com.trivago.vo.DataTable dataTable = null; String docString = null; Node argument = gherkinStep.getArgument(); if (argument instanceof DataTable) { dataTable = convertGherkinDataTableToCucableDataTable((DataTable) argument); } else if (argument instanceof DocString) { docString = ((DocString) argument).getContent(); } String keywordAndName = gherkinStep.getKeyword().concat(gherkinStep.getText()); step = new com.trivago.vo.Step(keywordAndName, dataTable, docString); steps.add(step); } return steps; }
private void addSteps(List<Step> replacementSteps) { for (Step replacementStep : replacementSteps) { addStep(step.getLocation(), replacementStep.getKeyword(), replacementStep.getText(), replacementStep.getArgument()); } }
private void processStep(Step step, List<StepDefinition> stepDefinitions) { String keyword = step.getKeyword().trim(); String text = step.getText().trim(); Node argument = step.getArgument(); testLog.logStep(keyword, text); for (StepDefinition stepDefinition : stepDefinitions) { if (stepDefinition.matches(text)) { stepDefinition.invoke(text, argument); return; } } throw new StepDefinitionNotFoundException(keyword, text); } }
public static String step(Step step) { return step.getKeyword() + withEscapedParameterFields(step.getText()) + " " + renderedArgument(step.getArgument()); }
List<Step> replaceWith(List<Step> replacementSteps) { List<Map<String, String>> dataTable = FragmentDataTableUtils.getDataTable(step); if (dataTable.isEmpty()) { addSteps(replacementSteps); return replacedSteps; } for (Map<String, String> dataTableRow : dataTable) { for (Step replacementStep : replacementSteps) { String text = FragmentDataTableUtils.applyToText(dataTableRow, replacementStep.getText()); DataTable argument = null; if (replacementStep.getArgument() != null) { argument = FragmentDataTableUtils.applyToArgument(dataTableRow, replacementStep); } addStep(step.getLocation(), replacementStep.getKeyword(), text, argument); } } return replacedSteps; }