WebVerifyHtml Function

Action

Parses the HTML response data and counts the appearance of the specified content with the provided string. If the verification condition is not met, an error is raised. The severity of this error can be specified. The appearance count of the specified content can be retrieved by an optional out-parameter. A subsequent low-level web function will not return a value until the request has finished. A cache hit is not performed unless the WEB_FLAG_DONT_FORCE_LOAD option is set. The verification is done even if this option is set and the verified request or a certain part of a page is a cache hit.

When verifying/parsing an HTML page that consists of multiple frames, you can specify which frame document to verify/parse by specifying the sFrame parameter. By default, all HTML documents of the HTML page are scanned. This applies to HTML pages that are retrieved through a page-level command like WebPageUrl or WebPageLink.

It is important to know that all parsing and verification functions must be specified before the Web API call for which the response data should be parsed/verified. You can specify multiple parse/verification functions before a Web API call. The order of the parse/verification functions is not relevant (Exception: WebParseDataBound and WebVerifyDataBound using the flag WEB_FLAG_SYNCHRON).

This verification feature can be enabled/disabled globally (Profile Settings / Web / Verification / HTML / HTML verification).

Note: This function can be added automatically to your script using the visual verification functionality of TrueLog Explorer.

Include file

WebAPI.bdh

Syntax

WebVerifyHtml( in  sVerify     : string,
               in  nAppearance : number optional,
               in  nOptions    : number optional,
               in  sFrame      : string optional,
               in  nSeverity   : number optional := SEVERITY_ERROR,
               out nResult     : number optional );
Parameter Description
sVerify String to compare with the parsed HTML content.
nAppearance Optional: Value to which the actual appearance of the specified content string is compared (see nOptions). If this parameter is omitted, the specified string must appear at least once to meet the verification rules.
nOptions Optional:
WEB_FLAG_EQUAL
The verification succeeds if the actual appearance is equal to nAppearance.
WEB_FLAG_GREATER (default)
The verification succeeds if the actual appearance is greater than nAppearance.
WEB_FLAG_SMALLER
The verification succeeds if the actual appearance is smaller than nAppearance.
WEB_FLAG_CASE_SENSITIVE
If this flag is set the string compare operation is case sensitive.
WEB_FLAG_IGNORE_WHITE_SPACE
If this flag is set all white spaces are ignored.
WEB_FLAG_DONT_FORCE_LOAD
Specify this option to enable caching for a subsequent request. Note that this may lead to unpredictable behaviour, because the verification may only cover certain parts (which are loaded) of a page.
WEB_FLAG_RULE
Specify this flag to perform the verification on every subsequent web function. Verification functions with this flag are usually located in the TInit transaction. Call WebCancelAllRules() to disable all verification rules.
Note: The option WEB_FLAG_RULE should only be used in the INIT transaction or in combination with the WebCancelAllRules function!
sFrame Frame that gets searched for the content (optional). If this parameter is omitted the whole page is scanned.
nSeverity Optional: Severity of the error that is raised if the verification fails. Can be one of the following values:
  • SEVERITY_SUCCESS: Success; no error (numerical value: 0)
  • SEVERITY_INFORMATIONAL: Informational; no error (numerical value: 1)
  • SEVERITY_WARNING: Warning; no error (numerical value: 2)
  • SEVERITY_ERROR: (Default) Error; simulation continues (numerical value: 3)
  • SEVERITY_TRANS_EXIT: Error; the active transaction is aborted (numerical value: 4)
  • SEVERITY_PROCESS_EXIT: Error; the simulation is aborted (numerical value: 5)
nResult Optional: If a variable is provided, it will receive the number of appearances of the specified content string.

Example

dcltrans
  transaction TMain
  var    nResult: number;
  begin
    WebVerifyHtml("Begin");
    WebPageUrl("http://mycompany.com/");
    WebVerifyHtml("Begin", 0, 0, NULL, SEVERITY_WARNING);
    WebVerifyHtml("Shop", 2, WEB_FLAG_EQUAL | WEB_FLAG_GREATER);
    WebUrl("http://mycompany.com/Shop/default.htm");
    WebVerifyHtml("Html", 3, WEB_FLAG_CASE_SENSITIVE |
WEB_FLAG_SMALLER, "Right", SEVERITY_ERROR, nResult);
    WebPageUrl("http://mycompany.com/frame/framea.html");
    Print(string(nResult));
  end TMain;