Introduction

Sometimes, it is required to pass a random or dynamic value for one or more keys in the REST Request( Payload/ Body). Testsigma provides Default Test Data Functions for this task.

The functions generate the required value and place it in the request during the execution of the Test Steps.




Syntax of usage in REST Body

Default Test Data Functions can be used to generate Test Data anywhere in the REST Body. The Function Parameter is invoked by using the !|ClassName.FunctionName(arguments)| format


Here's an example:

!|EmailFunctions.randomAlphanumaricEmail(int:7, String:gmail.com)|


Here, EmailFunctions is the Class name, randomAlphanumaricEmail is the Function name

First argument is an int with given value 7 and the second argument is a String with given value gmail.com


The above functions generates a random Alphanumeric Email with 7 random characters and the domain gmail.com - for example, rewvsfd@gmail.com


A Couple of Test Data Functions are available by default for dynamic Test Data generation. These are called Default Test Data Functions in Testsigma Terminology. Here's a list default Test Data Functions - List of default Test Data Functions available in Testsigma


You may also create your own Custom Test Data Functions using Java with our Custom Functions Feature. Please follow this guide to create your own Custom Functions and thereby generate Custom Test Data - How to create and use Custom Functions in Testsigma?

Note: You can also request the Testsigma Support Team to generate a Custom Function for you. The Team will evaluate the feasibility of the request and generate a function for you in a reasonable time.




Usage of Default Test Data Functions in REST Body

First of all, get the Function Class name, Function name and arguments specification from the below article:
List of default Test Data Functions available in Testsigma


If the Function was created by you, please check Test Development > Custom Functions page for Custom Function details such as Class name, Function name and arguments.

Given below is a sample REST API Request Body:

{
    "title": "Test Title",
    "content": "Test Content",
    "userid": 10
}


Let us assume we want a random email as the value of the 'content' key. We can use Test Data Function to accomplish this as given below:

{
    "title": "Test Title",
    "content": "email: !|EmailFunctions.randomAlphanumaricEmail(int:7, String:gmail.com)|",
    "userid": 10
}


Test Data Function Usage sample in REST Payload:

Generated payload: