hamami
8 years agoNew Contributor
Dynamically create REST test steps in groovy
Hello
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.support.UISupport; import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory import com.eviware.soapui.config.TestStepConfig import com.eviware.soapui.impl.rest.*;def myTestCase = context.testCase log.info myTestCase def projectPath = Path
def endPoint = "anEndPoint;
def addTestStep(operation, requestFile, testCase, projectPath, endpoint){
def usageId = requestFile.name.replace("_request.json","")
def projectPathTest = projectPath+"SPecificPath";
def testStepName=usageId;
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 );
newTestStep.getTestRequest().setRequestContent(requestFile.text)
newTestStep.httpRequest.endpoint = endpoint
} if ( com.eviware.soapui.support.UISupport.confirm("Reconstruct ?","Confirm") ){
testSuite.getTestCaseList().each{
testCase->testSuite.removeTestCase(testCase)
} new File(projectPathTest).eachDir{dir-> operation = dir.name def RestTestCase = testSuite.addNewTestCase(operation) RestTestCase.setFailOnError(false)
dir.eachFileMatch(~/.*_request\.json/){
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 ?