Forum Discussion

Jack21Z's avatar
Jack21Z
Occasional Contributor
11 years ago

Property Transfer Source: groovy script, Target: SOAP reques

Hi

I created a groovy script and i want to transfer directly my generated data/answer/result using TransferProperty to SOAP request without using Test Properties

thanks,
Jack

9 Replies

  • Jack21Z's avatar
    Jack21Z
    Occasional Contributor
    Hi,

    Uhm, my test steps are the following:


    GroovyScript --> script to generate data
    PropertyTransfer --> Source: Groovy Script Target: SOAP Request
    SOAP Request

    My goal here is i'm not using any Test Properties of use case, test suite and others as possible


    Regards,
    Jack
  • nmrao's avatar
    nmrao
    Champion Level 3
    Hey,

    In the first link provided has the sample how to set a value to a property and how to get the same. In this case, you would not require transfer property step at all. When property is used in the request, the value is automatically replaced when the request is sent.

    For eg
    There are two steps in a test case
    Groovy
    Test Step for soap request.

    Groovy:


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def timed = System.currentTimeMillis()
    def myGeneratedValue = 'test_'+timed
    testRunner.testCase.setPropertyValue("GENERATED_VALUE",myGeneratedValue)


    Request may look:


    <?xml version="1.0"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
    <soapenv:Header/>
    <soapenv:Body>
    <Reference>${#TestCase#GENERATED_VALUE}</Reference>
    </soapenv:Body>
    </soapenv:Envelope>



    Note that you do not need to set any property value manually. At run time ${#TestCase#GENERATED_VALUE} will replaced with generated value run time automatically if test case is run or run groovy step first and then request step.
    And smilarly you use properties at TestSuite, Project level as well. Hope this helps
    • mkhan031486's avatar
      mkhan031486
      Contributor

      Hi Rao, 

       

      I was actually stuck on the same issue as well, and you explained it beautifully. I have a question though... 

       

      What if I want to create the property in a test suite or at a project level.. what changes to I need to make to the below script???

       

      testRunner.testCase.setPropertyValue("GENERATED_VALUE",myGeneratedValue) 

       

       

       

      • nmrao's avatar
        nmrao
        Champion Level 3

        Set property / its value at suite level

         

         

        context.testCase.testSuite.setPropertyValue("GENERATED_VALUE",myGeneratedValue) 

        project level:

         

         

        context.testCase.testSuite.project.setPropertyValue("GENERATED_VALUE",myGeneratedValue) 

         

  • Jack21Z's avatar
    Jack21Z
    Occasional Contributor
    Thanks Rao,

    I figured it out!!!

    groovy Scipt:


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def timed = System.currentTimeMillis()
    def myGeneratedValue = 'test_'+timed
    return myGeneratedValue


    PropertyTransfer Test Step:


    Source: Groovy Script Property: result

    Target: SOAP request Property: Request


    Transfer the value from groovy -> soap request



    SOAP request

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
    <soapenv:Header/>
    <soapenv:Body>
    <Reference>"value from groovy script"</Reference>
    </soapenv:Body>
    </soapenv:Envelope>


    Regards,
    Jack
  • nmrao's avatar
    nmrao
    Champion Level 3
    If i were you, do not use additional step - Property transfer which could be done groovy itself.