A couple of default methods(getters and setters) are available for managing Global parameter in Custom Function code:

1. getGlobalParameterValue(String name)
2. setGlobalParameterValue(String name, String value)


Here's a sample Custom Function code that uses these methods to simply store and get Global Parameter and nothing else:

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 GlobalParameterManager extends TestsigmaCustomFunctions{
  	@CustomTestStep
	public TestStepResult storeGlobalParameter(String name, String value){
		TestStepResult result= new TestStepResult();
		try{
			setGlobalParameterValue(name,value);
			result.setStatus(ResultConstants.SUCCESS);
    		result.setMessage("Global Parameter "+name+" with value "+value+" has been stored successfully");
		}
		catch(TestEngineException teex){
    		result.setStatus(ResultConstants.FAILURE);
    		result.setMessage("Failed to store value in Global Parameter "+name);
			return result;
		}
		return result;
	}

    @CustomTestStep
  	public TestStepResult getGlobalParameter(String name){
		TestStepResult result= new TestStepResult();
		try{
    		String data = getGlobalParameterValue(name);
			result.setStatus(ResultConstants.SUCCESS);
    		result.setMessage("The fetched Global Parameter "+name+" has value: "+testdata);
		}
		catch(TestEngineException teex){
    		result.setStatus(ResultConstants.FAILURE);
    		result.setMessage("Failed to read value from Global Parameter "+name);
    		return result;
		}
		return result;
	}
}


In the above code, the first method 'storeGlobalParameter()' stores value from the variable 'value' into Global Parameter named 'name'.


Similarly, the second method 'getGlobalParameter()' fetches value of the Global Parameter named 'name'.


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 below method to set Global Parameter value

setGlobalParameterValue(name,value);


2. Use the below method to get the previously-stored Global Parameter value

String data = getGlobalParameterValue(name);

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


Point to Remember

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