Forum Discussion

rohith_soapUI's avatar
rohith_soapUI
New Contributor
7 years ago

is there a way to create the REST resources dynamically through groovy script,I am using the below

is there a way to create the REST resources dynamically through groovy script,I am using the below code but the resources are not getting created,any pointers?

 

import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory
import com.eviware.soapui.impl.rest.RestMethod
import com.eviware.soapui.impl.rest.RestResource
import com.eviware.soapui.impl.rest.RestService
import com.eviware.soapui.config.RestMethodConfig.Factory
import com.eviware.soapui.config.RestResourceConfig
import com.eviware.soapui.config.RestServiceConfig

RestRequestStepFactory rest = new RestRequestStepFactory();

def project = testRunner.testCase.testSuite.project;

def restServiceConfig = RestServiceConfig.Factory.newInstance();
RestRequestStepFactory restStep = new RestRequestStepFactory()

restServiceConfig.setType("restrequest");

RestService restService = new RestService(project, restServiceConfig);

 

restService.setName("GoogleService");
RestResource restResource = restService.addNewResource("GoogleService", "/maps/api/distancematrix/json");

RestMethod restMethod = restResource.addNewMethod("POST");

rest.buildTestStep(testRunner.testCase, rest.createNewTestStep(restMethod, "test"), false)

 

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3
    Why do you want to do so while it is easy to do so using wadl or swagger definition?