Ask a Question

How to get cookies in Groovy scripts?


How to get cookies in Groovy scripts?



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)



Version history
Last update:
‎09-28-2021 07:09 AM
Updated by: