Forum Discussion

SagarSingh's avatar
SagarSingh
New Contributor
11 years ago

Passing value at RunTime in Groovy

Hi Team

WE have two transactions create and retrieve, im trying to read the product_id from create response and pass it on to retrieve request
here is how im an doing it..

tSuite = testRunner.testCase.testSuite
testStep = tSuite.testCases["ConversionRate TestCase"].testSteps["Retrive"]
context.testCase.setPropertyValue("Product_ID" , "$prod_id") //set product_id in Retrieve Transaction
testStepContext = new WsdlTestRunContext(testStep) //context of the testcase
testStep.run(testRunner, testStepContext)

But product id is not getting set/sent in retrieve request, Request contains variable as ${Product_ID}

then i tried a different way to set the property
testRunner.testCase.getTestStepByName("Retrive").setPropertyValue("Product_ID" , "$prod_id");

but even in this case the retrieve fails to read the new product id set

can you please point out what am i doing wrong here..

1 Reply

  • nmrao's avatar
    nmrao
    Community Hero
    Here is the understanding from the topic description of the case:
    Both steps in the same test case.

    Steps look in the following order
    1. create request
    2. groovy script
    3. retrieve request

    And you need to get an element value from response of step 1, and use the value in an element of step 3 request.
    Groovy script may look like this


    //The following steps are to retrieve required element value from create response
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def currentStep = context.testCase.getTestStepAt(context.getCurrentStepIndex())
    def prevStep = testRunner.testCase.findPreviousStepOfType(currentStep,com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class)
    def response = prevStep.getTestRequest().getResponse()
    def streamText = response.getContentAsString()
    def responseHolder = groovyUtils.getXmlHolder(streamText)

    /* Below are samples, please use as per your response*/
    //define if there any namespaces from create response and replace values accordingly, otherwise ignore it
    //responseHolder.namespaces["ns"]="http://www.yourcompany.com/service"

    //retrieving required node value using xpath
    //def orderId = responseHolder.getNodeValue("//ns:orderID/text()")

    //Now set this retrieved value as property at test case level, so that it can be used in the next step
    context.testCase.setPropertyValue('ORDERID',orderId)


    In the step3, use as mentioned below, do not have to set separately

    retrieve request goes here
    ...
    .....
    <orderId>${#TestCase#ORDERID}</orderId>
    .....
    ....