I am currently struggling with a test script and need some help.
The goal is to achieve a fairly simple hybrid setup that addresses frontend via k6-browser and underlying API endpoints on a protocol level. The test itself is no big deal, but I am forced to add support for a login mechanism that involves multiple redirects and a totp token (I wrote a small k6 extension for this). I got it to work somehow, but I cannot run it with more than one vu because the login portal blocks simultaneous login attempts…
Long story short, I need to read the contents of a cookie that is part of the response I get from the auth system (adding the cookie for all subsequent requests already works via addCookies()). Does anyone have any idea how to read a cookie from a response header using k6-browser?
I saw the other topic here about k6-browser and reading cookies - unfortunately mine is httponly
Would be great if someone could point me in the right direction.
Hey @sashi , welcome to the forum!
So, unfortunately we are currently not supporting
browserContext.cookies() which should get the cookies for the specified URL after the login. I tried retrieving the cookies from the HTTP response returned from
page.waitForNavigation() but these parse response from
Network.responseReceived event which does not seem to include any
Set-Cookie header. These are reachable through
Network.event-responseReceivedExtraInfo event which includes all raw headers, but we currently do not support it
So I’m afraid there is not a way to retrieve httponly cookies as of now. We will review these issues and work on providing methods to work with cookies soon. Apologies for the inconvenience.
Hey @Daniel.J, thanks for your good answer!
I don’t see this as a show-stopper for me, even though I would have preferred better news. I can still create a meaningful test script by manually adding a cookie into the flow - it will not be as sophisticated as planned, but it will work.
I will come back later and see how cookie support developed.