/** * Generate multiline argument (DataTable or DocString) representation * * @param step - Cucumber step object * @return - transformed multiline argument (or empty string if there is * none) */ public static String buildMultilineArgument(Step step) { List<DataTableRow> table = step.getRows(); DocString ds = step.getDocString(); StringBuilder marg = new StringBuilder(); if (table != null) { marg.append("\r\n"); for (Row row : table) { marg.append(TABLE_SEPARATOR); for (String cell : row.getCells()) { marg.append(" ").append(cell).append(" ").append(TABLE_SEPARATOR); } marg.append("\r\n"); } } if (ds != null) { marg.append(DOCSTRING_DECORATOR).append(ds.getValue()).append(DOCSTRING_DECORATOR); } return marg.toString(); } }
public void step(Step step) { out.append(step.getKeyword()+step.getName()).append("\n"); writeRows(step.getRows()); }
@Override public void step(Step step) { if (lineOffset != 0 && isPreview) { int newLine = step.getLine().intValue() + lineOffset.intValue(); featureLineOffset.put(step.getLine().intValue(), newLine); step = new Step(step.getComments(), step.getKeyword(), step.getName(), newLine, step.getRows(), step.getDocString()); } if (step.getRows() != null && step.getRows().get(0) != null && !step.getRows().get(0).getComments().isEmpty()) { String filePathFromComment = getExtractFilePathFromComment(step.getRows().get(0).getComments().get(0).getValue()); Resource sourceResource = getSourceResource(filePathFromComment); if (sourceResource != null) { step = loadAndReplaceSteps(step, filePathFromComment, sourceResource); } } super.step(step); prettyFormatter.step(step); }
@Override public Range getLineRange() { Range range = super.getLineRange(); if (getRows() != null) { range = new Range(range.getFirst(), getRows().get(getRows().size() - 1).getLine()); } else if (getDocString() != null) { range = new Range(range.getFirst(), getDocString().getLineRange().getLast()); } return range; }
public StepDTO(Step step) { this.comments = CommentDTO.fromGherkinComments(step.getComments()); this.keyword = step.getKeyword(); this.name = step.getName(); this.line = step.getLine(); if (step.getRows() != null) { this.rows = new ArrayList<DataTableRowDTO>(); for (DataTableRow gherkinRow : step.getRows()) { this.rows.add(new DataTableRowDTO(gherkinRow)); } } if (step.getDocString() != null) { this.docString = new DocStringDTO(step.getDocString()); } }
@Override public void match(Match match) { if (match instanceof StepDefinitionMatch) { this.match = (StepDefinitionMatch) match; Step step = extractStep(this.match); synchronized (gherkinSteps) { while (gherkinSteps.peek() != null && !isEqualSteps(step, gherkinSteps.peek())) { fireCanceledStep(gherkinSteps.remove()); } if (isEqualSteps(step, gherkinSteps.peek())) { gherkinSteps.remove(); } } String name = this.getStepName(step); ALLURE_LIFECYCLE.fire(new StepStartedEvent(name).withTitle(name)); createDataTableAttachment(step.getRows()); } }
public void step(Step step) { if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Step: " + step.getKeyword() + " " + step.getName()); LOG.log(Level.FINE, " " + step.getRows()); // logger.fine(" " + step.getStackTraceElement()); } if (currentStep != null) { String error = "Step: {" + step.getKeyword() + "} name: {" + step.getName() + "} received before previous step: {" + step.getKeyword() + "} name: {" + step.getName() + "} handled! Maybe caused by broken JSON, see #JENKINS-21835"; listener.error(error); LOG.log(Level.SEVERE, error); if (!ignoreBadSteps) { throw new CucumberModelException(error); } } currentStep = step; }
private void printStep(String status, List<Argument> arguments, String location) { Step step = steps.remove(0); Format textFormat = getFormat(status); Format argFormat = getArgFormat(status); printComments(step.getComments(), " "); StringBuilder buffer = new StringBuilder(" "); buffer.append(textFormat.text(step.getKeyword())); stepPrinter.writeStep(new NiceAppendable(buffer), textFormat, argFormat, step.getName(), arguments); buffer.append(indentedLocation(location)); out.println(buffer); if (step.getRows() != null) { table(step.getRows()); } else if (step.getDocString() != null) { docString(step.getDocString()); } }
@Override public void match(final Match match) { final StepUtils stepUtils = new StepUtils(currentFeature, currentScenario); if (match instanceof StepDefinitionMatch) { isNullMatch = false; final Step step = stepUtils.extractStep((StepDefinitionMatch) match); synchronized (gherkinSteps) { while (gherkinSteps.peek() != null && !stepUtils.isEqualSteps(step, gherkinSteps.peek())) { stepUtils.fireCanceledStep(gherkinSteps.remove()); } if (stepUtils.isEqualSteps(step, gherkinSteps.peek())) { gherkinSteps.remove(); } } final StepResult stepResult = new StepResult(); stepResult.setName(String.format("%s %s", step.getKeyword(), getStepName(step))) .setStart(System.currentTimeMillis()); final String scenarioUuid = scenarioUuids.get(currentScenario); lifecycle.startStep(scenarioUuid, stepUtils.getStepUuid(step), stepResult); createDataTableAttachment(step.getRows()); } }
private Step loadAndReplaceSteps(Step step, String filePathFromComment, Resource sourceResource) { DataReader dataReader; try { InputStream inputStream = sourceResource.getInputStream(); dataReader = DataReaderFactory.create(sourceResource.getFilename()); DataDTO data = dataReader.readTable(inputStream); List<DataTableRow> rows = Lists.newArrayList(); for (Integer lineNum : data.getValues().keySet()) { List<String> cells = Lists.newArrayList(data.getValues().get(lineNum)); String valueComment = String.format("# %s:%d", filePathFromComment, lineNum + 1); Comment comment = new Comment(valueComment, lineNum); List<Comment> comments = Lists.newArrayList(comment); int newLineNum = step.getLine() + 2; if (isPreview) { newLineNum += lineOffset; } DataTableRow row = new DataTableRow(comments, cells, newLineNum + 1); rows.add(row); lineOffset += 2; } // re-calculate lineOffset lineOffset = lineOffset - step.getRows().size() - 1; step = new Step(step.getComments(), step.getKeyword(), step.getName(), step.getLine(), rows, step.getDocString()); } catch (InstantiationException | IllegalAccessException | IOException e) { throw Throwables.propagate(e); } return step; }
public StepExec convertStep(Step step) { StepExec stepExec = new StepExec(step.getKeyword(), step.getName()); stepExec.declareComments(convertComments(step.getComments())); DocString docString = step.getDocString(); if (docString != null) { stepExec.declareDocString(docString.getValue()); } stepExec.declareTable(convertTable(step.getRows())); return stepExec; }
@Override public Description getDescription() { if (description == null) { description = Description.createSuiteDescription(getName(), cucumberScenario.getGherkinModel()); if (cucumberScenario.getCucumberBackground() != null) { for (Step backgroundStep : cucumberScenario.getCucumberBackground().getSteps()) { // We need to make a copy of that step, so we have a unique one per scenario Step copy = new Step( backgroundStep.getComments(), backgroundStep.getKeyword(), backgroundStep.getName(), backgroundStep.getLine(), backgroundStep.getRows(), backgroundStep.getDocString() ); description.addChild(describeChild(copy)); runnerSteps.add(copy); } } for (Step step : getChildren()) { description.addChild(describeChild(step)); runnerSteps.add(step); } } return description; }
@Override public Description getDescription() { if (description == null) { description = Description.createSuiteDescription(getName(), cucumberScenario.getGherkinModel()); if (cucumberScenario.getCucumberBackground() != null) { for (Step backgroundStep : cucumberScenario.getCucumberBackground().getSteps()) { // We need to make a copy of that step, so we have a unique one per scenario Step copy = new Step( backgroundStep.getComments(), backgroundStep.getKeyword(), backgroundStep.getName(), backgroundStep.getLine(), backgroundStep.getRows(), backgroundStep.getDocString() ); description.addChild(describeChild(copy)); runnerSteps.add(copy); } } for (Step step : getChildren()) { description.addChild(describeChild(step)); runnerSteps.add(step); } } return description; }