Cookies
Use cookies to set up browser state or check values written by your application. Puth's core cookie helpers operate on raw values and work on pages, not iframe-scoped browsers.
Read and write cookies
Visit the target origin before reading its cookies. Pass an array of cookie definitions to $browser->setCookie(); include a URL or domain to identify where each cookie belongs.
$browser->visit('https://app.test');
$browser->setCookie([
['name' => 'preference', 'value' => 'dark', 'url' => 'https://app.test'],
]);
$cookie = $browser->getCookieByName('preference');browser.visit("https://app.test");
browser.setCookie(new Object[]{
Map.of("name", "preference", "value", "dark", "url", "https://app.test"),
});
Object cookie = browser.getCookieByName("preference");await browser.visit('https://app.test');
await browser.setCookie([
{ name: 'preference', value: 'dark', url: 'https://app.test' },
]);
const cookie = await browser.getCookieByName('preference');$browser->getCookieByName() returns the cookie object when it exists. Inspect that object for its value, domain and path.
Check a cookie
Use Laravel's plain-cookie assertions for raw values set through $browser->setCookie():
$browser->assertHasPlainCookie('preference');
$browser->assertPlainCookieValue('preference', 'dark');Laravel's encrypted-cookie helpers are described separately in Laravel cookies.
The generated PHP API includes raw-cookie assertions. They currently share the standalone assertion-binding limitation; the calls below show their signatures:
$browser->_assertHasCookie('preference');
$browser->_assertCookieValue('preference', 'dark');These assertions do not encrypt or decrypt cookie values.
Raw-cookie assertions throw when the check fails. They do not encrypt or decrypt cookie values.
browser.assertHasCookie("preference")
.assertCookieValue("preference", "dark");Raw-cookie assertions reject when the check fails. They do not encrypt or decrypt cookie values.
await browser.assertHasCookie('preference')
.assertCookieValue('preference', 'dark');Delete a cookie
Remove a cookie for the current page:
$browser->deleteCookie('preference');browser.deleteCookie("preference");await browser.deleteCookie('preference');$browser->assertPlainCookieMissing('preference');$browser->_assertCookieMissing('preference');browser.assertCookieMissing("preference");await browser.assertCookieMissing('preference');If a name exists under several domains or paths, pass cookie definitions with the matching domain/path to $browser->deleteCookie() instead of a name alone.
