How to use method in separate groovy script within test case
My directory structure is something like as follows:
-testSuite
--testCase
---model (groovy script)
---view (groovy script)
---login (soap request)
---logout (soap request)
Essentially - is it possible to call functions (methods) defined within the 'model' script from the 'view' script? And vice versa.
The functions return and require variables to be passed, they are not just runnables. They also perform operations on the xml requests, which is why I was under the impression using the script library would not be suitable.
Any help or direction would be greatly appreciated. Thanks.
For example, the following file is present at directory ../ReadyAPI-1.4.1/bin/scripts and we see how can this be accessed in two groovy script test steps in a project
Vehicle.groovy
class Vehicle { def name def yearMade def printModelDetails(log) { log.info "Vehicle is ${name}, made in ${yearMade}" } }
Model.groovy -- assume this is your groovy script test step
import Vehicle def vehicle = new Vehicle(name:'Merk', yearMade:1975) vehicle.printModelDetails(log)
//saving value of vehicle name at test case level property say VEHICLE_NAME
context.testCase.setPropertyValue('VEHICLE_NAME', vehicle.name)View.groovy
import Vehicle //get the previously store value from test case property
def vehicleName = context.testCase.getPropertyValue('VEHICLE_NAME') def vehicle2 = new Vehicle(name:vehicleName)
log.info vehicle2.nameNote that all the common stuff to be present in the first groovy class that is placed in scripts directory.
For more details see documentation