LoadRunner的VS.NET 2005外掛

TIB發表於2010-02-02

LoadRunner9.5的安裝包中的Additional Components目錄下,可以在IDE Add-ins目錄中找到VS.NET2003以及VS.NET2005的外掛。

 

安裝 VS.NET 2005 的外掛後,可以在VS.NET 2005中建立和開發LoadRunnerVS.NET Vuser指令碼。

 

建立LoadRunner C#.NET Vuser專案後,可以看到選單欄多了一下Vuser,把LoadRunner的執行時設定、參數列、指令碼執行、場景建立等功能作為外掛整合到VS.NET 2005IDE中。

 

 

 

 

詳細的使用方法可以參考外掛的幫助文件

 

The LoadRunner Visual Studio .NET add-in integrates LoadRunner with VS .NET. The add-in lets VS .NET users create a Vuser script using their standard VS .NET environment. This integration enables you to streamline the testing by allowing you to view, execute, and configure a script from within Visual Studio.

 

This add-in supports .NET environments in Visual Basic, C#, and Visual C++. The integration provides three Vuser templates—LoadRunner VB.NET Vuser, LoadRunner C#.NET Vuser, and LoadRunner C++.NET Vuser—that can be accessed through Visual Studio's New Project dialog box.

 

Each project contains an interface through which you can define the Vuser's initialization, execution, and termination logic.

 

Initialization: In this section, you define the logic to prepare the Vuser (such as login to server, prepare objects).

 

Execution: In this section, you define the core behavior of the Vuser (such as execute transactions, query account).

 

Termination: In this section, you define the logic for disconnecting the user or clearing any session objects.

 

 

Creating a LoadRunner C# .NET Vuser

The C#.NET Vuser is defined by the VuserClass interface. This interface is COM compliant (AutoDual interface), and contains three public functions characterizing initialization, execution, and termination.

 

public int Initialize()
public int Actions()
public int Terminate()


To create a C# VS .NET Vuser script:

1                  Open Microsoft Visual Studio .NET.

2                  To create a new project, choose File > New Project. The New Project dialog box opens.

3                  In the Project Types section in the left pane, select Visual Basic Projects. The dialog box displays a list of the available templates in the right pane.

4                  Scroll down to the LoadRunner C# .NET Vuser template and select it.

5                  Specify a name for the script in the Name field.

6                  Choose a location for the script using the Browse button.

7                  Click OK to generate the project.

 

You can modify the above function names. If you modify a function name, you must change it in the [CustomActions] section in the project's .USR file. Similarly, you can customize the Vuser interface's name. Specify the correct program ID for the PROGID attribute in the project's .USR file. In the following example, the Actions function was renamed to First Action and the PROGID was renamed to LoadTest1.

 

RunType=VsNetCom

PROGID=LoadTest1.VuserClass

 

{CustomActions}

Initialize=Initialize

Actions=First_Action

Terminate=Terminate

 

 

Adding Functionality to Your Script

After you create a project, you add standard code and LoadRunner API functions to your script. You can utilize this API to mark transactions, evaluate data-points, display logs, or issue error messages. For a complete list of the API and its capabilities, refer to the Online Function Reference (Help > Online Reference).

 

You access the API through the LoadRunner COM interface or C interface, depending on the project. You use the LoadRunner.LrAPI (LrAPI for C++) class to access all LoadRunner functionality. The LoadRunner templates create an instance of the LoadRunner API class called lr.

 

public VuserClass() { // LoadRunner Standard API Interface ::        DO NOT REMOVE!!! lr = new LoadRunner.LrApi(); }

 

You can rename this instance if necessary, but note that the Online Function Reference uses the instance name lr for the function descriptions.

 

To add functions to your script:

1                  To add a function, click the .cpp, .vb, or .cs file icon in the Solution Explorer. A tab opens, displaying the source code.

2                  Enter code into the appropriate public function: Initialize, Actions, or Terminate (initialization, execution, and termination for VB).

3                  To add a LoadRunner API function, type lr. (or the name of your LoadRunner API object) at the desired point. The Intellisense opens a list of all the available functions. Select a function to insert.

4                  Add all of the desired functions and control logic. Insert the desired code in the appropriate function: Initialize, Actions, and Terminate (initialization, execution, and termination for VB).

5                  To parameterize a value in your script, choose Vuser > Parameter Data. The Parameter List dialog box opens. For more information, press the F1 key while in the dialog box to open the online Help.

 

After you finish entering the code and parameterizing the script, you

configure its Run-Time settings, save it, and compile it.

 

To configure, save, and compile the script:

1                  Choose Vuser > Run-Time Settings to open the Run-time Settings dialog box. Set the Pacing, Log, Think Time, or Miscellaneous options. Click Help to open the online Help.

2                  Choose File > Save to save the project.

3                  Choose Build > Build <Project Name> to compile the script through VS.NET's standard build operations. VS .NET produces a DLL file.

4                  Choose Vuser > Run Vuser to run the Vuser script. The LoadRunner Information log in the Output section shows the run-time information.

 

The sample output below illustrates a stock trade:

 

- LoadRunner VS.NET Integration -- Sun Dec 16 22:02:26 2001

Execution Command Line : "F:/mercury/lrun/bin/mdrv.exe" -usr
"E:/Scripts/LoadRunnerUser1/LoadRunnerUser1.usr" -product_name
vugen  -vugen_win 2228914  -msg_suffix_enable 0
vugen_animate_delay 0 -extra_ext vugdbg_ext
Working Directory  : F:/mercury/lrun/bin


Virtual User Script started
Starting action vuser_init.
Login user account John Doe.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
Access account information.
Notify Transaction QUERYACCOUNT started.
...
Notify Transaction QUERYACCOUNT ended with Pass status (Duration:
2.2000).
Buy 1000 MERQ stocks.
Notify Transaction TRANSACT started.
...
Notify Transaction TRANSACT ended with Pass status (Duration: 1.5000).
Ending action Actions.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Logout from account.
Ending action vuser_end.
Vuser Terminated.


5     Choose Vuser > Create Load Scenario to create and launch a load test scenario for the active Vuser project. The Create Scenario window opens. Enter the information for your scenario. Press F1 for online Help.

 

 

Click OK to save this information and open the LoadRunner Controller.

 

For more information about running a load scenario, refer to the LoadRunner Controller User’s Guide.

 

 

Accessing Web Services in .NET Vuser Projects

You can access and execute Web services through VS .NET. It provides UDDI auto-discovery capabilities and WSDL parsers that support Web Service interfaces and their objects. This capability allows you to test the Web service components and business units as they are being developed or deployed.

 

VS.NET provides full Intellisense capabilities for Web Service references included with LoadRunner VB.NET, C#.NET, and C++ Vuser projects.

 

To specify a Web service:
 1 Choose Project > Add Web References
.


2                  Enter a URL in the URL box, or navigate to an .asmx or .wsdl file using one of the provided links.

3                  After entering the URL, or locating the desired Web service in the left pane, click Add Reference. VS .NET adds the Web service code to your project.

 

The following example illustrates a stock trading Web Service.

 

VB.NET Projects

Dim trader As New WebReference1.Trader
trader.BuyStocks(1000, "MERQ", "Acc#1234567890", "JohnDoe", "letmein")
trader.BuyStocks(5000, "MSFT", "Acc#1234567890", "JohnDoe", "letmein")


C#.NET Projects

WebReference1.Trader trader = new WebReference1.Trader(); trader.BuyStocks(1000, "MERQ", "Acc#1234567890", "JohnDoe", "letmein"); trader.BuyStocks(5000, "MSFT", "Acc#1234567890", "JohnDoe", "letmein");

C++ Projects

OnlineInvest.Trader trader; ... hrc = trader.BuyStocks(1000, L"MERQ", L"Acc#1234567890", L"JohnDoe",

L"letmein");
...

 

 

Debugging .NET Vusers

When you build or run a .NET Vuser project through the Vuser > Run Vuser command, the project's debug settings are automatically updated with the appropriate command and command arguments. This enables you to use VS.NET's built-in debugging features, such as Debug Start, Step Into, and Step Over.

 

If the project settings are not automatically updated, you can enable debugging by modifying the project’s Debugging properties. Choose Project > <Project Name> Properties. The Property Pages dialog box opens.

 

In the Start Actions section, specify <LoadRunner_home_dir>/bin/mdrv.exe as the Start Application.

 

In the Start Options section, specify the Vuser project’s path in the Command Line Arguments as -usr <Path_To_Project's_USR_File>, along with any other relevant options.

You can accurately obtain this information from the LoadRunner Information log in the Output section, as shown in the example below.

 

- LoadRunner VS.NET Integration -- Sun Dec 16 22:02:26 2001

Execution Command Line : "F:/mercury/lrun/bin/mdrv.exe" -usr "E:/Scripts/LoadRunnerUser1/LoadRunnerUser1.usr" -product_name vugen  -vugen_win 2228914  -msg_suffix_enable 0 vugen_animate_delay 0  -extra_ext vugdbg_ext Working Directory  : F:/mercury/lrun/bin

 

In the above example, the Command setting should be

F:/mercury/lrun/bin/mdrv.exe

 

The Command Arguments setting should be:
-usr
"E:/Scripts/LoadRunnerUser2/LoadRunnerUser2.usr" -product_name vugen  -vugen_win 2228914  -msg_suffix_enable 0  -vugen_animate_delay 0  -extra_ext vugdbg_ext

 

Note: It is important to verify that the argument you pass to -vugen_win is correct. This value is unique to the Visual Studio.NET instance. Different Visual Studio.NET instances will have different values.

 

相關文章