How to get cookies in Groovy scripts?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018
05:12 AM
09-17-2018
05:12 AM
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{ log.info(it.name + "=" + it.value) }
Example:
Natalie
Customer Care Team
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Customer Care Team
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Labels:
- Labels:
-
Scripting
0 REPLIES 0
