Forum Discussion

kolersa's avatar
kolersa
Contributor
10 years ago

ALWAYS GET NULL FROM REQUEST HEADER BY GROOVY

I try to get Cookie from request but always get null. I use groovy script

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def httpRequestHeaders = testRunner.testCase.testSteps["Dashboard"].testRequest.requestHeaders
def cookie2 = httpRequestHeaders["Cookie"]
cookie2 = cookie2.toString()

log.info(cookie2)
groovyUtils.setPropertyValue("Properties", "cookie2", cookie2)

In testep "Dashboard" I send get request with RAW

GET http://develop.cutwise.dev.cutwise.com/admin/dashboard HTTP/1.1
Accept-Encoding: gzip,deflate
Cookie3: test
Host: develop.cutwise.dev.cutwise.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.3.1 (java 1.5)
Cookie: PHPSESSID=c14unieegfh9p4dd8eki03tt03
Cookie2: $Version=1


Where Cookie3 I set as header and other Cookie and Cookie2 was set automatically by SOAPUI and option "Maintain http cookie".

I can get Cookie3 but can't get other cookies =(

What should I do? How feature "Maintain http cookie" works?

  • Try this below code in script assertion to request test step.


    Taking Accept-Encoding as example, but you may replace it with whatever property you wanted.

     

     

    def acceptedEncoding = messageExchange.requestHeaders['Accept-Encoding']
    log.info acceptedEncoding
    assert acceptedEncoding instanceof List
  • nmrao's avatar
    nmrao
    Champion Level 3

    Try this below code in script assertion to request test step.


    Taking Accept-Encoding as example, but you may replace it with whatever property you wanted.

     

     

    def acceptedEncoding = messageExchange.requestHeaders['Accept-Encoding']
    log.info acceptedEncoding
    assert acceptedEncoding instanceof List