Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
CookieJar.cookiesForURL(url)
Returns
Example
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://httpbin.test.k6.io/cookies/set?my_cookie=hello%20world', {
redirects: 0,
});
const jar = http.cookieJar();
const cookies = jar.cookiesForURL('https://httpbin.test.k6.io/');
check(res, {
"has cookie 'my_cookie'": (r) => cookies.my_cookie.length > 0,
'cookie has correct value': (r) => cookies.my_cookie[0] === 'hello world',
});
}