private CucumberException registerTypeInConfiguration(Exception e) { return new CucumberException(String.format("" + "Could not convert arguments for step [%s] defined at '%s'.\n" + "It appears you did not register a data table type. The details are in the stacktrace below.", //TODO: Add doc URL stepDefinition.getPattern(), stepDefinition.getLocation(true) ), e); }
private List<PickleStepDefinitionMatch> stepDefinitionMatches(String featurePath, PickleStep step) { List<PickleStepDefinitionMatch> result = new ArrayList<PickleStepDefinitionMatch>(); for (StepDefinition stepDefinition : stepDefinitionsByPattern.values()) { List<Argument> arguments = stepDefinition.matchedArguments(step); if (arguments != null) { result.add(new PickleStepDefinitionMatch(arguments, stepDefinition, featurePath, step)); } } return result; }
Throwable removeFrameworkFramesAndAppendStepLocation(Throwable error, StackTraceElement stepLocation) { StackTraceElement[] stackTraceElements = error.getStackTrace(); if (stackTraceElements.length == 0 || stepLocation == null) { return error; } int newStackTraceLength; for (newStackTraceLength = 1; newStackTraceLength < stackTraceElements.length; ++newStackTraceLength) { if (stepDefinition.isDefinedAt(stackTraceElements[newStackTraceLength - 1])) { break; } } StackTraceElement[] newStackTrace = new StackTraceElement[newStackTraceLength + 1]; System.arraycopy(stackTraceElements, 0, newStackTrace, 0, newStackTraceLength); newStackTrace[newStackTraceLength] = stepLocation; error.setStackTrace(newStackTrace); return error; }
public StepDefinitionDTO(UUID glueId, long id, StepDefinition stepDefinition) { this.glueId = glueId; this.id = id; this.pattern = stepDefinition.getPattern(); this.parameterCount = stepDefinition.getParameterCount(); this.location = stepDefinition.getLocation(false); this.detailedLocation = stepDefinition.getLocation(true); }
@Override public void runStep(Scenario scenario) throws Throwable { int argumentCount = getArguments().size(); Integer parameterCount = stepDefinition.getParameterCount(); if (parameterCount != null && argumentCount != parameterCount) { throw arityMismatch(parameterCount); } List<Object> result = new ArrayList<>(); try { for (Argument argument : getArguments()) { result.add(argument.getValue()); } } catch (UndefinedDataTableTypeException e) { throw registerTypeInConfiguration(e); } catch (CucumberExpressionException | CucumberDataTableException e) { throw couldNotConvertArguments(e); } try { stepDefinition.execute(result.toArray(new Object[0])); } catch (CucumberException e) { throw e; } catch (Throwable t) { throw removeFrameworkFramesAndAppendStepLocation(t, getStepLocation()); } }
public PickleStepDefinitionMatch(List<Argument> arguments, StepDefinition stepDefinition, String featurePath, PickleStep step) { super(arguments, stepDefinition.getLocation(false)); this.stepDefinition = stepDefinition; this.featurePath = featurePath; this.step = step; }
public String getPattern() { return stepDefinition.getPattern(); }
public ExecutionResult execute(UUID uuid, long id, StepDefinitionInvocation stepDefinitionInvocation) throws Throwable { SimpleGlue glue = glues.get(uuid); StepDefinition stepDefinition = glue.stepDefinition(id); LocalizedXStreams xStreams = new LocalizedXStreams(Thread.currentThread().getContextClassLoader()); try { String isoCode = stepDefinitionInvocation.getIsoCode(); I18n i18n = new I18n(isoCode); stepDefinition.execute(i18n, stepDefinitionInvocation.getArgs(xStreams.get(i18n.getLocale()), stepDefinition)); } catch (Exception e) { return new StepExecutionResult(e); } return new StepExecutionResult(); }
private void removeScenariosScopedStepDefinitions(Map<String, StepDefinition> stepDefinitions) { Iterator<Map.Entry<String, StepDefinition>> stepDefinitionIterator = stepDefinitions.entrySet().iterator(); while(stepDefinitionIterator.hasNext()){ StepDefinition stepDefinition = stepDefinitionIterator.next().getValue(); if(stepDefinition.isScenarioScoped()){ stepDefinitionIterator.remove(); } } } }
protected ParameterInfo getParameterType(StepDefinition stepDefinition, int n, Type argumentType) { ParameterInfo parameterInfo = stepDefinition.getParameterType(n, argumentType); if (parameterInfo == null) { // Some backends return null because they don't know parameterInfo = new ParameterInfo(argumentType, null, null, false, null); } return parameterInfo; } }
@Override public String getCodeLocation() { return stepDefinition.getLocation(false); }
@Override public void addStepDefinition(StepDefinition stepDefinition) { StepDefinition previous = stepDefinitionsByPattern.get(stepDefinition.getPattern()); if (previous != null) { throw new DuplicateStepDefinitionException(previous, stepDefinition); } stepDefinitionsByPattern.put(stepDefinition.getPattern(), stepDefinition); }
private CucumberException couldNotConvertArguments(Exception e) { return new CucumberException(String.format( "Could not convert arguments for step [%s] defined at '%s'.\n" + "The details are in the stacktrace below.", stepDefinition.getPattern(), stepDefinition.getLocation(true) ), e); }
private static String createMessage(StepDefinition a, StepDefinition b) { return String.format("Duplicate step definitions in %s and %s", a.getLocation(true), b.getLocation(true)); } }
PickleStepDefinitionMatch stepDefinitionMatch(String featurePath, PickleStep step) { String stepText = step.getText(); StepDefinition stepDefinition = stepDefinitionsByStepText.get(stepText); if (stepDefinition != null) { // Step definition arguments consists of parameters included in the step text and // gherkin step arguments (doc string and data table) which are not included in // the step text. As such the step definition arguments can not be cached and // must be recreated each time. List<Argument> arguments = stepDefinition.matchedArguments(step); return new PickleStepDefinitionMatch(arguments, stepDefinition, featurePath, step); } List<PickleStepDefinitionMatch> matches = stepDefinitionMatches(featurePath, step); if (matches.isEmpty()) { return null; } if (matches.size() > 1) { throw new AmbiguousStepDefinitionsException(step, matches); } PickleStepDefinitionMatch match = matches.get(0); stepDefinitionsByStepText.put(stepText, match.getStepDefinition()); return match; }
private CucumberException arityMismatch(int parameterCount) { List<String> arguments = createArgumentsForErrorMessage(); return new CucumberException(String.format( "Step [%s] is defined with %s parameters at '%s'.\n" + "However, the gherkin step has %s arguments%sStep text: %s", stepDefinition.getPattern(), parameterCount, stepDefinition.getLocation(true), arguments.size(), formatArguments(arguments), step.getText() )); }
public StepMatchDTO matchedArguments(UUID uuid, long id, StepDTO stepProxy) throws Throwable { SimpleGlue glue = glues.get(uuid); StepDefinition stepDefinition = glue.stepDefinition(id); List<Argument> matchedArguments = stepDefinition.matchedArguments(stepProxy.toStep()); return new StepMatchDTO(matchedArguments); }