1
votes

My use case is that I want to do a bulk update of request bodies in multiple SoapUI projects.

Example of request body.

{
 "name": "${#TestSuite#NameProperty}" 
 "id": "${#TestSuite#IdProperty}"
}

I want to expand the property ${#TestSuite#NameProperty} through Groovy, and get the value stored at TestSuite level then modify it as necessary.

Suppose I have 50 test steps in my test case and I want to expand the request for each one from Groovy script. To expand a specific test steps, I would pass the test Steps's name. For example:

expandedProperty = context.expand('${testStep1#Request}')

But, how can I achieve the same, if I wanted to iterate over all 50 test steps? I tried to used a nested parameter inside the context.expand expression, but it did not work. For Example:

currentTestStepName = "TestStep1"
expandedProperty = context.expand('${${currentTestStepName}#Request}')

This only returned me the expanded request from the test step right above it (where I am running the groovy script from) rather than the "TestStep1" step. ( Which is madness!)

Also, context.expand only seems to work while executing via Groovy script from the SoapUI workspace project. Is there and other way, or method similar to context.expand which can expand the properties like "${#TestSuite#NameProperty}" during headless execution? Eg: A groovy compiled jar file imported in SoapUI.

Thanks for any help in advance!

1
One way I figured out to do it is by constructing a string that sums up to be the actual TestStep name, and it worked. But, I was hoping may be there was an easier way to do it. Example: string = "\$"+"{TestStep1#Request}" and then expand the string context.expand(string) - Dighate
What is your use case? Just want write all the requests of the test to some where? Is groovy script in the same test case? - Rao
Updated my usecase in the original question. - Dighate
can you check if the updated answer suits your need. - Rao

1 Answers

2
votes

You can use context.expand('${${currentTestStepName}#Request}') way to get it.

There are other approaches as well, which does not use context.expand.

In order to get single test step request of any given test step:

Here user passes step name to the variable stepName.

log.info context.testCase.testSteps[stepName].getPropertyValue('Request')

If you want to get all the requests of the test case, here is the simple way using the below script.

/**
 * This script loops thru the tests steps of SOAP Request steps,
 * Adds the step name, and request to a map.
 * So, that one can query the map to get the request using step name any time later.
 */
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
def requestsMap = [:]
context.testCase.testStepList.each { step ->
    log.info "Looking into soap request step: ${step.name}"
    if (step instanceof WsdlTestRequestStep) {
        log.info "Found a request step of required type "
        requestsMap[step.name] = context.expand(step.getPropertyValue('Request'))
    }
}
log.info requestsMap['TestStep1']

Update : If the step that you are interested is REST step, use below condition instead of WsdlTestRequestStep in the above.

if (step instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) { //do the stuff }