Web Forms

Web forms are defined in the dclform section of test scripts.

Web Form Declaration Syntax

The form declaration is specified by a form name (for example, FORM_NAME) which can be any valid identifier string and must be followed by a colon. The left side string specifies the name of the field or parameter. An empty string is allowed for nameless URL parameters, such as image map coordinates. The right value specifies the data value of the field or parameter. These can be global constants, global variables and random variables.

The example below illustrates the required syntax for Web form declarations:

dclform
  FORM_NAME:
  "field-name" := R-Value;

Web Form String Encoding

All strings used in the forms declaration will be URL encoded when sent to the server. This means that unsafe characters will automatically be converted into a hexadecimal sequence (%xx). Parameters added directly to the URL will not be encoded (for example, WebUrl("http://host/cgi-bin/doit?MyUnSafeMessage&-?%?-?", 0.0). This allows applications to use non-standard URL parameters.

Web Form Script Example

The following example shows a portion of a Silk Performer script for simulating a form submission. Random variables rsEmail and rsPlatform with two different random functions (RndFile and RndInd) are defined in the random variables section. With each subsequent call to WebFormPost and WebFormGet, the random variables are refreshed and contain new random values. These random values are used to generate the URL encoded form string automatically sent within the request to the Web server. WebFormPost adds the form content string at the end of the HTTP header while WebFormGet adds it at the end of the URL separated by a "?".

dclrand
  rsEmail : RndFile
  ("elname.rnd", 20);
  rsPlatform : RndInd("Windows NT" = 0.3;
  "Windows 2000" = 0.6;
  "other" = 0.1);

dcltrans
  transaction TWebFormPost
  begin
    WebFormPost("http://www.comp.com/cgi/FormMail.pl", CGI_CUST_SUPPORT, nWait);
    WebFormGet("http://www.comp.com/cgi/form", CGI_CUST_SUPPORT, nWait);
  end TWebFormPost;

dclform
  CGI_CUST_SUPPORT:
  "email" := rsEmail,
  "sitetype" := "business",
  "sitelang1" := "english",
  "platform" := rsPlatform;