There are two Custom Function types available in Testsigma. They are:

  1. Custom Function Test Data
  2. Custom Function Test Step


The main difference between these Custom Function types is in the return type of the Custom Function and the annotation used for the Custom Function method.


Custom Test Data

It is used to generate some customized test data for your NLP Steps. For example, if you want to generate a random Phone number in a highly specific format that you require, you can use Custom Test Data for that.


Sample Custom Function Test Data:

import org.apache.commons.lang3.RandomStringUtils;
import com.testsigma.customfunc.common.TestsigmaCustomFunctions;
import com.testsigma.customfunc.common.CustomTestData;
public class RandomNumber extends TestsigmaCustomFunctions{
@CustomTestData
public String numberOfNDigits(int n){
String randomdigits;
//your code starts here
---
---
---
//your code ends here
return randomdigits;
}
}

Notice that the @CustomTestData annotation is added for the Custom Function method and the return type of the method is 'String'.


As an example, you can use the above created Custom Test Data in the NLP - "Enter test data in ui identifier field" as:
Enter !|CustomRandomPhoneNumer| in ui identifier field

How to use Default Test Data Functions in Test Steps?


Custom Test Step

It is used to perform complex and AUT/SUT specific actions that are currently not available in the NLP Grammar.


Although we update the NLP Grammar library quite frequently to add all generally possible user requirements, there might be cases when a user application needs to do certain actions that are specific to them. Custom Function Test Steps provide a solution in these scenarios.

import com.testsigma.customfunc.common.TestsigmaCustomFunctions;

public class createAlert extends TestsigmaCustomFunctions{
TestStepResult result = new TestStepResult();

@CustomTestStep
public String numberOfNDigits(int n){
//your code starts here
---
---
---
//your code ends here
return result;
}
}

Notice that the @CustomTestStep annotation is added for the Custom Function method and the return type of the method is always 'TestStepResult'.