cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get Rest request using groovy script

Occasional Contributor

Unable to get Rest request using groovy script

I am using soap ui 5.3.1 open source versions.

 

In my project I have three test suites, one test suite contains groovy step which calls another groovy step to read all the input data from external file and based on the data, it will call another groovy step in different test suite.

 

In the last groovy step, I am unable to get Rest request in order to build it dynamically. Below is my code..

 

log.info ("method name is :$methodname")

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

 

My test is failing at the below step..I tried different options like replacing testRunner with context but no luck

 

def holder = groovyUtils.getXmlHolder(testRunner.testCase.testSuite.project.testSuites["Services"].testCases[ServiceName].testSteps[methodname].testRequest.getRequestContent())

 

In error log I see below message:

2016-08-03 19:43:40,193 ERROR [errorlog] org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA
org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3486)
at org.apache.xmlbeans.impl.store.Locale.parse(Locale.java:712)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:696)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:683)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:208)
at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:580)
at com.eviware.soapui.support.xml.XmlUtils.createXmlObject(XmlUtils.java:215)
at com.eviware.soapui.support.XmlHolder.<init>(XmlHolder.java:40)
at com.eviware.soapui.support.XmlHolder.<init>(XmlHolder.java:53)
at com.eviware.soapui.support.GroovyUtils.getXmlHolder(GroovyUtils.java:71)
at com.eviware.soapui.support.GroovyUtils$getXmlHolder.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script11.run(Script11.groovy:24)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:129)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:77)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:595)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:77)
at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
at Script1.run(Script1.groovy:90)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.xml.sax.SAXParseException; systemId: file:; lineNumber: 1; columnNumber: 1; Unexpected element: CDATA
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportFatalError(Piccolo.java:1038)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:723)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3454)

7 REPLIES 7
Occasional Contributor

Re: Unable to get Rest request using groovy script

I did change by adding response to my script and getting new error instead of above CDATA  error. Can any guide me how to resolve the issue 

 

holder = groovyUtils.getXmlHolder(context.testCase.testSuite.project.testSuites["Services"].testCases[ServiceName].testSteps[methodname].testRequest.response.getRequestContent())

 

 

2016-08-03 20:11:53,267 ERROR [errorlog] java.lang.NullPointerException: Cannot invoke method getRequestContent() on null object
java.lang.NullPointerException: Cannot invoke method getRequestContent() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at Script13.run(Script13.groovy:24)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:129)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:77)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:595)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:77)
at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
at Script1.run(Script1.groovy:90)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Community Hero

Re: Unable to get Rest request using groovy script

@ravibabu_it

Please use below code snippet for the same.


Before that, replace TEST_STEP_NAME with actual value of your case. And you can find some useful examples here from soapui.org documentation.

https://www.soapui.org/scripting-properties/tips-tricks.html

 

 

import com.eviware.soapui.support.XmlHolder
def response = context.expand( '${TEST_STEP_NAME#Response}')
def holder = new XmlHolder(response)

 

 

 

Please find an example to extract CDATA here:

https://github.com/nmrao/soapUIGroovyScripts/blob/b1f3a2eea91b1f82bd5f4c8ff9d4198afd7d3245/groovy/Xm...

 



Regards,
Rao.
Occasional Contributor

Re: Unable to get Rest request using groovy script

Thanks  Rao for looking into it. Sure I will try your suggestion. I have fixed my CDATA issue and getting null pointer exception as mentioned in second my post. I thought i am getting null pointer exception may be due "request" is null and for that i tried to get TestRequest properties  and it shows null in the log. Any thoughts why  is "Request " parameter is null? 

please find my code and its log message below. I have also attached my screenshot.  

 

firstTestStep =context.testCase.testSuite.project.testSuites["Services"].testCases["Rest"].testSteps["GetUserdetails"]
stepPropList = firstTestStep.getPropertyList()
for(i in stepPropList){
log.info(" " + i.getName() + " : " + i.getValue())
}

 

 

  • Thu Aug 04 16:02:18 IST 2016:INFO: Username : null
  • Thu Aug 04 16:02:18 IST 2016:INFO: Password : null
  • Thu Aug 04 16:02:18 IST 2016:INFO: Domain : null
  • Thu Aug 04 16:02:18 IST 2016:INFO: Request :
  • Thu Aug 04 16:02:18 IST 2016:INFO: ResponseAsXml : null
  • Thu Aug 04 16:02:18 IST 2016:INFO: Response : null
  • Thu Aug 04 16:02:18 IST 2016:INFO: RawRequest : null

 

Occasional Contributor

Re: Unable to get Rest request using groovy script

Now I got why my request is null after going through this link...

 

http://stackoverflow.com/questions/32120209/how-to-get-request-property-in-soap-ui-for-rest-service-...

 

it looks like request will be always null for Rest get request and for post request it contains value.. I have to look for other options to make my framework working..

 

Thanks,

Ravindra

Regular Contributor

Re: Unable to get Rest request using groovy script

@ravibabu_it

Thanks for the link...it helps me finding the solution for the same query...👍

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Occasional Contributor

Re: Unable to get Rest request using groovy script

Did u got any way to get the rest request for the "GET' request ??

Regular Contributor

Re: Unable to get Rest request using groovy script

Hi @selva29,

 

I was only able to get the parameters i have passed in GET request, as there is no request for the GET type.

 

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Top Kudoed Authors