Forum Discussion

cmonroe's avatar
cmonroe
Occasional Contributor
13 years ago

Using Groovy to grab the cookie in the request header

I used the web recording tool to authenticate via http into a server.
However, there is some kind of redirect done and I don't see the step where the response comes back from the server with the cookie value in it.
The next teststep contains the value I need, but I am trying to locate the groovy script classes that will help access the Cookie parameter value in the http header.

Any thoughts?

Craig

5 Replies

  • cmonroe's avatar
    cmonroe
    Occasional Contributor
    Thanks Henrik.

    Partially but as the web recording didn't log one of the responses because of a redirect (it appears), I am looking to get the cookie from the request header.
    I attached a screen shot. I need to grab the value for the cookie.

    Thanks,

    Craig
  • Aha!

    That you can do like this:
    def request = testRunner.testCase.testSteps["HTTP Test Request"].testRequest  
    def headers = request.requestHeaders
    def myCookie = headers["Cookie"]


    Have a nice weekend

    Henrik
    SmartBear Software
  • cmonroe's avatar
    cmonroe
    Occasional Contributor
    Henrik,

    Thank you! That did it!
    I can see the value logged now.

    I am getting an error when transferring, but hopefully that is minor.

    def request = testRunner.testCase.testSteps["CustomersForm"].testRequest
    def headers = request.requestHeaders
    def myCookie = headers['Cookie']

    log.info ("This is the value:" + myCookie)

    testRunner.testCase.testSuite.project.setPropertyValue("Cookie", myCookie)

    Error:

    groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.WsdlProjectPro.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [Cookie, [ASP.NET_SessionId=lzbgzu450pm12u2mpt0w0oiq; admin-eaq-admin702=44A7E68438AB79C7D0886BBDBE92252BB39F066CF0A4358911D1C1AFFAA51BC6DF4E7C4247ECB58002886A43EE60FBDE03C4E441B4883DBC6C3D22367C89DDA475390924AB62FAE0E5CFC446051F18D6CD06EBAEC81024402E3220FC3B633335E80B2219F15A7F9A9E976B63807948F98B0CBD758AD8AC3D6EF3A174AE8AFD442BC8536239B8D28238E39BD44EBCCA355580A1C1]] Possible solutions: setPropertyValue(java.lang.String, java.lang.String), setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String), getPropertyValue(java.lang.String) error at line: 7

    I will investigate this, but if you no what it is off the top of your head, let me know. You guys are great! Thanks!
  • Hi,

    The method takes an ArrayList as its second argument so something like this would be needed:


    def myCookies = new java.util.ArrayList()
    myCookies.add(myCookie)
    testRunner.testCase.testSuite.project.setPropertyValue("Cookie", myCookies)


    Does that work?

    Regards,
    Henrik
    SmartBear Software