Each HTTP request declared in the test uses the sending parameters set in the [General] section. But these parameters can be modified when required, and made unique for each request. The essence of these local settings is the same as for the respective [General] section ones. The parameter names are obtained by adding a $ character to the name of the respective parameter from the [General] section ($URI, $Server, $Port and so on). The locally defined parameters have a higher priority then the global ones, i.e. the global values will be used only if no local parameters were set. Examine the following test script:Example 1
[General]
Method=GET
Server=myserver
Port=5000
URI=/servlet
[Request1]
param1=value1
param2=value2
In this case Request1 will use the values of Server, Port, URI set globally (in the [General] section), since these are not locally redefined. The resulting HTTP request will look as follows:
GET /servlet?param1=value1¶m2=value2 HTTP/1.1
Host: myserver:5000Now let us redefine locally some parameters, and we will obtain
Example 2
[General]
Method=GET
Server=myserver
Port=5000
URI=/servlet
[Request1]
$Server=server2
$Port=8000
$URI=/servlet/view
param1=value1
param2=value2Here the Request1 will use the locally redefined values - $URI, $Port. The resulting HTTP request will be:
GET /servlet/view?param1=value1¶m2=value2 HTTP/1.1
Host: myserver:8000Not all of the settings from the [General] section can be redefined locally. The parameters that can be redefined are listed below.
Syntax:
$Server={servername}
Locally defined name (or IP) of the server to send the request to.
Syntax:
$Port={portnumber}
Locally defined server port to send the request to.
Syntax:
$URI={uri|$href(text)|$action|$var(name,default)}
Locally defined request URI. Unlike the globally defined one, it can use either a static value or one of the following functions:
$href(text) – searches for the link with the specified text in the HTML code of response to the previous request and takes the URI from this link;
Example:
The HTML code of the response contains:
<A href="/manual_3.html">preparing test scripts</a>
If we use in the subsequent request the $URI=$href(Preparing test scripts) function, we will finally obtain the actual URI of this link, which is equivalent to $URI=/manual_3.html.
$action – the first form in the respnonse to previous request is found and the URI is extracted from the form action.
Example:
The HTML code of the response contains:
<FORM NAME="search" METHOD="GET" ACTION="/cgi-bin/search.pl">
<INPUT TYPE="text" NAME="text" VALUE="" MAXLENGTH=80>
<INPUT TYPE="submit" VALUE="Start search">
If we use in the subsequent request the $URI=$action function, we will finally obtain the actual URI of this form action, which is equivalent to $URI=/cgi-bin/search.pl.
$var(name,default) – the URI value will be taken from the variable previously set by the $exportvar function. If the specified variable is undefined, the default value will be used.
Syntax:
$Method={GET|POST}
Request method.
Syntax:
$Keepalive={0|1}
Toggles the use of keep-alive requests.
Syntax:
$Delay={number}
Delay (in ms) after request execution.
Syntax:
$Fail=[!]/regexp/
If the specified regular expression is matched in the HTML code of the response to the current request, the request will be accounted as failed. (see Failerrorsymbol). If you place the ! character (exclamation point) before the regular expression, the result of matching will be inverted, i.e. the request will be accounted as failed if the response HTML code DOES NOT contain the matching pattern.
Example:
The test script is:
[General]
requests=5
server=www.yahoo.com
[Request1]
$uri=/
$method=GET
$fail=/Yahoo/The HTML code of the response contains:
<HTML><HEAD><TITLE>Yahoo!</TITLE>
If the request description contains $Fail=/Yahoo/, the request will be accounted as failed and the string specified by the Failerrorsymbol setting will be written to the report instead of request processing time. This setting is useful for functional testing.
Syntax:
$Exportvar=(varname),/regexp/,{replacestring}
Defines a variable and its value (see also $Var, $RegExp). Extracts the pattern matching the regular expression from the current response HTML code and stores it in a variable named varname. $0-$9 metacharacters can be used in {replacestring} to specify the groups in the text matched by the regular expression.