Forum Discussion
Venkat
18 years agoNew Contributor
Hello,
Thanks for your replies, Niclas and Ole! Appreciate it! I am using Soap UI 2.0-beta1 version. Your suggestion to first run the step the script is referring to (Groovy Script) helped. But now I want to print out the contents of one of the elements in the response. What is the syntax for referring to that element? I am trying to use the following code and I am not getting it to do what I wanted. Here is my code:
------------------------------------------------------------------
def request = testRunner.testCase.getTestStepByName( "Test Request" );
def property = request.getProperty( "request" );
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
printer.print( "Starting test\n");
def node = new groovy.util.XmlParser(false,false).parseText(property.value);
def entityID = node["SOAP-ENV:Body"]["//ns:getXrefBySSPrefixSourceCompanyIDResponse[1]/ns:getXrefBySSPrefixSourceCompanyIDResult[1]/ns0:CompanyXref[1]/EntityID[1]"];
printer.print( entityID );
printer.print( "Ending test\n");
------------------------------------------------
What am I doing wrong? Why don't I get the values of "EntityID" printed? I can see the value 32074 in the response side of "Test Request" step. Here is my output:
------------------------------------------------
Starting test
[]Ending test
--------------------------------------------------------
Thanks for your replies, Niclas and Ole! Appreciate it! I am using Soap UI 2.0-beta1 version. Your suggestion to first run the step the script is referring to (Groovy Script) helped. But now I want to print out the contents of one of the elements in the response. What is the syntax for referring to that element? I am trying to use the following code and I am not getting it to do what I wanted. Here is my code:
------------------------------------------------------------------
def request = testRunner.testCase.getTestStepByName( "Test Request" );
def property = request.getProperty( "request" );
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
printer.print( "Starting test\n");
def node = new groovy.util.XmlParser(false,false).parseText(property.value);
def entityID = node["SOAP-ENV:Body"]["//ns:getXrefBySSPrefixSourceCompanyIDResponse[1]/ns:getXrefBySSPrefixSourceCompanyIDResult[1]/ns0:CompanyXref[1]/EntityID[1]"];
printer.print( entityID );
printer.print( "Ending test\n");
------------------------------------------------
What am I doing wrong? Why don't I get the values of "EntityID" printed? I can see the value 32074 in the response side of "Test Request" step. Here is my output:
------------------------------------------------
Starting test
[]Ending test
--------------------------------------------------------