Forum Discussion

aaron_ehrensber's avatar
aaron_ehrensber
Contributor
14 years ago

Scripting WebService call

I have a groovy script in which I basically want to loop over the results from a previous webservice call, snag the results, and send a subsequent webservice request.

(In a nutshell - make call A to get 10 IDs from system, loop 10 times and make 10 requests). I have the loop in place and can access the 10 responses....

My script is ...

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def requestHolder = groovyUtils.getXmlHolder ("getFeatureRights#Response" )

requestHolder.declareNamespace("ns2","http://host:port/webservices/PermissionWebServices/")
def featureRightList = requestHolder.getNodeValues("//ns2:getFeatureRightsResponse[1]/featureRights");

int counter = 1
int loopControl = featureRightList.length + 1;

while (counter < loopControl ) {
def classId = requestHolder.getNodeValue("//ns2:getFeatureRightsResponse[1]/featureRights[" + counter + "]/classificationId[1]");
def featureRightId = requestHolder.getNodeValue("//ns2:getFeatureRightsResponse[1]/featureRights[" + counter + "]/id[1]");

testRunner.testCase.testSteps["addGroupFeatureRights"].setPropertyValue("classificationId", classId)
testRunner.testCase.testSteps["addGroupFeatureRights"].setPropertyValue("featureRightId", featureRightId)

// run the webservice
def result = testRunner.runTestStepByName("addGroupFeatureRights");
String status = result.getStatus().toString();
log.info (status);

counter++;
}
[code]


I have 2 questions....

1. The addGroupFeatureRights is the webservice call I wish to make. Am I correct in the way I'm attempting to set the properties in that call?
2. The webservice call... The classificationId tag, for example, is just <classificationId></classificationId> Do I need to put anything in the tag to tell it to reference the value that I'm passing in?

Thank you in advance for any help.

Aaron

1 Reply

  • Seems I have myself fixed up with a properties step and a few transfers, which is fine. I'd rather handle it through scripting though, but oh well...

    My last problem now is that after my groovy loop, the test continues as normal - and runs the very last data through the webservice 1 extra time. Can my groovy script issue a STOP command or something to end the test once the loop is done?