No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.33. Go to the latest version

CookieJar.cookiesForURL(url)

suggest edits
ParameterTypeDescription
urlstringThe URL for which to get cookies.

Returns

TypeDescription
objectObject of cookies where the key is the cookie name and the value is an array.

Example

import http from 'k6/http';
import { check } from 'k6';
export default function () {
let res = http.get(
'https://httpbin.org/cookies/set?my_cookie=hello%20world',
{ redirects: 0 },
);
let jar = http.cookieJar();
let cookies = jar.cookiesForURL('http://httpbin.org/');
check(res, {
"has cookie 'my_cookie'": (r) => cookies.my_cookie.length > 0,
'cookie has correct value': (r) => cookies.my_cookie[0] === 'hello world',
});
}