Functions
Chutney provides a set of procedures, or Functions
, you can use in your scenarios' expressions.
They allow to read scenarios and their executions reports with a better functional point of view.
You can see them as a set of aliases, allowing to simplify the processing of scenario execution context variables. 1
Those are based on spEL Functions.
Extending Chutney functions
Actions are extensible, and you can provide your own.
For further details, see how to implement your own function and then how to package Chutney with it.
Example🔗
Let's say you made an HTTP request which get some json movies' list and put it in context variable body
.
You now want to get the list of movie titles rated above 85/100 from it, in order to make an assertion.
Existing 'body' variable in context | |
---|---|
The best way to filter and extract the relevant data from a JSON document is to use a JSONPath expression.
Here is the one for our example : $.movies[?(@.rating > 85)].title
In order to process it, you would need to write code using a JSONPath library and then tell Chutney to run your custom code.
Here is a raw expression you could write :
${T(com.jayway.jsonpath.JsonPath).parse(#body).read("$.movies[?(@.rating > 85)].title")}
In this case you can use the jsonPath
function, provided by Chutney, and the resulting SpEL would become :
${#jsonPath(#body, '$.movies[?(@.rating > 85)].title')}