Monday, May 10, 2010

soapUI with Groovy

I've been doing a lot of stuff with soapUI recently and one interesting problem that I came accross is that I need to fire the first request which does insertion and get the response, which contains a transaction number. Afterwards, I need to fire the second request which does a query using that transaction number.

Although, this problem can be solved manually, it's not a very elegant solution. Luckily, we can solve this quite easily with soapUI Groovy scripting feature.

def groovyUtils = new

// Run the first request and get the response
def firstResponse = testRunner.runTestStepByName("Test Case 1")
def holder = groovyUtils.getXmlHolder(firstResponse.responseContent)
def txnNumber = holder["//NS1:InsertionResponse/NS1:TransactionNumber"]

// Modify the second request using the first response
def secondRequest = testRunner.testCase.getTestStepByName("Test Case 2")
def property = secondRequest.getProperty("request")
holder = groovyUtils.getXmlHolder(property.value)
holder.put("//NS1:QueryRequest/NS1:TransactionNumber", txnNumber)

// Run the second request and get the response
def secondResponse = testRunner.runTestStepByName("Test Case 2")
holder = groovyUtils.getXmlHolder(secondResponse.responseContent)


  1. Thanks for this post. I have a problem in making my script library working..Can you give some tips?
    What jar files do I need to place in classpath to compile Groovy classes placed in /bin/script folder?

  2. hi,we provide online training & video tutorial for soapui
    for free videos refer