Menu

This is documentation for the next version of K6. For the latest stable release, go to the latest version.

Open source

CookieJar.cookiesForURL(url)

ParameterTypeDescription
urlstringThe URL to get cookies for.

Returns

TypeDescription
objectA JS object with all cookies for the given URL, where the key is the cookie name and the value is an array.

Example

JavaScript
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',
  });
}