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 the appropriate UWP (Universal Windows Platform) before installing the add-in. For example, install UWP 2022 before installing LRVS2022IDEAddInSetup.exe.
To create a Vuser script in Visual Studio:
-
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.
-
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; }
-
Add code to the template, in the TODO sections.
-
Open the Object Browser (View menu). Expand the LoadRunner node (for example Interop.LoadRunner) to see the LoadRunner Professional elements. Add the required elements to your script, such as transactions, rendezvous points, and messages.
-
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.
-
Use the Vuser menu to replay the script and test its functionality.
-
Select Vuser > Create Load Scenario, to create a LoadRunner Professional scenario using this .usr file.
-
You can also build the LoadRunner Professional project as a DLL file, which is then saved in the same folder as the project. You can reference this DLL directly from a LoadRunner Professional scenario.
-
For Visual Studio 2022, when creating C++ Vuser projects, manually update the following in Visual Studio:
-
Set the solution configuration to Release
-
Set the solution platform to x86
-
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 is 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.
Known issues
Visual C++ language | When using the 2017/2019/2022 Visual Studio add-ins, the Visual C ++ language must be installed in order to work with C++ .NET Vuser projects. |
VS2022 add-in |
Due to a Visual Studio 2022 cache issue, the template might not show up the first time you try to access it in Visual Studio 2022. Resolution: Restart Visual Studio. |
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:
|
VB project |
If you have an issue creating a VB project in Visual Studio 2017/2019/2022, use this workaround:
|
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:
|
See also: