Forum Discussion

MikeDally's avatar
MikeDally
Contributor
10 years ago

How do I automatically insert a REST test step into a SoapUI test using Groovy?

My team and I currently have a few hundred tests scripted which we want to start automating. Instead of manually creating test cases in SoapUI, I have written a script which generates test cases with...
  • MikeDally's avatar
    MikeDally
    10 years ago

    Hi guys,

     

    Wow didn't realise this was such a thought-provoking post! :D

     

    I have figured out what I need to do anyway, which involves numerous loops:

     

        import com.eviware.soapui.impl.rest.RestResource;
        import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory
        import com.eviware.soapui.config.TestStepConfig
        import com.eviware.soapui.impl.rest.RestRequest;
        import com.eviware.soapui.impl.rest.RestService;
    
     List<RestService> restServiceList = testRunner.testCase.testSuite.project.getInterfaceList()
     for(RestService restService : restServiceList){
     	operationList = restService.getOperationList()
     	for(int indexOfOperation; indexOfOperation < operationList.size(); indexOfOperation ++){
     	     RestResource resource = restService.getOperationAt(indexOfOperation);
     	     List<RestResource> requestList = resource.getRequestList();
              for(int indexOfRequestList; indexOfRequestList < requestList.size(); indexOfRequestList++)
              	restRequest = resource.getRequestAt(indexOfRequestList)
     	     	testCaseName = resource.getName()
     	     	TestStepConfig testStepConfig = RestRequestStepFactory.createConfig( restRequest, testCaseName );
              	testRunner.testCase.addTestStep( testStepConfig )
     }
     }