From 4a81880f1855adf91cfa6b846378ca174a263fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 7 Sep 2023 15:33:31 +0300 Subject: [PATCH] Add filter cookies by urls examples --- examples/cookies.js | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/examples/cookies.js b/examples/cookies.js index 948468cab..4c8b645a9 100644 --- a/examples/cookies.js +++ b/examples/cookies.js @@ -60,12 +60,10 @@ export default async function () { expires: dayBefore } ]); - - check(context.cookies().length, { + let cookies = context.cookies(); + check(cookies.length, { 'number of cookies should be 2': n => n === 2, }); - - const cookies = context.cookies(); check(cookies[0], { 'cookie 1 name should be testcookie': c => c.name === 'testcookie', 'cookie 1 value should be 1': c => c.value === '1', @@ -74,6 +72,41 @@ export default async function () { 'cookie 2 name should be testcookie2': c => c.name === 'testcookie2', 'cookie 2 value should be 2': c => c.value === '2', }); + + // let's add more cookies to filter by urls. + context.addCookies([ + { + name: 'foo', + value: '42', + sameSite: 'Strict', + url: 'http://foo.com' + }, + { + name: 'bar', + value: '43', + sameSite: 'Lax', + url: 'https://bar.com' + }, + { + name: 'baz', + value: '44', + sameSite: 'Lax', + url: 'https://baz.com' + } + ]); + + cookies = context.cookies('http://foo.com', 'https://baz.com'); + check(cookies.length, { + 'number of filtered cookies should be 2': n => n === 2, + }); + check(cookies[0], { + 'the first filtered cookie name should be foo': c => c.name === 'foo', + 'the first filtered cookie value should be 42': c => c.value === '42', + }); + check(cookies[1], { + 'the second filtered cookie name should be baz': c => c.name === 'baz', + 'the second filtered cookie value should be 44': c => c.value === '44', + }); } finally { page.close(); }