Passing variables from one response to another request

Now let us make a new Soap project and load our local web service into it.Then we make two test suites login and addProduct into our new project. In login we make a new test case login and add a new Soap request login.

In addProduct we make a new test case addProduct and a new Soap Request addProduct. Then we make a new groovy script test step in addProduct test step as well.

We define the user name and password in project custom properties and use it in login

Then we do this coding in groovy script.

import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext;
import com.eviware.soapui.support.XmlHolder;

log.info "In the groovy test step for AddProduct"
project = testRunner.testCase.testSuite.project;
loginStep =  project.testSuites["login"].testCases["dologin"].testSteps["doLogin"];
def logintestStepContext  =  new WsdlTestRunContext(loginStep);

loginStep.run(testRunner,logintestStepContext);
def response = logintestStepContext.expand('${doLogin#response}')
def xml  =  new  XmlHolder(response);
sessionid = xml.getNodeValue('//sessionid');
log.info "The session id is " + sessionid

//Then we go to the request of addProducts Soap request.
def request = context.expand('${addProducts#request}')
xml  =  new  XmlHolder(request);//holder to hold this soap request.

//Then we set a Node value from this request to a particular value.In our case we set the session node to the session id we got above from login soap response.

xml.setNodeValue("//sessionid",sessionid);

def getxml = xml.getXml();//Here we store the entire request xml in a variable
testRunner.testCase.getTestStepByName("addProducts").setPropertyValue("request",getxml);//set session id in request as well
//i.e when we run the above command the session id will change in our addProduct request as well
//But for username we will choose manually from project custom properties.

//log.info "end"