Scripting examples on how you can interact with cookies during your load test if required.
Cookies
As HTTP is a stateless protocol, cookies are used by server-side applications to persist data on client machines. This is used more or less everywhere on the web, commonly for user session tracking purposes. In k6 cookies are managed automatically by default, however, there are use cases where access to read and manipulate cookies are required.
From the response headers
access-cookie.js
Log all the cookies in a response
⚠️ Note that this only works when using k6 locally
The console.log() family of APIs are currently only usable when running k6 locally. When running k6 tests with LoadImpact Cloud Execution the logs will be discarded.
log-all-cookies.js
Setting a cookie in the VU cookie jar
To set a cookie that should be sent with every request matching a particular domain, path, etc. you'd do something like this:
set-cookie-in-jar.js
Relevant k6 APIs: