A couple of default methods(getters and setters) are available for managing Run-time Test Data in Custom Function code:

1. setRuntimeTestData(String name, String value)

2. getRuntimeTestData(String name)


Here's a sample Custom Function code that uses these methods to simply store and get Runtime 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 RuntimeTestDataManager extends TestsigmaCustomFunctions{

    @CustomTestStep
  public TestStepResult storeRuntimeTestData(String name, String value) throws TestEngineException{
    
    setRuntimeData(name,value);
    TestStepResult result= new TestStepResult();
    result.setStatus(ResultConstants.SUCCESS);
    result.setMessage("Runtime Testdata variable "+name+" with value "+value+" has been stored successfully");
    return result;
  }
  
    @CustomTestStep
  public TestStepResult getRuntimeTestData(String name) throws TestEngineException{

    String testdata = getRuntimeData(name);
    TestStepResult result= new TestStepResult();
    result.setStatus(ResultConstants.SUCCESS);
    result.setMessage("The fetched Runtime Testdata variable "+name+" has value: "+testdata);
    return result;
  }
}


In the above code, the user defined methods storeRuntimeTestData() and getRuntimeTestData() allows us to store and fetch Runtime Test Data in our Custom Function. We just need to extend the 'TestsigmaCustomFunctions' class for that.


Steps to get and set runtime test data in your custom function

1. Extend your Custom Function code class from the class TestsigmaCustomFunctions

2. Use the method setRuntimeData(String name, String value) to set Runtime Test Data

setRuntimeData(name,value);


2. Use the method getRuntimeData(String name) to get the previously stored Runtime Test Data

String testdata = getRuntimeData(name);

Note: You can use any variable name instead of 'testdata' to store the data.


Points to Remember

1. Please make sure the variable names are not duplicated. This might lead to undesirable results.

2. The scope of Runtime variable is limited to a single Execution Configuration. You can use it in all the Test Cases and Test Suites that is under the same Execution Configuration.

3. You can also use the NLP grammar to manage the Runtime Test Data.