Forum Discussion

sralpert's avatar
sralpert
Occasional Contributor
15 years ago

Still can't pass cookies

The Maintain HTTP state option does not pass cookies in 3.6.1. So I tried to create some groovy script to do the equivalent. I've not found it spelled out clearly anyplace. However, here's my problem. When I step through the code in soapUI it seems to work (eg, no failure). Here's a script between a login and a GetPatientData soap call:

def httpRespHeaders = context.testCase.testSteps["Login"].testRequest.response.responseHeaders
def cookie = httpRespHeaders["Set-Cookie"]
log.info("cookie: " + cookie)
def httpReqHeaders = context.testCase.testSteps["GetPatientData"].testRequest.requestHeaders
httpReqHeaders["Cookie"]=cookie
context.testCase.testSteps["GetPatientData"].testRequest.requestHeaders=httpReqHeaders

However, when I run this in TestRunner, I get an exception:
Status: FAILED
Time Taken: 300
Size: 0
Timestamp: Thu Feb 24 14:54:15 EST 2011
TestStep: Pass cookie
Error:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: expecting EOF, found 'requestHeader' @ line 1, column 57.
xt.testCase.testSteps["Login"]requestHea
^
org.codehaus.groovy.syntax.SyntaxException: expecting EOF, found 'requestHeader' @ line 1, column 57.
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:102)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:71)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:158)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:814)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:511)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:487)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
...
Caused by: Script1.groovy:1:57: expecting EOF, found 'requestHeader'
at groovyjarjarantlr.Parser.match(Parser.java:211)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:764)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:93)
... 26 more

How can I solve this problem? (version 3.6.1 of 10/18/2010)

/steveA

2 Replies

  • sralpert's avatar
    sralpert
    Occasional Contributor
    I know it's rude to answer your own query but adding
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    makes things work. Thus:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def httpRespHeaders = context.testCase.testSteps["Login"]
    .testRequest.response.responseHeaders
    def cookie = httpRespHeaders["Set-Cookie"]

    // create new headers for next request
    def httpReqHeaders = context.testCase.testSteps["GetPatientData"].testRequest.requestHeaders

    // transfer cookie
    httpReqHeaders["Cookie"]=cookie
    context.testCase.testSteps["GetPatientData"].testRequest.requestHeaders=httpReqHeaders

    Solves this problem
  • Hi

    Facing same problem in SOAPUI 3.6.1. can have some fix to solve the problem other than upgrading to SOAPUI4.0?

    Thanks