Functions
Similar to functions in Excel, Testfully functions allow you to compute values dynamically and add them to your requests. The values are computed using a wide range of methods. For example, you could use step()
to extract values from one step and add them to others. This page includes all you need to know about functions.
How to use
To start using functions, wrap them using the {{}}
interpolator tag and when needed, you can also pass arguments to functions. In summary:
- Call a function by wrapping it with
{{}}
. - Named and unnamed arguments can be passed to a function.
{{sum(1,2,3)}
}` is an example of a function call with 3 unnamed arguments: 1,2,3.{{step(index:1, path:variables.token )}}
is an example of a function with two named arguments: index and path.
- You can nest function calls within each other.
{{sum(step(index: 1, segment:response_headers, path:x-avail-credit), 1)}}
The order in which you provide a range of named params does not matter. You do not need to wrap params with '
or "
.
Supported Functions
Testfully comes with a range of pre-defined functions to streamline your work. User-defined functions are in our roadmap and will be added in the future.
sum()
Use the sum() function to get the sum of two or more values. Pass values as unnamed arguments.
Examples
- {{sum(1,2,3)}} equals to 1+2+3=6.
- {{sum(10,-1)}} equals to 10-1=9.
- {{sum(10,sum(10,20))}} equals to 10+(10+20)=40.
step()
Use the step() function to resolve values of other steps within the same multi-step request. Function step() supports the following named params:
Param Name | Description | Default Value |
---|---|---|
index | Index of the target step -- starts from 0 | 0 |
path | Path to value | N/A |
segment | Segment of the request to extract the value. One of: request_body, response_body, request_headers, and response_headers. | response_body |
default_value | The default value to be used when value could not be resolved | N/A |
Examples
step(index:0, segment:response_headers: path:x-avail-credit)
reads value of thex-avail-credit
response header from the 1st step.step(index:0, segment:response_body, path: data.success)
reads value of thedata.success
field from the response body of the 1st step.
Randoms
Testfully offers a range of functions to generate random data.
Function Name | Description | Example |
---|---|---|
int() | A random integer greater than zero | 98605 |
float() | A random float greater than zero | 27643.886 |
email() | A random email address. | addie@green-plus.bm |
string() | Generates a random string | 4x49cSMPKv0eypg1iec9k0HHjsW |
guid() | Generates a random UUID V4 | e9b1f1db-1fab-47f1-95f8-f625eb8be23c |
uuid() | Generates a random UUID V4 | e9b1f1db-1fab-47f1-95f8-f625eb8be23c |
uuidv4() | Generates a random UUID V4 | e9b1f1db-1fab-47f1-95f8-f625eb8be23c |
Date & Time
Functions that relate to date & time.
Function Name | Description | Example |
---|---|---|
isoTimestamp() | current time in ISO String format | 2023-06-06T04:25:37.667Z |
timestamp() | The current UNIX timestamp in milliseconds | 1686025537667 |