Skip to main content

Custom VuC functions: check_error

Jerry NgWorker's Compensation Board of British Columbia
Jerry Ng is a senior systems analyst at the Worker's Compensation Board of British Columbia in Canada. Jerry has a background in mainframe development and systems design and analysis. Since 2000, Jerry has concentrated on performance testing with the help of the Rational tools.
Roland Stens, Independent Consultant
Roland Stens is an independent consultant based in Vancouver, Canada, who specializes in QA and testing -- particularly performance and robustness testing. His background is in programming, system analysis, database and network management, testing, and project/test management. As an active participant in various forums related to performance testing, he shares his insights with other testers to help expand their knowledge and vision of the tools and testing processes. He is happy to answer questions by e-mail.

Summary:  Use the custom VuC procedure described here to check the results of an HTTP command for the occurrence of predefined error texts so that the script will detect them, when it would otherwise appear to pass. This function is part of a library of customized utilites and VuC functions created by experts in the testing community.

Date:  29 Jun 2005
Level:  Introductory
Activity:  211 views

Editor's note: This article is part of a library of custom VuC functions developed by performance test engineers to handle special situations encountered in scripting applications. For an overview of the library and links to other custom functions, see "A library of custom VuC functions."

The checkerr procedure lets you check the results of an HTTP command for the occurrence of predefined error texts so that the script will detect them, when it would otherwise appear to pass.

Purpose/Use

When testing a Web site or a Web application in IBM® Rational® TestManager®, you want to make sure that your script performs without error. A built-in facility automatically checks the HTTP return code and flags any code that would indicate an error. But this facility isn't infallible, and the reason is that many Web application developers build sophisticated error handling that returns a nicely formatted page describing the error instead of an HTTP error code.

The problem with these error pages is that they're valid pages as far as the tool is concerned, and when one is returned your script continues to operate. After your test, the test log doesn't show any problem, and you're under the mistaken impression that your test was successful. To find these "undetected" errors, you need to extend your script so that it's able to capture any error reported in a valid response.

We developed the checkerr procedure to tackle this problem. This procedure, which allows you to specify any number of strings that would indicate that an error page was sent, can be called after you receive the results of an HTTP command. The procedure can then evaluate the content of the response and log an error or warning if one is detected. Depending on the severity of the detected error, your script comes to a full stop or continues.

Two types of errors can be checked:

  • severe errors that cause an exit of the entire virtual user emulation
  • lite/info-only errors that produce an error message in the test log output

To use this error-checking procedure, you must first create the checkerr script and the checkerrstring script as outlined below under "Procedure Code." Copy the checkerr script at the top of each VU script you want to use it in, or copy it into checkerr.h in your c:\Rational\Rational Test\include directory and use the following include in your VU script:

#include <check_error.h>

You can also copy the code into checkerr.h in your repository's script directory and then use the following include in your VU script:

#include "check_error.h"


Requirements

There are no external requirements to use this procedure.


Procedure Code

Two pieces of procedure code need to be implemented:

  • checkerr, the code for checking the VU response
  • checkerrstring, the arrays with the user-defined search arguments

Here's the code for the checkerr procedure, to be included in your script or as a .h file:

#include "checkerrstring.s"

proc checkerr(response_string)
string response_string;
{
/********************************************************************/
/*                 S T A R T   P R O C E D U R E                */
/********************************************************************/

int    j;
string return_string = "";

/********************************************************************/
/*               Handling Severe Error Conditions               */
/********************************************************************/

j = 0;

while ((severe_err[j] > "") && (return_string == ""))
{
   if (strstr(response_string, severe_err[j]) > 0)
   {
      return_string = _cmd_id + ": " + _command + " - " + response_string;
      if (strlen(return_string) > 1000)
         user_exit(-1, substr(return_string, 1, 1000));
      else
         user_exit(-1, return_string);
   }
   else
      j = j + 1;
}
/********************************************************************/
/*                 Handling Lite Error Conditions               */
/********************************************************************/
j = 0;

while ((lite_err[j] > "") && (return_string == ""))
{
   if (strstr(response_string, lite_err[j]) > 0)
   {
      return_string = _cmd_id + ": " + _command + " - " + lite_msg[j];
      printf(return_string);
   }
   else
      j = j + 1;
}

/********************************************************************/
/*                  E N D   P R O C E D U R E                   */
/********************************************************************/

return;

}

As mentioned earlier, the checkerr procedure can be placed in each calling script immediately following the #include command, or it can go in a separate .h file referenced by an additional #include command. The procedure can then be put in either the test script section of the repository or the Rational Test include directory. Putting it in the latter location will give you the benefit of not having to copy this procedure into every repository you work with.

For the checkerr procedure to work, the following string arrays need to be initialized in the module checkerrstring.s with appropriate error strings and messages:

  • severe_err -- This array contains the strings that checkerr will use to check for a severe error condition that will require an exit of the virtual user process. Please note that the last array element must be an empty string.
  • lite_err and lite_msg -- The lite_err array contains the strings that checkerr will use to check for nonsevere/info-only error conditions that will produce an error message in the test log output but won't cause an exit of the virtual user process. The lite_msg array contains the corresponding error messages. For example, lite_msg[1] belongs to lite_err[1], and this message will also show up in your test log output. Please note that the last array elements for both arrays must be empty strings.

Here's a sample of the checkerrstring script:

/***************************************************************************/
/* Array "severe_err[]" lists texts in the "response_string" to be     */
/* checked for severe error conditions that will require an exit of    */
/* the entire virtual user emulation. Note that the last array         */
/* element must be an empty string.                                    */
/***************************************************************************/

string severe_err[] =
   {
   "internal error",
   "Server object error",
   "VBScript runtime",
   "A server error has occurred",
   "error '800",
   ""
   };

/***************************************************************************/
/* Arrays "lite_err[]" and "lite_msg[]" list texts in the              */
/* "response_string" to be checked for nonsevere/info-only error       */
/* conditions that will produce an error message in the output but     */
/* will not cause an exit of the entire virtual user emulation. Note   */
/* that corresponding "Error String" as well as "Error Message" must   */
/* be defined in both "lite_err[]" and "lite_msg[] arrays. And note    */
/* that the last array elements for both arrays must be an empty       */
/* string.                                                             */
/***************************************************************************/

string lite_err[] =
   {
   "Server not available",
   ""
   };

string lite_msg[] =
   {
   "Server not available... Can't view PDF Letter.\n",
   ""
   };

The checkerrstring file needs to be created as checkerrstring.s in your repository. This will then allow you to customize the error strings for each individual project through the Robot editor. You'll need to add your own error conditions and messages. Always make sure that the last element of your arrays is an empty string ("").


Command Syntax

checkerr(text-to-check)

You can use this procedure to check error conditions encountered during the execution of virtual user commands in all VU scripts targeted for Web sites or Web applications. To do this, you must insert the call in the script following every http_nrecv emulation command that could potentially return an error page.

The result of the most recent http_nrecv emulation command is always available in the VU system variable _response. This allows you to use the checkerr procedure as follows:

checkerr(_response);


Examples of Use

Inserting this procedure in your VU script is straightforward. In the following sample code, you see a set of HTTP emulation codes that will result in retrieval of a Web page:

www_yahoo_com_1 = http_request ["Yahoo004"] "www.yahoo.com:80",
?

set Server_connection = www_yahoo_com_1;

http_header_recv ["Yahoo005"]  200;     /* OK */

http_nrecv ["Yahoo006"]  100 %% ;       /* 35484 bytes */
checkerr(_response);
            

If you place the call to the checkerr procedure directly after the http_nrecv emulation command and feed the procedure the _response VU system variable, which contains the most recently received response, the procedure will check the contents of the received page.


About the authors

Jerry Ng is a senior systems analyst at the Worker's Compensation Board of British Columbia in Canada. Jerry has a background in mainframe development and systems design and analysis. Since 2000, Jerry has concentrated on performance testing with the help of the Rational tools.

Roland Stens is an independent consultant based in Vancouver, Canada, who specializes in QA and testing -- particularly performance and robustness testing. His background is in programming, system analysis, database and network management, testing, and project/test management. As an active participant in various forums related to performance testing, he shares his insights with other testers to help expand their knowledge and vision of the tools and testing processes. He is happy to answer questions by e-mail.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=4299
ArticleTitle=Custom VuC functions: check_error
publish-date=06292005
author1-email=
author1-email-cc=
author2-email=rstens@shaw.ca
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers