Custom Script Generator Adapter API |
Use this API to develop a script generator adapter to be used with a Custom Recorder Adapter. Use API Script Generator Adapter API to develop a script generator adapter to be used with the API recording method.
Custom Script Generator Adapters implement the following calls. The shaded rows list functions that other adapter types also implement.
Identifies a Custom Script Generator Adapter.
BOOL IsCustomScriptgenAdapter
();
Return TRUE to indicate that this is a Custom Script Generator Adapter. Any other response disables the adapter.
A C adapter should respond to this call as illustrated below.
extern "C" BOOL LINKDLL IsCustomScriptgenAdapter() { return TRUE; }
Performs initialization procedures.
intInitializeScriptgen
(TCHAR *errorMessage
, size_terrorMessageSize
);
In response to this call, perform any needed initialization procedures and return RSR_SUCCESS
.
extern "C" int LINKDLLInitializeScriptgen
(TCHAR *errorMessage
, size_terrorMessageSize
) { //perform initialization procedures if (successful) return RSR_SUCCESS else { TCHAR buf[] = "Recorder failed to initialize"; if (_tcslen(buf) >= errorMessageSize) return RSR_BUFFER_TOO_SHORT; _tcscpy(errorMessage, buf); return RSR_FAILURE; } }
CancelScriptgen()
, InitializeRecorder()
, StartScriptgen()
Starts a script generation session.
intStartScriptgen
(TCHAR *sessionPath
, size_tsessionPathSize
, TCHAR *scriptPath
, size_tscriptPathSize
, StatusCallbackPtrfPtr
, TCHAR *errorMessage
, size_terrorMessageSize
);
Respond to this call by starting script generation and returning RSR_SUCCESS
.
The following example provides progress information in 10% intervals and parses for multiple script names.
extern "C" int LINKDLL StartScriptgen(TCHAR* pathname, size_t pathnameSize, TCHAR* scriptFilePathnames, size_t scriptFilePathnamesSize, StatusCallbackPtr fPtr, TCHAR* errorMessage, size_t errorMessageSize) { CStringArray ScriptNames; for (int i=1; i<=10; i++) { TCHAR progress[5]; sprintf(progress,"%d",i*10); fPtr(RSR_CALLBACK_PROGRESS, progress); Sleep(1000); } ParseString(scriptFilePathnames,';',&ScriptNames); for(i = 0;i<ScriptNames.GetSize();i++) { CopyFile("c:\\seed.java",ScriptNames[i]+".java",FALSE); } fPtr(RSR_CALLBACK_FINISHED, "Scriptgen successful!!!"); return RSR_SUCCESS; }
CancelScriptgen()
, InitializeScriptgen()
, StartRecording()
Cancels a script generation request.
intCancelScriptgen
(TCHAR *errorMessage
, size_terrorMessageSize
);
This call is made when a Robot user cancels script generation, or in case of a system error. On receiving the call, stop script generation as soon as possible, perform cleanup operations, and return RSR_SUCCESS
.
extern "C" int LINKDLL CancelScriptgen(TCHAR* errorMessage, size_t errorMessageSize) { //stop scriptgen and perform cleanup if (successful) return RSR_SUCCESS else { TCHAR msg[] = "Cancellation cleanup failed"; if (_tcslen(buf) >= errorMessageSize) return RSR_BUFFER_TOO_SHORT; _tcscpy(errorMessage, buf); return RSR_FAILURE; } }
InitializeScriptgen()
, StartScriptgen()
Returns the public name of this adapter.
intGetDisplayName
(TCHAR *name
, size_tnameSize
);
name |
Pointer to a container for the adapter's display name. Copy the name to this location. |
nameSize |
INPUT. The size allocated for name . The adapter's display name cannot exceed this size. |
Specify the GUI name for this adapter. This name is presented to the Robot user (in the Script Generator list box beside the Use Custom radio box) on the Method tab of the Session Record Options dialog.
This example specifies that the GUI name of this adapter is rtweblogicEJB
.
extern "C"
int LINKDLL GetDisplayName
(TCHAR *name, size_t nameSize)
{
TCHAR buf[] = "rtweblogicEJB";
if (_tcslen(buf) > nameSize)
return RSR_BUFFER_TOO_SHORT;
_tcscpy(name, buf);
return RSR_SUCCESS;
}
Returns configuration options in effect for this adapter.
intGetOptions
(TCHAR *options
, size_toptionsSize
);
As illustrated in the example, options supported by an adapter should be entered from a saved, local file. Otherwise, they do not persist between sessions.
The following table describes the Robot-defined configuration option arguments that a Script Generator Adapter can support. See Adapter Configuration on page 81 for a mapping of these options to the Robot GUI.
The following response indicates that this adapter:
extern "C"
int LINKDLL GetOptions
(TCHAR* options, size_t optionsSize)
{
TCHAR buf[RSR_MAX_OPTIONS];
_tcscpy(buf, _T(""));
_tcscat(buf, TEST_SCRIPT_TYPE);
_tcscat(buf, _T(","));
_tcscat(buf, _T(RSR_SCRIPT_TYPE_JAVA));
_tcscat(buf, _T(";"));
_tcscat(buf, GENERATOR_USE_DATAPOOLS);
_tcscat(buf, _T(";"));
if (_tcslen(buf) > optionsSize)
return RSR_BUFFER_TOO_SHORT;
_tcscpy(options, buf);
return RSR_SUCCESS;
}
Sets user-specified configuration options for this adapter.
intSetOptions
(TCHAR *options
, size_toptionsSize
);
options |
INPUT. Pointer to a read-only location containing the Robot user's selections. |
optionsSize |
INPUT. The size of options . |
When the user selects or specifies a value for a Robot-defined option, this call communicates the user's choice to your adapter.
For Robot-defined options pertaining to script generation (those specified on the Generator tab of the Session Record Options dialog), this call communicates the user's choices using this format:
option
[,choice][,value
]
option
is one of the option strings in column 1 of the options table: see GetOptions()
.
choice
is 0 (not checked) or 1 (checked).
value
(s) appears after a preceding comma.
For example, if your adapter supports option GENERATOR_THINK
and a user checks this option and specifies a maximum of 5 milliseconds, the options
argument of SetOptions()
contains this value: GENERATOR_THINK,1,5
. If the user does not check this option, SetOptions()
returns this value: GENERATOR_THINK,0,0
. Options are separated from one another by semicolons.
This example checks to see whether a Robot user selected the Think maximum (ms) option.
extern "C"
int LINKDLL SetOptions
(TCHAR* options, size_t optionsSize)
{
/* CStringArray declared for parsed sub-strings */
CStringArray OptionsArray;
/* parse the original string with semi-colon delimeter.*/
ParseString(options,';',&OptionsArray);
for(int i = 0;i<OptionsArray.GetSize();i++)
{
/* for every sub-string, create another CStringArray*/
CStringArray SubArray;
if(!OptionsArray.GetAt(i).IsEmpty())
{
/*parse the substrings with comma delimeters */
ParseString (OptionsArray.GetAt(i).GetBuffer
(OptionsArray.GetAt(i).GetLength()),',',&SubArray);
/* deal with each sub-string set */
if(SubArray[0]==GENERATOR_THINK)
{
if(SubArray[1] == 0)
{
int think_min = SubArray[2];
}
else
{
/* Unrecognized option -- error may be thrown*/
}
}
}
}
Provides a custom GUI for adapter-defined configuration options.
intDisplayCustomConfigGUI
(TCHAR *errorMessage
, size_terrorMessageSize
);
If your adapter specifies the option CONFIGURATION,USE_CUSTOM_UI
, a Configure button on the Generator per Protocol tab of the Session Record Options dialog is enabled. If a user clicks this button, Robot issues this call. In response, your adapter should display a custom GUI for entering or editing custom configuration options.
GetOptions()
, and the options need not adhere to the triplet format defined by Robot for custom options.
GetOptions()
, the Robot user can use a provided triplet grid as well as your custom GUI.
GetOptions()
. Doing so causes an error because the format is not understood.
SetOptions()
. With a custom GUI, you are responsible for reading and persisting user choices.
extern "C" int LINKDLLDisplayCustomConfigGUI
(TCHAR *errorMessage
, size_terrorMessageSize
) { //display custom GUI and gather user input if (successful) return RSR_SUCCESS; else { TCHAR buf[] = "Custom GUI failed to start"; if (_tcslen(buf) > errorMessageSize) return RSR_BUFFER_TOO_SHORT; _tcscpy(errorMessage, buf); return RSR_FAILURE; } }
Session Recording Extensibility Reference | Rational Software Corporation |
Copyright (c) 2003, Rational Software Corporation | http://www.rational.com support@rational.com info@rational.com |