Ask a Question

How to get cookies in Groovy scripts?


How to get cookies in Groovy scripts?

Hi Community,


Let me share an answer to the above question with you 🙂


If the Session option is enabled, ReadyAPI maintains the HTTP session on the TestCase level automatically, which means that it stores cookies received from the server and sends them back in the subsequent requests to the same endpoint. If you need to get programmatic access to the stored cookies, you can use this Groovy script (it's applicable to ReadyAPI v.1.7.0 and later):


import org.apache.http.protocol.HttpContext
import com.eviware.soapui.model.iface.SubmitContext
import org.apache.http.impl.client.BasicCookieStore
import org.apache.http.client.protocol.HttpClientContext

HttpContext httpContext = context.getProperty(SubmitContext.HTTP_STATE_PROPERTY)
BasicCookieStore cookieStore = httpContext.getAttribute(HttpClientContext.COOKIE_STORE)
//iterate through the cookies store and output the name-value pairs to the log
cookieStore.getCookies().each{ + "=" + it.value)



Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Showing results for 
Search instead for 
Did you mean: