Forum Discussion

resmis19's avatar
resmis19
Occasional Contributor
12 years ago

Groovy script and SOAP UI

Hi all,

Im enitrely new to SOAP UI and Groovy script.
My problem is,

I have a request file which take say ,Item and Quantity.
Now I want to read the values for this request from an xml or excel file.Read it and then put in the request file.

As per my udnerstanding,I need to write a groovy script which reads the value and then put those values in the properties and then inturn into the request.If this is the faster soltuion,can you please help me doing this?

Thanks,
Re

6 Replies

  • resmis19's avatar
    resmis19
    Occasional Contributor
    Thanks for the reply.But I'm not using the PRO version.

    Awaiting your help.
  • Naveen87's avatar
    Naveen87
    Occasional Contributor
    Hi,

    If your xml looks like

    <xml>
    <quantity> 3 </quantity>
    <item> Iphone 5 </item>
    </xml>

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    def url = context.expand( '${#Project#url}' ) //define the external xml file URL d://sample.xml in project properties

    String s1= new File("${url}").text
    def holder = groovyUtils.getXmlHolder(s1);

    def item1 = holder.getNodeValue("//quantity")
    propTestStep = context.testCase.getTestStepByName("Pro") //get the properties step name, here the property step name is Pro
    propTestStep.setPropertyValue("quantity", item1)

    for using this quantity in the request, simply use ${Pro#quantity} in the request