Home » HP Mercury LoadRunner

Creating a Vuser Script with Visual C

6 July 2009 1,024 views No Comment Author: Raveen Sharma

Vuser scripts can be created using Visual C 6.0 or higher. To create a Vuser script with Visual C, please follow the below steps:

  1. In Visual C, create a new project – dynamic link library (dll). Select File > New and click the Projects tab.
  2. In the Wizard, select empty dll
  3. Add a new cpp file with 3 exported function: init, run, end
  4. Add library file lrun50.lib
  5. Select the C/C++ tab and select Code generation (Category) > Use Run Time library (List). Change it to: Multithreaded dll
  6. Select the C/C++ tab and select Preprocessor (Category) > Preprocessor definitions (edit field) Remove _DEBUG
  7. Add code from your client application, or program as you normally would
  8. Enhance your script with Vuser API functions. For example, lr_output_message to issue messages, lr_start_transaction to mark transactions, and so forth
  9. Build the project. The output will be a DLL
  10. Create a directory with the same name as the DLL and copy the DLL to this directory
  11. In the lrvuser.usr file in the Template directory, Update the USR file key BinVuser with the DLL name: BinVuser=<DLL_name>

In the following example, the lr_output_messsage function issues messages indicating which section is being executed. The lr_eval_string function retrieves the name of the user. To use the following sample, verify that the path to the Vuser API include file, lrun.h is correct

#include “c:\lrun_5\include\lrun.h”

extern “C” {

int __declspec(dllexport) Init (void *p)

{

lr_output_message(“in init”);

return 0;

}

int __declspec(dllexport) Run (void *p)

{

const char *str = lr_eval_string(“<name>”);

lr_output_message(“in run and parameter is %s”, str);

return 0;

}

int __declspec(dllexport) End (void *p)

{

       lr_output_message(“in end”);

return 0;

}

} //extern C end

Popularity: 92% [?]

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.