Create and View Vuser Scripts in Visual Studio

LoadRunner Professional's basic IDE add-ins for Visual Studio let you create a Vuser script in Visual Studio in VB, C++, or C#. In Visual Studio, you can also view Vuser scripts created in VuGen.

Create a script in Visual Studio

To create your script, you first install Visual Studio add-in. Then, use one of the predefined templates.

Prerequisites:

  • Visual Studio must be installed in the default location.
  • We recommend installing UWP (Universal Windows Platform) 2017 or 2019 before installing the add-in LRVS2017IDEAddInSetup.exe or LRVS2019IDEAddInSetup.exe.

To create a Vuser script in Visual Studio:

  1. Install the IDE add-in for your version of Microsoft Visual Studio from your LoadRunner Professional installation package's Additional Components folder. For example, Additional Components\IDE Add-Ins\LRVS<version>IDEAddInSetup.exe.

  2. In Visual Studio, select the appropriate template from the Installed Templates LoadRunner VB|C++|C# .NET Vuser. Visual Studio creates a new project with one class and a template for a Vuser, and the script file, <name>.usr. The template contains three sections, Initialize, Actions, and Terminate.

    The following example shows a Visual C# template:

    public int Initialize()
          {
              // TO DO: Add virtual user's initialization routines
                return lr.PASS;
          }	
          public int Actions()
          {
              // TO DO: Add virtual user's business process actions
              return lr.PASS;
          }
          public int Terminate()
          {
              // TO DO: Add virtual user's termination routines
              return lr.PASS;
          }
    
  3. Add code to the template, in the TODO sections.

  4. Open the Object Browser (View menu). Expand the LoadRunner node (for example Interop.LoadRunner) to see the LoadRunner Professional elements. Add the desired elements to your script, such as transactions, rendezvous points, and messages.

  5. Expand the Toolbar menu, Vuser, and enhance your script with runtime settings and parameters. For more information, see the runtime settings General > Run Logic or the Parameter List dialog box.

  6. Use the Vuser menu to replay the script and test its functionality.

  7. Select Vuser > Create Load Scenario, to create a LoadRunner Professional scenario using this .usr file.

  8. You can also build the LoadRunner Professional project as a DLL file, which will be saved in the same folder as the project. You can reference this DLL directly from a LoadRunner Professional scenario.

Back to top

View a script in Visual Studio

Visual Studio provides you with additional tools to view, edit, and debug your Vuser scripts. You can add breakpoints, view variable values, add assembly references, and edit the script using Visual Studio's IntelliSense. You can also run the script in a step-by-step mode for debugging.

When you save a script, VuGen creates a Visual Studio solution file, Script.sln, in your script's folder. You can open the solution file in Visual Studio .NET and view all of its components in the Solution Explorer.

To open the Vuser script in Visual Studio, select Design > Open Script in Visual Studio or click the Visual Studio button on the VuGen toolbar.

Note: By default, the Vuser script opens in the latest version of Visual Studio that is installed on your computer. For example, if you have both Visual Studio 2017 and 2019 installed, the script will be converted and opened in Visual Studio 2019.

Double-click the appropriate section in the Solution Explorer, such as vuser_init.cs, to view the contents of the script.

Note: VuGen automatically loads all of the necessary references that were required during recording. You can add additional references for use during compilation and replay through the Solution Explorer. Select the Reference node and select Add Reference from the right-click menu.

Click on globals.cs or globals.vb in the Solution Explorer to view a list of the variables defined and used by your script.

Back to top

Known issues

Visual C++ language When using the 2015/2017/2019 add-ins for Visual Studio, the Visual C ++ language must be installed in order to work with C++ .NET Vuser projects.
Register .NET assembly

When using Visual Studio and add-ins to create C# and VB .NET scripts, Visual Studio creates .NET assemblies that need to be registered in the system before their run. Registration of the .NET assembly requires administrative permissions.

Resolution: Enable UAC and register the .NET assembly before running the test using one of these methods:

  • Run Visual Studio "As Administrator" and provide administrative credentials when prompted. In Project Settings, ensure that the Register for COM interop option is set (Project > Properties > Build > Register for COM interop). Visual Studio will automatically register the test DLL as a .NET assembly every time it builds the project.
  • Run Visual Studio without administrative permissions, and manually register the test DLL after it is built. To do so, run Windows Console with administrative permissions and run the following command: %WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe <TargetDLLwithPath> /codebase (ignore the warning issued when you run this command).

    For example, you might replace <TargetDLLwithPath> with c:\users\qatest\documents\visual studio 2015\Projects\LoadRunnerUser1\LoadRunnerUser1\LoadRunnerUser1.dll. You do not need to register the DLL after every build. It is enough to register it once after making changes in the COM interfaces defined in the DLL.

VB project

If you have an issue creating a VB project in Visual Studio 2017 or 2019, use this workaround:

  1. Create a VBVBWizards folder under ..\Microsoft Visual Studio\<version>\Enterprise.
  2. Copy the folders 1033 and LrVbVuserClass found under ..\Microsoft Visual Studio\<version>\Enterprise\VB\VBWizards, and paste them into the VBVBWizards folder.
  3. Restart Visual Studio. The VB project should now be created successfully.

Threads

Although .NET-based and Java protocols support creating threads, we recommend that you do not use background threads in real load testing scenarios because:

  • Threads can degrade tests scalability.

  • Threads can affect performance measurements.

  • The utility functions' behavior is undetermined if called from any thread except the Vuser main thread which runs the vuser_init, Action, and vuser_end actions. This applies to all functions named lr*.

Back to top

See also: