Create a script with TruAPI

This task describes how to create a script with TruAPI.

  1. Create a standard npm package.

    1. Open a command window.
    2. Create a folder in your script directory.

    3. Type npm init.

      The setup questions are optional.

  2. Implement the script.

    Write your own .js code or use truapi-gen to generate a template.

    • To create a generic test, type truapi-gen --template default
    • To create a HTTP script, type truapi-gen --template base-url --testUrl http://<url>/

      See TruAPI sample scripts

      Tip: Sample scripts can found in the location: <installdir>\npm\node_modules\truapi\sample

  3. Add transaction names to the truapi.json file.

    A truapi.json configuration file is added to the test folder when you run a truapi-gen command. To display script transactions on the LoadRunner Cloud > Load test > SLA page, manually enter the transactions names, separated by commas, into the transaction section of the file.

    Note: To automatically update the truapi.json file with transactions names, type truapi-cli --updateTran.

  4. After you have written the TruAPI script, test it locally to verify that it runs without error.

    1. Open a cmd window.
    2. Set the path to the test folder.

    3. Type truapi-cli.

  5. Generate the TruAPI script package.

    1. Open a cmd window.
    2. Set the path to the test folder.

    3. Type npm pack.

      A *.tgz is created. This file can be uploaded to LoadRunner Cloud and added to a test definition.

Next steps: