Forum Discussion

hamami's avatar
New Contributor
8 years ago

Dynamically create REST test steps in groovy


I have some JSON file that I want to use as input, let's consider that I have this folders

mainFolder --> Folder 1 : 10 JSON file (req)
           --> Folder 2 : 10 JSON file (req)

I want to create from these folders : - Each directory is a testCase - Each file is a testStep

Here's my code :

import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory
import com.eviware.soapui.config.TestStepConfig
import*;def myTestCase = context.testCase myTestCase

def projectPath = Path
def endPoint = "anEndPoint;
def addTestStep(operation, requestFile, testCase, projectPath, endpoint){
def usageId
def projectPathTest
= projectPath+"SPecificPath";
def testStepName
def iface
= testCase.testSuite.project.getInterfaceList()[0];
def operationName
= operation;
def op
= iface.operations[operationName];
def config
= com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory.createConfig( op, testStepName);
def newTestStep
= testCase.addTestStep( config );
.httpRequest.endpoint = endpoint
} if ("Reconstruct ?","Confirm") ){
new File(projectPathTest).eachDir{dir-> operation = def RestTestCase = testSuite.addNewTestCase(operation) RestTestCase.setFailOnError(false)
file-> addTestStep(operation, file, RestTestCase, projectPath, endPoint) } } }

I verified many times, many pages, many forums, it seems that I have the correct form and algorithm to get what I want, instead, I succeed to create testCase with the names of the folders, I succeed to get the request JSON file, but I fail to create the test step, and I'm pretty sure it's ether the config or the interface/operation who make it fail :

def config = com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory.createConfig( op, testStepName);

Any help please ?