Description

The GenRocket API helps to update the Scenario at runtime just before execution from the user's system or server without going online and logging into the GenRocket web platform to make updates. 


API methods can be used when writing code to make updates. Sometimes, the code does not have to be written to make these updates. In these instances, the required updates can be accomplished with a single JSON file directly on the user's local computer. 


This article shows the format for the JSON file and how to update your Scenarios locally on your computer using the -apif and --api-file commands.


These command-line options instruct GenRocket to override the GenRocket component's parameter values dynamically using a JSON file of sequential API Methods. Please see this article to view available API Methods: Index of API Methods.


In This Article


Commands 

-apif <apiFile>
--api-file <apiFile>


Required Parameter

The following parameter is required when using these commands:

  • <apiFile> - defines the path and file name of the JSON file of sequential API methods 
    • Mac OSx/Linux Example - /home/jdoe/APIFiles/api.json
    • Windows Example - C:\Users\Username\APIFiles\api.json

Syntax

Below is the syntax for running the command in a CMD or Terminal window:

genrocket -r <SCENARIO_FILE> -apif <JSON_FILE>


Using APIF with Test Data Cases (TDCs)

Users can execute the following command for Test Data Cases. It allows a user to modify the Scenario by specifying the APIs in the file after applying Test Data Case.

genrocket -tdc <tdc> -r <Scenario> -apif <apifile>


Usage Example 1 - Override Domain Loop Count

These commands should be included in the command line when running the GenRocket Scenario directly on the user's local computer. 


Basic Setup

Let's say a user has a Project set up with a single User Domain. For this Domain, the global loopCount has been set to a value of 10000.

This means that the downloaded Scenario will generate 10,000 records of data when ran on the user's local computer.



JSON File & API Method

After downloading the Scenario, the user determines they need to run the same Scenario but generate 500,000 records of data. This can be accomplished without logging into the GenRocket web platform by using the -apif command. 


Note: The JSON file may contain multiple API Methods. For this example, only one API Method will be included in the file. 


API Method

The user will need to have a JSON file on their local machine with the following API Method: 


JSON File Contents

For this example, the JSON File will contain the following. The JSON File has been named UpdateUsers.json.

{
  "api": [
    {
      "methodName": "domainSetLoopCount",
       "parameters": {
       "domainName": "User",
       "loopCount": "500000"
      }
    }
  ]
}


Run the Scenario on the User's Local Machine

The user will need to open a CMD or Terminal Window and enter the command line with the appropriate Scenario Name and JSON File Name/Path. For this example, it will appear as follows: 


genrocket -r UserScenario.grs -apif /home/jDoe/APIFiles/UpdateUsers.json


If the user is currently within the directory in the CMD or Terminal Window where the file is stored, then the command would appear differently. A good example would be when the Scenario and JSON file are both in the user's Downloads Folder.


genrocket -r UserScenario.grs -apif UpdateUsers.json


Sample Output

When the command is run in the CMD or Terminal Window, it will override the global loopCount value for the User Domain and generate 500,000 rows of test data. Here is the beginning of the sample output for this example: 



Here is the end of the sample output for this example. 500,000 rows of data have been generated: 



Usage Example 2 - Override All Domain Variable Values

For this example, the user has downloaded their Scenario and needs to modify the id, loopCount, and seed Domain Variable values. The user wants to change the Domain Variable values to the following: 

  • id = 1010
  • loopCount = 500
  • seed = 11


API Method

The user will need to have a JSON file on their local machine with the following API Methods: 


JSON File Contents

For this example, the JSON File will contain the following. The JSON File has been named UpdateDomainVariables.json.


{
  "api": [{
      "methodName": "domainSetLoopCount",
      "parameters": {
        "domainName": "User",
        "loopCount": "500"
      }
    },
    {
      "methodName": "domainVariableSet",
      "parameters": {
        "name": "global.User.id",
        "value": "1002"
      }
    },
    {
      "methodName": "domainVariableSet",
      "parameters": {
        "name": "global.User.seed",
        "value": "11"
      }
    }
  ]
}


Run the Scenario on the User's Local Machine

The user will need to open a CMD or Terminal Window and enter the command line with the appropriate Scenario Name and JSON File Name/Path. For this example, it will appear as follows: 


genrocket -r UserScenario.grs -apif /home/jDoe/APIFiles/UpdateDomainVariables.json


If the user is currently within the directory in the CMD or Terminal Window where the file is stored, then the command would appear differently. A good example would be when the Scenario and JSON file are both in the user's Downloads Folder.


genrocket -r UserScenario.grs -apif UpdateDomainVariables.JSON


Sample Output

When the command is run in the CMD or Terminal Window, it will override the global id, loopCount, and seed values for the User Domain and generate 500 rows of test data. The first record will have an id value of '1010'. The test data will be generated using seed number '11'. 


Here is the beginning of the sample output for this example: