Forum Discussion

sakthivel's avatar
sakthivel
Contributor
8 years ago

Groovy Script to Create Multiple SOAP Request

Hi,

     I have a requirement to Groovy Script to create : Project->Suite->Test Case->Test Steps(Multiple SOAP Request). Below code is creating one SOAP Request. But I want to create more than one SOAP Request using Groovy Script. I am getting error because i am trying to create multiple requests. Would you please help me. How to create multiple SOAP Request using Groovy Script.

 

import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory
def suite = context.testCase.testSuite.project.addNewTestSuite("Customer")
def tc = suite.addNewTestCase("CustomerUpdate")


String[] requests= ["CustomerInsert", "CustomerUpdate", "CustomerDelete"]

def operation = testRunner.testCase.testSuite.project.getInterfaceAt(0).getOperationList()[0]
def factory = new WsdlTestRequestStepFactory()
for(int i=0;i<3;i++)
{
def config = factory.createConfig(operation,requests)
def testStep = tc.addTestStep(config)

}
testStep.properties['Request'].value = '<request>someData</request>'
context.testCase.testSuite.project.save()

 

  • I am able to create multiple request. 

     

    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
    import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory
    def suite = context.testCase.testSuite.project.addNewTestSuite("Customer1111")
    def tc = suite.addNewTestCase("CustomerUpdate")
    def operation = testRunner.testCase.testSuite.project.getInterfaceAt(0).getOperationList()[0]
    def factory = new WsdlTestRequestStepFactory()
    def arr = ["d","g","b","z"]
    for(def x : arr)
    {
    log.info "For each Loop" + x.toString();
    config = factory.createConfig(operation,x)
    testStep = tc.addTestStep(config)

    testStep.properties['Request'].value = '<request>someData</request>'
    }

    context.testCase.testSuite.project.save()

     

    Thanks

     

    • PaulMS's avatar
      PaulMS
      Super Contributor

      The name of each request should be variable inside the loop and probably the request value as well.

       

      for(int i=0;i<3;i++)
      {
      def config = factory.createConfig(operation,requests[i])
      def testStep = tc.addTestStep(config)
      testStep.properties['Request'].value = '<request>someData</request>'
      }
      • steveKubik's avatar
        steveKubik
        Occasional Contributor

        Hi,

         

        Thanks for your reply, but I am getting error in my code : Looks I am missing something in my code. Please help me on this. I am struggling lot on this.

         

         

        1. Create a Project->Test Suite->Test Case->Properties Files-> I am able to create till this level but I am getting error

        when I create SOAP request.


        import com.eviware.soapui.impl.wsdl.*
        import com.eviware.soapui.impl.WsdlInterfaceFactory
        import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
        import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory
        import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
        import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory

        import com.eviware.soapui.impl.wsdl.*
        import com.eviware.soapui.impl.WsdlInterfaceFactory

         

        String projectName = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        def workspace = testRunner.testCase.testSuite.project.workspace
        def project = workspace.createProject('Project33333',new File("C:\\Temp\\" + projectName + ".xml"));
        WsdlInterfaceFactory.importWsdl(project, 'http://www.webservicex.com/globalweather.asmx?WSDL', true)
        def suite = project.addNewTestSuite("CustomerSuite")
        tc = suite.addNewTestCase("CustomerTestCases")
        ts = tc.addTestStep( 'properties', 'Excel-Values' )
        ts.setPropertyValue( 'PropertyName', 'value' )

        def operation = testRunner.testCase.testSuite.project.getInterfaceAt(0).getOperationList()[0]


        def factory = new WsdlTestRequestStepFactory()
        def arr = ["PEO","USC","USCS","ASC"]
        for(def x : arr){
        log.info "For each Loop" + operation;
        config = factory.createConfig(operation,x)
        //log.info "Config:::" + config;
        testStep = ts.addTestStep(config)
        testStep.properties['Request'].value = '<request>someData</request>'
        }


        context.testCase.testSuite.project.save()