A couple of default methods(getters and setters) are available for managing Parameter Test Data in Custom Function code:
1. setTestDataParameterValue(name,value)
2. getTestDataParamterValue(name)
Here's a sample Custom Function code that uses these methods to simply store and get Parameter Test data and nothing else:
import org.openqa.selenium.WebDriver; import com.testsigma.customfunc.common.CustomTestStep; import com.testsigma.customfunc.common.TestsigmaCustomFunctions; import com.testsigma.customfunc.result.ResultConstants; import com.testsigma.customfunc.result.TestStepResult; import com.testsigma.testengine.exceptions.TestEngineException; public class ParameterTestDataManager extends TestsigmaCustomFunctions{ @CustomTestStep public TestStepResult storeParameterTestData(String name, String value) throws TestEngineException{ setTestDataParameterValue(name,value); TestStepResult result= new TestStepResult(); result.setStatus(ResultConstants.SUCCESS); result.setMessage("Parameter Testdata variable "+name+" with value "+value+" has been stored successfully"); return result; } @CustomTestStep public TestStepResult getParameterTestData(String name) throws TestEngineException{ String testdata = getTestDataParamterValue(name); TestStepResult result= new TestStepResult(); result.setStatus(ResultConstants.SUCCESS); result.setMessage("The fetched Parameter Testdata variable "+name+" has value: "+testdata); return result; } }
In the above code, the user defined methods storeParameterTestData() and getParameterTestData() uses the Testsigma provided methods setTestDataParameterValue(name,value) and getTestDataParamterValue(name) to store and fetch Parameter Test Data in our Custom Function, respectively.
We just need to extend the 'TestsigmaCustomFunctions' class for that.
Steps to set and set Parameter test data in your custom function
1. Extend your Custom Function code class from the class TestsigmaCustomFunctions.
2. Use the testsigma provided method setTestDataParameterValue(name, value) to update the value of Parameter Test Data variable.
setTestDataParameterValue(name, value)
3. Similarly, use the testsigma provided method getTestDataParamterValue(name) to get the value of previously stored Parameter Test Data variable.
String testdata = getTestDataParamterValue(String name);
Note: You can use any variable name instead of 'testdata' to store the data.
Points to Remember
1. The most important thing that you need to note is that the setTestDataParameterValue() method will update the value in Test Data Profile that is selected in the Test Case Details and the update will happen only after the execution is complete. If you need to use it during the same Test, store it to Runtime Test Data as well for usage within the same test.
2. The scope of Parameter Test Data variable is permanent. Once changed, it will be persistent until modified later.
3. Please make sure the variable names are not duplicated. This might lead to undesirable results.