Forum Discussion
JKelsey
14 years agoOccasional Contributor
Thanks, that sounds promising. I tried doing what you suggested, using code copied from various samples I found, but I'm getting an error when the script runs.
Here is what I tried, just to see if I could get a value back from my script library class.
* created a file AuthorizationHeader.groovy in the bin/scripts/soapui/utils folder
* created a header called "Test" in one of my REST request test steps, with value of:
${=soapui.utils.AuthorizationHeader.calcHeader(context)}
When I run the test step, I get this error:
Thu Mar 03 12:12:07 PST 2011:ERROR:Error evaluating script
groovy.lang.MissingMethodException: No signature of method: static soapui.utils.AuthorizationHeader.calcHeader() is applicable for argument types: (com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext) values: [[requestUri:http://webserver, postMethod:com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.ExtendedGetMethod@14fc5ad, #HTTP_STATE:[ | | ], httpMethod:com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.ExtendedGetMethod@14fc5ad, httpClient:org.apache.commons.httpclient.HttpClient@9c7d4, requestTransport:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport@1e64a8, RunCount:0, wsdlRequest:com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest@1627fd1, httpResponseProperties:[page:, search:Id lt 10, orderby:Id desc, size:], hostConfiguration:HostConfiguration[], ThreadIndex:0, requestContent:]]
Possible solutions: calcHeader(com.eviware.soapui.model.testsuite.TestRunContext)
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1357)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1343)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at Script6.run(Script6.groovy:1)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:88)
at com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.doEval(EvalPropertyResolver.java:186)
at com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.resolveProperty(EvalPropertyResolver.java:165)
at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expand(PropertyExpander.java:166)
at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expandProperties(PropertyExpander.java:94)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:154)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Question #1:
How do I fix the error?
I copied code from a SOAP sample, but my request is a REST request. I suspect I'm importing the wrong thing and/or referring to it incorrectly in the line that defines calcHeader.
I tried taking the suggestion in the "Possible solutions" message by changing my test step header value to pass com.eviware.soapui.model.testsuite.TestRunContext instead of context, but that resulted in multiple compliation errors. The beginning of the error looked like this:
General error during conversion: startup failed:
soapui.utils.AuthorizationHeader: 9: unexpected token: ) @ line 9, column 71.
odel.testsuite.TestRunContext )
Question #2:
The error seems to show what is in the context that I can use. Unfortunately, I don't see what I need. What I need is the full URI to the REST resource, including any parameters. In the RAW request tab, it's on this line:
I need this part:
How to I get what I need from the test context once I figure out how to set up my class correctly?
Thanks.
Here is what I tried, just to see if I could get a value back from my script library class.
* created a file AuthorizationHeader.groovy in the bin/scripts/soapui/utils folder
package soapui.utils
import com.eviware.soapui.model.testsuite.TestRunner
import com.eviware.soapui.model.testsuite.TestRunContext
public class AuthorizationHeader
{
public calcHeader( TestRunContext runContext )
{
def testStep = testRunner.testCase.testSteps[testStepName]
result = testStep
}
}
* created a header called "Test" in one of my REST request test steps, with value of:
${=soapui.utils.AuthorizationHeader.calcHeader(context)}
When I run the test step, I get this error:
Thu Mar 03 12:12:07 PST 2011:ERROR:Error evaluating script
groovy.lang.MissingMethodException: No signature of method: static soapui.utils.AuthorizationHeader.calcHeader() is applicable for argument types: (com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext) values: [[requestUri:http://webserver, postMethod:com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.ExtendedGetMethod@14fc5ad, #HTTP_STATE:[ | | ], httpMethod:com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.ExtendedGetMethod@14fc5ad, httpClient:org.apache.commons.httpclient.HttpClient@9c7d4, requestTransport:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport@1e64a8, RunCount:0, wsdlRequest:com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest@1627fd1, httpResponseProperties:[page:, search:Id lt 10, orderby:Id desc, size:], hostConfiguration:HostConfiguration[], ThreadIndex:0, requestContent:]]
Possible solutions: calcHeader(com.eviware.soapui.model.testsuite.TestRunContext)
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1357)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1343)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at Script6.run(Script6.groovy:1)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:88)
at com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.doEval(EvalPropertyResolver.java:186)
at com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.resolveProperty(EvalPropertyResolver.java:165)
at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expand(PropertyExpander.java:166)
at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expandProperties(PropertyExpander.java:94)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:154)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Question #1:
How do I fix the error?
I copied code from a SOAP sample, but my request is a REST request. I suspect I'm importing the wrong thing and/or referring to it incorrectly in the line that defines calcHeader.
I tried taking the suggestion in the "Possible solutions" message by changing my test step header value to pass com.eviware.soapui.model.testsuite.TestRunContext instead of context, but that resulted in multiple compliation errors. The beginning of the error looked like this:
General error during conversion: startup failed:
soapui.utils.AuthorizationHeader: 9: unexpected token: ) @ line 9, column 71.
odel.testsuite.TestRunContext )
Question #2:
The error seems to show what is in the context that I can use. Unfortunately, I don't see what I need. What I need is the full URI to the REST resource, including any parameters. In the RAW request tab, it's on this line:
GET http://webserver/virtualdirectory/Order.svc/?search=Id%20lt%2010&orderby=Id%20desc HTTP/1.1
I need this part:
http://webserver/virtualdirectory/Order.svc/?search=Id%20lt%2010&orderby=Id%20desc
How to I get what I need from the test context once I figure out how to set up my class correctly?
Thanks.
Related Content
- 2 years ago
- 2 months ago
- 5 years ago
Recent Discussions
- 19 days ago