Scripting with Visual Studio Code

This topic describes how to build and run DevWeb scripts using the Visual Studio Code (VS Code) editor.

Create DevWeb scripts in VS Code

When creating a DevWeb script using VS Code, you can use the VsCodeTemplate as a basis for your script. This can be downloaded from AppDelivery Marketplace.

You can also download a VS Code extension package for creating and editing your DevWeb scripts. For details, see VS Code extension.

Alternatively, if you create a new DevWeb script from your own application, we recommend that you copy some of the files from the template script to your new script. This enables you to utilize extra functionality for the script in the VS Code environment.

Note: For Visual Studio Code 1.46.0 and later, an experimental debugger might be enabled by default. This debugger is not supported with DevWeb scripts.

Workaround: To debug, in the VS Code settings set ‘debug.javascript.usePreview’ to false.

To set up the VS Code environment:

  1. The VS Code template can be downloaded from AppDelivery Marketplace. Download and extract the appropriate VsCodeTemplate.zip package for your LoadRunner Developer version.

    Alternatively, you can copy the VsCodeTemplate folder from <DevWeb root>\examples\.

    Tip: If you prefer to copy files to an existing DevWeb script, open the <DevWeb root folder>\examples\VsCodeTemplate folder, and copy the following files and folder to an existing DevWeb script folder:

    • .vscode folder. These files enable you to view predefined tasks for the DevWeb script in VS Code.

    • DevWebSdk.d.ts and tsconfig.json files. These files enables JavaScript SDK code completion for the DevWeb scripts in VS Code.

  2. Copy the template folder to a location on the same machine as LoadRunner Developer, and rename the copied folder.

  3. In VS Code, open the script: Select File > Open Folder and open the copied folder.
  4. Edit the script as required.
  5. Select Terminal > Run Task (in older versions of VS Code, select Tasks > Run Tasks), then select one of the options to record or generate the DevWeb script.

    For details, see VS Code tasks.

Note: The tasks use the environment variable DEVWEB_PATH, which should point to the DevWeb installation path. The environment variable is created automatically when DevWeb is installed with LoadRunner Professional or LoadRunner Enterprise.

Back to top

VS Code extension

VS Code extension functionality is provided as tech preview.

You can download a VS Code extension for LoadRunner Developer, and install it directly from VS Code. You can then open a template in VS Code and create a DevWeb script, with all editing functionality available.

The VS Code extension includes correlate selection functionality for DevWeb scripts. This enables you to manually select the text you want to correlate, and then use the Correlate Selection option to add extractors. For more information about correlations, see Correlate dynamic values.

To install and use the VS Code extension:

  1. Download and extract the appropriate LoadRunner Developer VscodeExtension.vsix file from AppDelivery Marketplace.

  2. Open VS Code. In the Extensions view in VS Code, select Views and More Actions (ellipsis) button > Install from VSIX.

  3. In the displayed Browse window, navigate to the downloaded VS Code extension file, and click Install.

    After installation is complete, LoadRunner Developer is added to the list of extensions.

  4. Open the new extension. In the Explorer area, right-click and select Create DevWeb script from the displayed menu.

  5. Select a folder for the script, or create a new one.

  6. The script files are displayed in VS Code, edit as required.

  7. Select Terminal > Run Task for task options. For details, see VS Code tasks.

To manually correlate selected text:

  1. Within a web request in your DevWeb script, select the text to correlate.
  2. Select Correlate Selection from the right-click menu.

    Note: The Correlate Selection option is enabled only if the following are true:

    • The script was generated from a HAR file.
    • The selected text is in the context of a web request.
    • The selected text is not in the first request.
    • The selected text contains at least 4 characters.
  3. Give the extractor a name in the Enter extractor name box (displayed at top of the editing pane), and press Enter.

  4. The editor finds all occurrences of the value, and the first match is displayed in the results box. You can select to replace all occurrences with the extractor, or scroll down the list to replace the occurrences one-by-one.

    The extractor type is determined by DevWeb and added to the script in all relevant locations.

Back to top

Run DevWeb scripts from VS Code

You can run your DevWeb script for up to 50 Vusers, using the DevWeb plug-in.

To run a script:

  1. Select Terminal > Run Tasks(in older versions of VS Code, select Tasks > Run Tasks).
  2. Select one of the run options.
  3. If any errors are discovered during the run, press CTRL+left mouse button to jump to the line where the error occurred.

Back to top

VS Code tasks

The VsCodeTemplate includes the following tasks for LoadRunner Developer and DevWeb scripts (available by selecting Terminal > Run Tasks):

Task: Purpose: For details, see:
Generate script Generate a script from a HAR file Offline Script Generator tool
Record script Run the DevWeb Proxy Recorder to record a HAR file DevWeb Proxy Recorder
Run single Vuser Run the script in single mode with 1 Vuser Run scripts locally
Run load Run the script in load mode with up to 50 Vusers
Generate script with Swagger API functions Generate a script in Swagger mode API testing with DevWeb
Generate Swagger API functions Generate a swaggerApi.js file
Get distribution list from LoadRunner Cloud Display a list of cloud locations available for the test on LRC Run tests on LRC from your IDE
Get load generator list from LoadRunner Cloud Display a list of OPLG machines available for the test on LRC
Run test on LoadRunner Cloud Run load test on LoadRunner Cloud
Get test run results from LoadRunner Cloud Get results for a load test on LRC
Run test on LoadRunner Enterprise Run load test on LoadRunner Enterprise Run tests on LRE from your IDE
Get test run results from LoadRunner Enterprise Get results for a load test on LRE

Back to top

See also: