The GroovyScriptReceiver can execute the Groovy Script present anywhere on your system.
The GroovyScriptReceiver requires the following parameters to be defined:
- path - Defines the location of the Groovy Script.
- subDirectory - Defines the sub-directory within the path where the Groovy Script will be found.
- fileName - Defines the name of the Groovy Script file.
- beforeLoop - Defines when the Groovy Script should be executed. In order to execute the script before the iteration of each row of data, select true for the beforeLoop Receiver parameter.
- whileLoop - Defines whether to execute the script during the iteration of each row of data. If loopCount is n, the script will be executed n number of times. Each row of generated data will become the argument for the Groovy Script.
- afterLoop - Defines whether to execute the script after the iteration of each row of data.
Receiver Attribute Property Keys
The Receiver defines only one property key that can be modified on any of its associated Domain Attributes:
- include - Determines if the Attribute will be included as an argument to the Groovy script..
Suppose you want to run a Groovy script. The Groovy Script modifies the Scenarios using the GenRocket API, before executing them. Therefore Groovy Script needs to know the path to the directory where all the Scenarios are present.
groovy <nameOfGroovyFile> <pathToTheScenarios>
In order to run the Groovy script using GroovyScriptReceiver, create a Domain, e.g. GroovyDemo and add Attributes only when your script requires the arguments.
Our example requires a path to the Scenario as an argument, therefore we need to create an Attribute that will have path to Scenarios. After that we just need to assign GroovyScriptReceiver to the Domain.
As we will be needing the data from the Attribute row, we need to set whileLoop true . As the loopCount is set to 1, the Groovy script will execute with only once.