Forum Discussion

Sarita's avatar
New Contributor
4 years ago

In SoapUI how to create multiple REST Requests via groovy script?

Hi Experts,   I have a bunch of REST request messages in text format. Is there a way to import them to a SoapUI project? I want to import them and add as "Test Request" Test Step to an existing Te...
  • ZDGN's avatar
    4 years ago

    Hi Sarita,


    You were really close ğŸ˜‰.

    You should use "RestRequestStepFactory" instead of "NewRestRequestAction".

    Here is a script that worked for me:


    import com.eviware.soapui.impl.wsdl.teststeps.registry.RestRequestStepFactory
    // get the current testCase to add testSteps later
    def tc = testRunner.testCase;
    // get the REST TestStep as template to create the other requests
    def tsTemplate = tc.getTestStepByName("REST Request");
    // create the test step factory to use later
    //def testStepFactory = new NewRestRequestAction();
    // now get all the request from a specific location...
    def directory = new File("C:\\Users\\xxxxxxxxx\\Documents\\xxxxxxxx")
    // for each file in the directory
    directory.eachFile{ file ->
    	// use file name as test step name
    	def testStepName = file.getName()
    	// create the config
    	def testStepConfig = RestRequestStepFactory.createConfig( tsTemplate.getTestRequest(), testStepName)
    	// add the new testStep to TestCase
    	def newTestStep = tc.insertTestStep( testStepConfig, -1 )
    	// set the request from the file content


    Please tell us if the script is working for your case.