Contributions
Re: In SoapUI how to create multiple REST Requests via groovy script?
Hi David, Here is my final code, which generates requests with .txt extension. def testStepName = file.getName() just to trim the .txt extension def testStepName = file.name.take(file.name.lastIndexOf('.')) //Final Code 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("Request 1"); // now get all the request from a specific location... // your location def directory = new File("D:/.../") // for each file in the directory directory.eachFile{ file -> // use file name as test step name def testStepName = file.name.take(file.name.lastIndexOf('.')) // to trim the .txt extension // 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 newTestStep.getTestRequest().setRequestContent(file.getText()) }2.7KViews0likes0CommentsRe: In SoapUI how to create multiple REST Requests via groovy script?
Hirichie, Thank you for your reply. I am using REST API URI to create a Project in SoapUI. our REST API's are not described in a .wadl format. I am looking for a groovy script to create multiplerequests. Trying the below groovy script, but I am getting error in my code: Looks like I am missing something in my code. import com.eviware.soapui.impl.rest.actions.method.NewRestRequestAction ; // 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("Request 1"); // 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("D:/.............................../") // 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 = testStepFactory.createConfig( tsTemplate.getTestRequest(), testStepName) // add the new testStep to TestCase def newTestStep = tc.insertTestStep( testStepConfig, -1 ) // set the request from the file content newTestStep.getTestRequest().setRequestContent(file.getText()) }2.9KViews0likes4Comments