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
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.
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:
Delete a cookie in the VU cookie jar
To delete a cookie in the jar for a specific URL and name, use the delete method.
Clear all cookies in the VU cookie jar
To clear all cookies in the jar by specifying url, use the clear method.
Relevant k6 APIs: