Under the Win32 platform Web Rollerscripting support is implemented via the ActiveScriptingHost, - that is, any scripting language providing the respective interface can be used. Currently JScript, VBScript and PerlScript are supported.
The support of scripting in Web Roller actually
means replacing the sequence of requests defined in the original test script
with the program defined by the external (or inline) script. All the settings
of the current test script remain active (except for sequences - these will
be ignored). Whenever scripting is active, Web Roller
passes control to the script and does not generate any requests by itself. The
Method | Description |
int Request ( string requestname); | Attempts to make a request with the specified name. Returns 0, if the request fails (or no request with such name exists), 1 if the request was successful. |
string Response (); | Returns the response to the latest request. |
int SetParam (string req, string param[, string value]); | Sets the value of the specified parameter of the specified request. If string value is omitted, the parameter is set to the initial value from the request description. Returns 1 upon success, 0 upon failure. |
int IsAborting (); | Returns 1 if Ctrl-Break was pressed, 0 if not. If you want the script to correctly terminate on Ctrl-Break, this value should be monitored. |
string GetOpt (string opt); | Returns the settings of the global parameters (General section). Additionally returns ClId the unique number of the current virtual client. |
void Logit (string logstr); | Adds a string to the log (if logging is enabled). |
int AddRequest(string name, string uri); | Create a new request. Returns 1 upon success, 0 if the request with the specified name already exists. |
int SetRequestOpt(string name, string options); | Sets the request parameters. The options string should be in the same format as when passing parameters within a sequence (see in Test scripts). |
int AddParam(string reqname, string pname, string pvalue); | Adds a parameter to the specified request. |
The name of the script file to be used is set by the scriptfile parameter in the General section. If this setting is present, the scripting is automatically enabled. You can also embed the script text in the body of Web Roller's test script (.TST) file. To do this, you should specify $inline.ext as the value of scriptfile setting. It is important to use the correct ext extension (js, pl or vbs) for inline code, since Web Roller will use it to determine the language of the inline script.
Example (PerlScript):
<$Web Roller->LogIt("Let's try...");
my $res=$Web Roller->AddRequest("test","http://myhost.mydomain.com/scripts/test/params.pl");
$Web Roller->LogIt("AddRequest:$res");
$res=$Web Roller->AddParam("test","param1","paramvalue");
$Web Roller->LogIt("AddParam:$res");
$res=$Web Roller->SetParam("test","param1","xxxyyyzzz");
$Web Roller->LogIt("SetParam:$res");
$res=$Web Roller->Request("test");
$Web Roller->LogIt("Request:$res");
$res=$Web Roller->SetParam("test","param1");
$Web Roller->LogIt("SetParam:$res");
$res=$Web Roller->Request("test");
$Web Roller->LogIt("Request:$res");