Using DDVariables

Last updated: 06\24\2009

Reference DDVariableStore for API information on using DDVariables in Rational Robot Scripts.
Reference Script Javadoc for API information on using DDVariables in Rational Functional Tester Scripts.


The data driven engine now supports the referencing and use of named variables within test tables and for use by scripts. This gives us some excellent benefits like:

Using DDVariables in Test Tables
(goto Using DDVariables in Robot Scripts), (goto Using DDVariables in RFT Scripts)

Setting Values:
Test tables can set variable values by providing a variable name reference with an assignment operator. Variable names are referenced by preceding the variable name with a caret (^) symbol. This symbol must be the first non-whitespace character in the field.  The assignment operator is the equal (=) sign.

Example (SuiteDriver test table calling StepDriver and providing values for variables):

    t, EnterUser,, ^user.name= "John Smith", ^user.id="jsmith", ^user.password = "silly"
The above example is a call to execute the "EnterUser" test table.  It also sets the values of variables that will be used by the table; namely, user.name, user.id, and user.password .  Note that the caret is not actually part of the variables' names.  It is merely used in the fields to identify variables from literal strings.

The above example will be preprocessed by the data driven engine prior to execution.  The engine will extract and set the values of the variables using DDVariableStore.DDVExtractVariables.

Getting Values:
Test tables can retrieve variable values by providing a variable name reference.  Variable names are referenced by preceding the variable name with a caret (^) symbol.  This symbol must be the first non-whitespace character in the field.

Example (StepDriver test table using the stored variables set by SuiteDriver):

    t, NewUserWindow,     UserNameField     , SetTextValue,   ^user.name
    t, NewUserWindow,      UserIDField      , SetTextValue,   ^user.id
    t, NewUserWindow,   UserPasswordField   , SetTextValue,   ^user.password
    t, NewUserWindow,     AddUserButton     , Click
This example shows that we can use the same test table to add any number of users to this application simply by changing the variable values prior to the call.

Additional Features:
The variable extraction is done on ALL fields that contain a valid variable reference.  This extraction is performed and immediately substituted back into the test record prior to execution.   This means that the object references and action commands can be given aliases if that is desired. 

Example (Aliases provided for "Click" command above):

    t, NewUserWindow, AddUserButton, ^Press = Click
Extraction with immediate Substitution creates the proper executable for this record:
    t, NewUserWindow, AddUserButton,"Click"
Subsequent records can then reference ANY "Click" command by this alias:
    t, AnyWindow, AnyButton, ^Press

For more information on this and using DDVariable references inside the Application Map for dynamic component recognition see DDVariables for Dynamic Recognition.


Using SAFSVARS in RFT Scripts
(or goto Using DDVariables in Test Tables)

The SAFSVARS Service is available not only to SAFS test tables, but also to any custom RFT script called via the CallScript Driver Command. This is done through STAF and the STAFHelper available to custom script as documented in the Script JavaDoc.

Generally, you must minimally include the following imports in your custom RFT script:

	import org.safs.*;
	import org.safs.rational.*;

Then in your script you need to minimally do the following:

	Script safs = (Script) getScriptCaller();
	RRobotJHook hook = safs.getRobotJHook();
	STAFHelper staf = hook.getHelper();

	//retrieve SAFSVARS variable values
	String value = staf.getVariable("varname");

	//set SAFSVARS variable values
	staf.setVariable("varname", "somevalue");


Using DDVariables in Robot Scripts
(or goto Using DDVariables in Test Tables)

The DDVariableStore is available not only to the RRAFS engine, but any Robot script or framework that chooses to INCLUDE it.  This is especially useful for Robot scripts called by the engine.  The engine can pass parameters or data to the script via these variables.  Additionally, outside of the RRAFS engine, Robot scripts can call scripts and pass parameters, data, and results back and forth between them.

INCLUDEing the RRAFS Library:

You can $INCLUDE this library in two ways:

  1. INCLUDE everything for the data driven framework with a single call:
    '$INCLUDE: "DDEngine.SBH"
  2. INCLUDE only the DDVariableStore:
    '$INCLUDE: "DDVariableStore.SBH"

Setting Values:
Scripts can set individual variables via the DDVariableStore.DDVSetVariableValue function.  An example setting variable "user.name" to value "John Smith" would be:

	Dim Result As Integer

	Result = DDVSetVariableValue("user.name", "John Smith")
Of course, you can use SQABasic variables in place of the string literals we have here.

Setting Multiple Values:
Scripts can also use the record extraction techniques used by the data driven engine to set multiple variables in a single call.  You would do this by sending a String of delimited fields to the DDVariableStore.DDVExtractVariables function.  An example of this would be:

	Dim strResult    As String
	Dim strVariables As String

	strVariables = " ^user.name = John Smith, ^user.id = jsmith, ^user.password = silly"
	strResult    = DDVExtractVariables(strVariables, 1, ",")

Getting Values:
Scripts can retrieve variables via the DDVariableStore.DDVGetVariableValue function.  An example of getting the variable "user.name" would be:

	Dim Result As Integer
	Dim varUserName As Variant

	Result = DDVGetVariableValue( "user.name", varUserName)

Another feature of this function is that a default value can be provided just in case the variable has never been set prior to the call.  We do this by giving the input Variant a value that it will retain IF the variable does not already exist.  This default value will also be used to initialize and store the new value of the variable for subsequent calls until it is given a new value with the DDVariableStore.DDVSetVariableValue function.  An example of this would be:

	Dim Result As Integer
	Dim varUserName As Variant

	varUserName = "John Doe"
	Result = DDVGetVariableValue( "user.name", varUserName )

(back to the top)
Questions or comments? Contact SAFSDEV-RRAFS Support at SAFSDEV on SourceForge.