Dynamic responses: Supported helper functions

Helper functions let you control the format, appearance, and other factors related to the output data of a dynamic response in your Service virtualization transactions in the asset catalog. To learn more, see Add parameter options and dynamic responses to transactions.

Request Helpers

Name

Description

Example

request.query.<key>

Returns the value of the query parameter with the specified key

${request.query.status}

Returns the value of “status” query parameter.

Example:

http://localhost:80/test?status=InProgress

This request returns the following response:

InProgress

request.headers.<key>

Returns the value of the request header with the specified key.

${request.header.Accept}

Returns the value of the request header “Accept” .


Example:
http://localhost:80/test
This request with an Accept header of application/json returns the following response:
application/json

request.cookies.<key>

Returns the value of the cookie with the specified key.

${request.cookies.JSESSIONID}

Returns the value of the request header “JSESSIONID” .

Example:

http://localhost:80/test

This request with the JSESSIONID cookie value of 1A530637289A03B07199A44E8D531427 returns the following response:

1A530637289A03B07199A44E8D531427

request.body

Returns the value of the body.

s
${request.body}

Example:

Post request http://localhost:80/test with a request body value of:
“PING”

This request returns the following response:
“PING”

String helpers

Name

Description

Example

Example response


capitalizeFirst
Capitalizes the first character of the value ${capitalizeFirst "hello world"} Hello world
center Centers the value in a field of a given width ${center "hello world" size=19 pad="-"} ----hello world----
cut Removes all values of an argument from the given string ${cut "hello world" "d"} hello worl
defaultlfEmpty If value evaluates to False, uses the given default. Otherwise, uses the value ${defaultlfEmpty "" "none"} none
join Joins an array, iterator, or an iterable with a string ${join "a" "b" "c" " // "} a // b // c
ljust Left aligns the value in a field of a given width ${ljust "Hello" size=10 pad=" "} “Hello “
rjust Right aligns the value in a field of a given width ${rjust "Hello" size=10 pad=" "} “ Hello”
substring Returns a new string that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1 ${substring "Hello World" 0 5} Hello
lower Converts a string into all lowercase ${lower "HEllo"} hello
upper Converts a string into all uppercase ${upper "hellO"} HELLO
slugify Converts to lowercase, removes non-word characters (alphanumerics and underscores), and converts spaces to hyphens. Also strips leading and trailing whitespace ${slugify "Hello World"} hello-world
stringFormat Formats the variable according to the argument, a string formatting specifier ${stringFormat "Hello %s" "world"} Hello World
stripTags Strips all [X]HTML tags ${stripTags "<html><body><dummy>hello world</dummy></body></html>"} hello world
capitalize Capitalizes all the whitespace separated words in a String ${ capitalize "hello world"} Hello World
abbreviate Truncates a string if it is longer than the specified number of characters. Truncated strings end with a translatable ellipsis sequence ("..."). Argument: Number of characters to truncate to ${abbreviate "Hello World" 8} Hello...
wordWrap Wraps words at the specified line length. Argument: number of characters at which to wrap the text ${wordWrap "Lorem ipsum dolor sit amet, consectetur adipiscing elit." 14}

Lorem ipsum

dolor sit

amet,

consectetur

adipiscing

elit.

replace Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence ${ replace "Hello ..." "..." "world" } Hello world
yesno Maps values that resolve to true, false, and (optionally) null, to the strings "yes", "no", and "maybe", or given custom strings ${yesno true yes="Hello" no="world" maybe="none"} Hello
numberFormat

Format parameters is one of:

  • "integer": the integer number format

  • "percent": the percent number format

  • "currency"

${numberFormat .24 "percent"} 24%

Number helpers

Name

Description

Example

Example response

isEven

Returns a value only if the first argument is even. Otherwise, return null

${isEven 2 "Hello"}

Hello

isOdd

Returns a value only if the first argument is odd. Otherwise, return null

${isOdd 3 "World"}

World

stripes

Returns a different value if the passed argument is odd or even

${stripes 2 "Hello" "World"}

Hello

Conditional helpers

Name

Description

Example

Example response

eq

Tests if two elements are equals

${#eq request.path.0 "hello"}

"Hello is in the path"

${else}

"Hello is not in the path"

${/eq}

Returns “Hello is in the path” if the first part of the request’s path is equal to “Hello”; else returns "Hello is not in the path"

neq

Tests if two elements are NOT equals

${#neq request.path.0 "hello"}

"Hello is not in the path"

${else}

"Hello is in the path"

${/neq}

Returns “Hello is in the path” if the first part of the request’s path is equal to “Hello”; else returns "Hello is not in the path"

gt

Tests if the first argument is greater than the second one

${#gt request.path.0 "hi"}

"hello is lexicographically greater than hi"

${else}

"Hello is not lexicographically greater than hi"

${/gt}

Returns “hello is lexicographically greater than hi” if the first part of the request’s path is lexicographically greater than “hi”; else returns “Hello is not lexicographically greater than hi"

gte

Tests if the first argument is greater than or equal to the second one

${#gt request.path.0 "hi"}

"hello is lexicographically greater than hi"

${else}

"Hello is not lexicographically greater than hi"

${/gt}

Returns “hello is lexicographically greater than hi” if the first part of the request’s path is lexicographically greater than or equal to “hi”; else returns “Hello is not lexicographically greater than hi"

lt

Tests if the first argument is less than the second one

${#lt request.path.0 "hi"}

"hello is lexicographically lesser than hi"

${else}

"Hello is not lexicographically lesser than hi"

${/lt}

Returns “hello is lexicographically lesser than hi” if the first part of the request’s path is lexicographically lesser than “hi”; else returns “Hello is not lexicographically lesser than hi"

lte

Tests if the first argument is less than or equal to the second one

${#lte request.path.0 "hi"}

"hello is lexicographically lesser than hi"

${else}

"Hello is not lexicographically lesser than hi"

${/lte}

Returns “hello is lexicographically lesser than hi” if the first part of the request’s path is lexicographically lesser than or equal to “hi”; else returns “Hello is not lexicographically lesser than hi"

and

Truth of arguments is determined by isEmpty(), so this helper can be used with non-boolean values. Multiple values can also be specified

${#and true "NonEmptyString" 10 request.path.0}

Yes

${else}

No

${/and}

Returns “Yes”, as all the arguments evaluate to true

or

Truth of arguments is determined by isEmpty(), so this helper can be used with non-boolean values. Multiple values can also be specified

${#or false "NonEmptyString"}

Yes

${else}

No

${/or}

Returns “Yes”, as the second arguments evaluate to true

not

Truth of arguments is determined by isEmpty(), so this helper can be used with non-boolean values

${#not false}

Yes

${else}

No

${/not}

Yes

Assign helpers

Name Description Example Example response
assign Creates auxiliary variables

${#assign "title"}Hello World${/assign}

${title}

Hello World

WireMock helpers

BlazeMeter supports WireMock helpers to support import from open source. By default, these helpers use {{...}} in WireMock. BlazeMeter automatically fixes imported transactions to use the supported ${...} notation, but if you are manually adding these to a transaction, use the proper BlazeMeter supported notation for them to work.

BlazeMeter supports the following WireMock helpers:

  • xPath
  • soapXPath
  • jsonPath
  • randomValue
  • hostname
  • date
  • now
  • parseDate
  • trim
  • base64
  • urlEncode
  • formData
  • regexExtract
  • size

To learn more about these helpers, see wiremock.org/docs/response-templating.

Response helper

Name Description Example Example response
response.body

Returns the value that is specified in the Transaction→Response→Body field. Use this helper anywhere in the transactions, including HTTP calls and webhook calls.

Transaction → Response → Body contains name=$(config.myName}.
This body contains the value of a myName variable defined in the Configurations tab and assigns it to name at runtime.
Use this value in the body of the HTTP call or webhook call as $(response.body}.
For example, myName=John.

During execution, name=$(config.myName} resolves to name=John.