Scripting with your IDE

You can build a DevWeb script using your favorite IDE or text editor. You can then run the script from the IDE using LoadRunner Developer (see Run scripts from your IDE), or directly in LoadRunner Cloud to scale up the test (see Run scripts on LoadRunner Cloud).

This topic describes how to work with some common tools, and provides some examples.

Scripting with Visual Studio Code

This example describes creating a DevWeb script using Visual Studio Code (VS Code). You can use the existing VsCodeTemplate script as a base.

To set up and write the script with Visual Studio Code:

  1. Copy the VsCodeTemplate folder from \<DevWeb root folder>\examples\ to a location on the same machine as DevWeb.
  2. Rename the folder, for example, MyDevWebProject.
  3. In VS Code, open the script folder: Select File > Open Folder and open the relevant folder.
  4. When the folder has loaded, select Terminal > Configure Tasks (in older versions of VS Code, select Tasks > Configure Tasks).
  5. Select Others from the dropdown list of task templates.
  6. Configure tasks.json as follows:

    Note: In older versions of VS Code, taskName might be used instead of the label key.

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "DevWeb Single Run",
          "type": "process",
          "presentation": {
            "panel": "new"
          },
          "windows": {
            "command": "${env:DEVWEB_PATH}\\DevWeb.exe"
          },
          "osx": {
            "command": "${env:DEVWEB_PATH}/DevWeb"
          },
          "linux": {
            "command": "${env:DEVWEB_PATH}/DevWeb"
          },
          "args": [
            "-ide=vscode",
            "${cwd}"
          ]
        },
        {
          "label": "DevWeb Load Run",
          "type": "process",
          "presentation": {
            "panel": "new"
          },
          "windows": {
            "command": "${env:DEVWEB_PATH}\\DevWeb.exe"
          },
          "osx": {
            "command": "${env:DEVWEB_PATH}/DevWeb"
          },
          "linux": {
            "command": "${env:DEVWEB_PATH}/DevWeb"
          },
          "args": [
            "-mode=load",
            "-ide=vscode",
            "${workspaceRoot}"
          ]
        },
        {
          "label": "DevWeb Debug Run",
          "type": "process",
          "windows": {
            "command": "${env:DEVWEB_PATH}\\DevWeb.exe"
          },
          "osx": {
            "command": "${env:DEVWEB_PATH}/DevWeb"
          },
          "linux": {
            "command": "${env:DEVWEB_PATH}/DevWeb"
          },
          "isBackground": true,
          "presentation": {
            "panel": "new"
          },
          "args": [
            "-inspect",
            "-ide=vscode",
            "${workspaceRoot}"
          ]
        }
      ]
    }
  7. Select Terminal > Run Tasks (in older versions of VS Code, select Tasks > Run Tasks), then select one of the run options to run the DevWeb script: Load Run, Debug Run, Single Run.

    If any errors are discovered during the run, press CTRL+left mouse button to jump to the line where the error occurred.

Note: This example uses 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

Scripting with Visual Studio

When scripting with Microsoft Visual Studio, you can create external tools that contain tasks to run DevWeb scripts. You need only do this once, and then you can use the tools for all your DevWeb scripts.

To create an external tool to run DevWeb scripts:

The following example describes how to create three external tools:

  • DevWeb Single Run
  • DevWeb Load
  • DevWeb Debug
  1. In Visual Studio, select Tools > External Tools.
  2. In the displayed External Tools dialog box, click Add.
  3. Fill in the dialog box fields for each tool you create, as appropriate, using the tables below.
  4. Select the check box for Use Output window.
  5. Click OK.

  6. After creating the external tool, it should be available to run from the Tools menu.

Field values to create the tools:

Field name Value
Title DevWeb Single Run
Command

%DEVWEB_PATH%/DevWeb.exe (if you do not have the DEVWEB_PATH environment variable defined, use the full path)

Arguments -ide=vs $(ProjectDir)
Initial directory $(ProjectDir)

 

Field name Value
Title DevWeb Load
Command

%DEVWEB_PATH%/DevWeb.exe (if you do not have the DEVWEB_PATH environment variable defined, use the full path)

Arguments -mode=load -ide=vs $(ProjectDir)
Initial directory $(ProjectDir)

 

Field name Value
Title DevWeb Debug
Command

%DEVWEB_PATH%/DevWeb.exe (if you do not have the DEVWEB_PATH environment variable defined, use the full path)

Arguments -inspect -ide=vs $(ProjectDir)
Initial directory $(ProjectDir)

To debug a DevWeb project:

Tip: You need to repeat the following process every time you want to debug, which can be inconvenient. We recommend using Visual Studio Code to debug instead - see Scripting with Visual Studio Code.

  1. Create a DevWeb Debug external tool, as described above.
  2. With the project selected, run Tools > DevWeb Debug. DevWeb starts, but the test will not run.
  3. In the main menu, click Debug > Attach to Process. The Attach to Process dialog box is displayed.
  4. In the Connection type field, select WebKit websocket (no authentication).
  5. In the Connection target field, type http://localhost:9230 (note that the host and port are configurable from the config.yml file, jsInspector section).
  6. Press ENTER on the keyboard. The correct process should be displayed in the Process area.
  7. In the Attach to field, enter WebKit code.
  8. Select the correct process and click Attach.

Back to top

Scripting with JetBrains WebStorm (IntelliJ)

This example demonstrates how to create a DevWeb script using WebStorm (IntelliJ). You can use the existing EmptyScript template as a base.

Autocomplete: If you do not start your script from the EmptyScript template, then in order to activate autocomplete capabilities you should copy DevWebSdk.d.ts from the EmptyScript folder to the script folder: <DevWeb root folder>/examples/EmptyScript

To set up and write the script with WebStorm:

  1. Copy the EmptyScript folder from \<DevWeb root folder>\examples\ to a location on the same machine as DevWeb.

  2. Rename the folder, for example, MyDevWebProject.
  3. In WebStorm, open the MyDevWebProject project.
  4. In the Project view, under the MyDevWebProject project, open main.js to start writing your code.
  5. To enable running the script in WebStorm, set up WebStorm to use the DevWeb executable:

    1. Select File > Settings.
    2. Select Tools > External tools, and click the + button.

    3. Configure DevWeb as follows:

      Click OK.

Back to top

Scripting with Atom.io

This example demonstrates how to create a DevWeb script using Atom.io.

To set up and write the script with Atom.io:

  1. Prerequisite: Download and unzip the DevWeb Atom.io plugin:

    • Windows. Unzip to C:\Users\<user name>\.atom\packages
    • Linux/MacOS. Unzip to ~/.atom/packages

    When you open Atom.io, the DevWeb menu should appear.

  2. Copy the EmptyScript folder from \< DevWeb root folder>\examples\ to a location of your choice.
  3. Rename the folder, for example, MyDevWebProject.
  4. In Atom, open the MyDevWebProject folder and double-click main.js in the project tree to start writing your code.

Back to top

Scripting with Eclipse

This example demonstrates how to create a DevWeb script using Eclipse. You can use the existing EmptyScript template as a base.

To set up and write the script with Eclipse:

  1. Copy the EmptyScript folder from \<DevWeb root folder>\examples\ to a location on the same machine as DevWeb.
  2. In Eclipse, select File > Import Projects from File System or Archive. The Import Projects from File System or Archive wizard opens.

  3. In the Import source field, enter the path to the EmptyScript folder, or click Directory and browse to the folder. Click Finish.

  4. From Project Explorer, open EmptyScript > main.js to start writing your code.
  5. To enable running the script in Eclipse, set up Eclipse to use the DevWeb executable:

    1. Select Run > External Tools > Eternal Tools Configurations and click the New Configuration button.

    2. Enter a name for the configuration in the Name field, for example, "DevWebSingleRun".

    3. Under Location, enter the path to DevWeb. If relevant, you can use the DEVWEB_PATH environment variable using ${env_var:DEVWEB_PATH}, as in the example below.

    4. Under Working Directory, enter the path to the script.

    5. Under Arguments, add the following arguments, separated with a blank space:

      • -ide=eclipse
      • The path to the script, for example: C:\Scripts\EmptyScript

Back to top

See also: