Using external scripts

The support of scripting in Web Roller allows to replace the sequence of requests with a program.

Web Roller scripting is implemented via the ActiveScriptingHost, i.e. any scripting language using the respective interface can be used. Currently JScript, VBScript and PerlScript (the latter requires installation of ActiveState ActivePerl) are supported. The name of the script file is set by the Script parameter of the [General] section. If this parameter is specified, the scripting is turned on automatically. It is also possible to include the script text in the body of a test script. In this case $inline.ext should be used as the name of script file.

Caution!: It is important to specify a correct extension - it is used to determine the script language:

Scripting imposes certain limitations:

The rest of the settings and functions described earlier remain functional. Web Roller transfers the control to the script program and does not issue any requests itself.

To provide operation with HTTP requests the wapt object is added to the script's namespace, offering the following methods:


AddRequest

int AddRequest(string RequestName, string Uri);

Declare a new HTTP request with name RequestName. Returns 1 upon success, 0 if a reauest with this name already exists.

Example:

$wapt->AddRequest("test","/");
$wapt->AddRequest("test","http://myserver");


AddParam

int AddParam(string ReqãuestName, string ParamName, string ParamValue);

Adds the Param=Value pair in the RequestName request.

Example:

$wapt->AddParam("test","param1","value4");


SetParam

int SetParam (string RequestName, string Param[, string Value]);

Sets the value of existing Param parameter in the existing RequestName request. If Value is not specified, then the parameter will be reset to the original value specified in the request declaration. Returns 1 upon success, otherwise 0.

Example:

$wapt->SetParam("test","param1","value9");


ResetRequest

int ResetRequest (string RequestName)

Restores the initial request parameters values modified by SetParam, AddParam for the RequestName request.

Example:

$wapt->AddParam("test","param1","value4");
$wapt->SetParam("test","param1","value9");
$wapt->ResetRequest("test");


Request

int Request (string RequestName);

Issue a RequestName request. Returns 0 if the request does not exist (or unsuccessful), 1 upon successful request termination.

Example:

$wapt->Request("test");


SetRequestOpt

int SetRequestOpt(string RequestName, string Options);

Sets the parameters ($uri, $server, $port, $delay, $method, $keepalive) for the RequestName request. The Options string should be in the same format as when redefining parameters from within a sequence.

Note: If Perl is used, the Options string should be in single quotes:

$wapt->SetRequestOpt("test",’$uri=/view’);


GetOpt

string GetOpt (string Option);

returns the value of the Option parameter from the [General] section. Additionallly returns clid – the ordinal number of the current virtual client.

Example:

$wapt->GetOpt("requests");


Response

string Response ();

Returns the response to the last HTTP request.


IsAborting

int IsAborting ();

Returns 1 if Ctrl-Break was pressed, otherwise 0. If you want the script to properly terminate on pressing, this value should be checked frequently.


Logit

void Logit (string logstr);

Writes the logstr string to the logfile, if logging is on ([General] section, Log=1).


Examples

Example1. Primitive Perl script:

[General]
script=$inline.pl

[script]
$wapt->AddRequest("test","http://myserver/");
$wapt->Request("test");
[/script]

This will result in sending the following HTTP request to the server:

GET / HTTP/1.1
Host: myserver

Example2. Using the Requests parameter

[General]
log=1
script=$inline.pl
requests=3

[script]
$wapt->AddRequest("test","http://myserver/");
for($i=0;$i<$wapt->GetOpt("requests");$i++)
{
$wapt->Request("test");
}
[/script]